| 1 |
<!DOCTYPE html> |
| 2 |
<html><head> |
| 3 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> |
| 4 |
<title>highlight.asm-mips</title> |
| 5 |
<meta name="generator" content="KF5::SyntaxHighlighting - Definition (MIPS Assembler) - Theme (Breeze Dark)"/> |
| 6 |
</head><body style="background-color:#232629;color:#cfcfc2"><pre> |
| 7 |
<span style="color:#7a7c7d;"># A demonstration of some simple MIPS instructions</span> |
| 8 |
<span style="color:#7a7c7d;"># used to test QtSPIM</span> |
| 9 |
|
| 10 |
<span style="color:#7a7c7d;"># Declare main as a global function</span> |
| 11 |
<span style="color:#2980b9;">.globl</span> main |
| 12 |
|
| 13 |
<span style="color:#7a7c7d;"># All program code is placed after the</span> |
| 14 |
<span style="color:#7a7c7d;"># .text assembler directive</span> |
| 15 |
<span style="font-weight:bold;">.text</span> |
| 16 |
|
| 17 |
<span style="color:#7a7c7d;"># The label 'main' represents the starting point</span> |
| 18 |
<span style="color:#27ae60;">main:</span> |
| 19 |
<span style="color:#8e44ad;">li</span> <span style="color:#0000ff;">$t2</span>, <span style="color:#f67400;">25</span> <span style="color:#7a7c7d;"># Load immediate value (25) </span> |
| 20 |
<span style="font-weight:bold;">lw</span> <span style="color:#0000ff;">$t3</span>, value <span style="color:#7a7c7d;"># Load the word stored in value (see bottom)</span> |
| 21 |
<span style="font-weight:bold;">add</span> <span style="color:#0000ff;">$t4</span>, <span style="color:#0000ff;">$t2</span>, <span style="color:#0000ff;">$t3</span> <span style="color:#7a7c7d;"># Add</span> |
| 22 |
<span style="font-weight:bold;">sub</span> <span style="color:#0000ff;">$t5</span>, <span style="color:#0000ff;">$t2</span>, <span style="color:#0000ff;">$t3</span> <span style="color:#7a7c7d;"># Subtract</span> |
| 23 |
<span style="font-weight:bold;">sw</span> <span style="color:#0000ff;">$t5</span>, Z <span style="color:#7a7c7d;">#Store the answer in Z (declared at the bottom) </span> |
| 24 |
|
| 25 |
<span style="color:#7a7c7d;"># Exit the program by means of a syscall.</span> |
| 26 |
<span style="color:#7a7c7d;"># There are many syscalls - pick the desired one</span> |
| 27 |
<span style="color:#7a7c7d;"># by placing its code in $v0. The code for exit is "10"</span> |
| 28 |
<span style="color:#8e44ad;">li</span> <span style="color:#2980b9;">$v0</span>, <span style="color:#f67400;">10</span> <span style="color:#7a7c7d;"># Sets $v0 to "10" to select exit syscall</span> |
| 29 |
<span style="font-weight:bold;">syscall</span> <span style="color:#7a7c7d;"># Exit</span> |
| 30 |
|
| 31 |
<span style="color:#7a7c7d;"># All memory structures are placed after the</span> |
| 32 |
<span style="color:#7a7c7d;"># .data assembler directive</span> |
| 33 |
<span style="font-weight:bold;">.data</span> |
| 34 |
|
| 35 |
<span style="color:#7a7c7d;"># The .word assembler directive reserves space</span> |
| 36 |
<span style="color:#7a7c7d;"># in memory for a single 4-byte word (or multiple 4-byte words)</span> |
| 37 |
<span style="color:#7a7c7d;"># and assigns that memory location an initial value</span> |
| 38 |
<span style="color:#7a7c7d;"># (or a comma separated list of initial values)</span> |
| 39 |
<span style="color:#27ae60;">value:</span> <span style="color:#2980b9;">.word</span> <span style="color:#f67400;">12</span> |
| 40 |
<span style="color:#27ae60;">Z:</span> <span style="color:#2980b9;">.word</span> <span style="color:#f67400;">0</span> |
| 41 |
</pre></body></html> |