1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
<Comment># A demonstration of some simple MIPS instructions</Comment><br/>
<Comment># used to test QtSPIM</Comment><br/>
<Normal Text></Normal Text><br/>
<Normal Text> </Normal Text><Comment># Declare main as a global function</Comment><br/>
<Normal Text> </Normal Text><Section>.globl</Section><Normal Text> main </Normal Text><br/>
<Normal Text></Normal Text><br/>
<Normal Text> </Normal Text><Comment># All program code is placed after the</Comment><br/>
<Normal Text> </Normal Text><Comment># .text assembler directive</Comment><br/>
<Normal Text> </Normal Text><Type>.text</Type><Normal Text> </Normal Text><br/>
<Normal Text></Normal Text><br/>
<Comment># The label 'main' represents the starting point</Comment><br/>
<Label>main:</Label><br/>
<Normal Text> </Normal Text><Pseudo Instruction>li</Pseudo Instruction><Normal Text> </Normal Text><Other Register>$t2</Other Register><Normal Text>, </Normal Text><Decimal>25</Decimal><Normal Text> </Normal Text><Comment># Load immediate value (25) </Comment><br/>
<Normal Text> </Normal Text><Hardware Instruction>lw</Hardware Instruction><Normal Text> </Normal Text><Other Register>$t3</Other Register><Normal Text>, value </Normal Text><Comment># Load the word stored in value (see bottom)</Comment><br/>
<Normal Text> </Normal Text><Hardware Instruction>add</Hardware Instruction><Normal Text> </Normal Text><Other Register>$t4</Other Register><Normal Text>, </Normal Text><Other Register>$t2</Other Register><Normal Text>, </Normal Text><Other Register>$t3</Other Register><Normal Text> </Normal Text><Comment># Add</Comment><br/>
<Normal Text> </Normal Text><Hardware Instruction>sub</Hardware Instruction><Normal Text> </Normal Text><Other Register>$t5</Other Register><Normal Text>, </Normal Text><Other Register>$t2</Other Register><Normal Text>, </Normal Text><Other Register>$t3</Other Register><Normal Text> </Normal Text><Comment># Subtract</Comment><br/>
<Normal Text> </Normal Text><Hardware Instruction>sw</Hardware Instruction><Normal Text> </Normal Text><Other Register>$t5</Other Register><Normal Text>, Z </Normal Text><Comment>#Store the answer in Z (declared at the bottom) </Comment><br/>
<Normal Text></Normal Text><br/>
<Normal Text> </Normal Text><Comment># Exit the program by means of a syscall.</Comment><br/>
<Normal Text> </Normal Text><Comment># There are many syscalls - pick the desired one</Comment><br/>
<Normal Text> </Normal Text><Comment># by placing its code in $v0. The code for exit is "10"</Comment><br/>
<Normal Text> </Normal Text><Pseudo Instruction>li</Pseudo Instruction><Normal Text> </Normal Text><Main Register>$v0</Main Register><Normal Text>, </Normal Text><Decimal>10</Decimal><Normal Text> </Normal Text><Comment># Sets $v0 to "10" to select exit syscall</Comment><br/>
<Normal Text> </Normal Text><Hardware Instruction>syscall</Hardware Instruction><Normal Text> </Normal Text><Comment># Exit</Comment><br/>
<Normal Text></Normal Text><br/>
<Normal Text> </Normal Text><Comment># All memory structures are placed after the</Comment><br/>
<Normal Text> </Normal Text><Comment># .data assembler directive</Comment><br/>
<Normal Text> </Normal Text><Type>.data</Type><br/>
<Normal Text></Normal Text><br/>
<Normal Text> </Normal Text><Comment># The .word assembler directive reserves space</Comment><br/>
<Normal Text> </Normal Text><Comment># in memory for a single 4-byte word (or multiple 4-byte words)</Comment><br/>
<Normal Text> </Normal Text><Comment># and assigns that memory location an initial value</Comment><br/>
<Normal Text> </Normal Text><Comment># (or a comma separated list of initial values)</Comment><br/>
<Label>value:</Label><Normal Text> </Normal Text><Section>.word</Section><Normal Text> </Normal Text><Decimal>12</Decimal><br/>
<Label>Z:</Label><Normal Text> </Normal Text><Section>.word</Section><Normal Text> </Normal Text><Decimal>0</Decimal><br/>
|