| 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 Light)"/> |
| 6 |
</head><body style="background-color:#ffffff;color:#1f1c1b"><pre> |
| 7 |
<span style="color:#898887;"># A demonstration of some simple MIPS instructions</span> |
| 8 |
<span style="color:#898887;"># used to test QtSPIM</span> |
| 9 |
|
| 10 |
<span style="color:#898887;"># Declare main as a global function</span> |
| 11 |
<span style="color:#0057ae;">.globl</span> main |
| 12 |
|
| 13 |
<span style="color:#898887;"># All program code is placed after the</span> |
| 14 |
<span style="color:#898887;"># .text assembler directive</span> |
| 15 |
<span style="font-weight:bold;">.text</span> |
| 16 |
|
| 17 |
<span style="color:#898887;"># The label 'main' represents the starting point</span> |
| 18 |
<span style="color:#006e28;">main:</span> |
| 19 |
<span style="color:#644a9b;">li</span> <span style="color:#0000ff;">$t2</span>, <span style="color:#b08000;">25</span> <span style="color:#898887;"># Load immediate value (25) </span> |
| 20 |
<span style="font-weight:bold;">lw</span> <span style="color:#0000ff;">$t3</span>, value <span style="color:#898887;"># 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:#898887;"># 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:#898887;"># Subtract</span> |
| 23 |
<span style="font-weight:bold;">sw</span> <span style="color:#0000ff;">$t5</span>, Z <span style="color:#898887;">#Store the answer in Z (declared at the bottom) </span> |
| 24 |
|
| 25 |
<span style="color:#898887;"># Exit the program by means of a syscall.</span> |
| 26 |
<span style="color:#898887;"># There are many syscalls - pick the desired one</span> |
| 27 |
<span style="color:#898887;"># by placing its code in $v0. The code for exit is "10"</span> |
| 28 |
<span style="color:#644a9b;">li</span> <span style="color:#0057ae;">$v0</span>, <span style="color:#b08000;">10</span> <span style="color:#898887;"># Sets $v0 to "10" to select exit syscall</span> |
| 29 |
<span style="font-weight:bold;">syscall</span> <span style="color:#898887;"># Exit</span> |
| 30 |
|
| 31 |
<span style="color:#898887;"># All memory structures are placed after the</span> |
| 32 |
<span style="color:#898887;"># .data assembler directive</span> |
| 33 |
<span style="font-weight:bold;">.data</span> |
| 34 |
|
| 35 |
<span style="color:#898887;"># The .word assembler directive reserves space</span> |
| 36 |
<span style="color:#898887;"># in memory for a single 4-byte word (or multiple 4-byte words)</span> |
| 37 |
<span style="color:#898887;"># and assigns that memory location an initial value</span> |
| 38 |
<span style="color:#898887;"># (or a comma separated list of initial values)</span> |
| 39 |
<span style="color:#006e28;">value:</span> <span style="color:#0057ae;">.word</span> <span style="color:#b08000;">12</span> |
| 40 |
<span style="color:#006e28;">Z:</span> <span style="color:#0057ae;">.word</span> <span style="color:#b08000;">0</span> |
| 41 |
</pre></body></html> |