summaryrefslogtreecommitdiff
path: root/Homework/cs5300/hw-MIPS/code/fee.asm
diff options
context:
space:
mode:
Diffstat (limited to 'Homework/cs5300/hw-MIPS/code/fee.asm')
-rw-r--r--Homework/cs5300/hw-MIPS/code/fee.asm44
1 files changed, 44 insertions, 0 deletions
diff --git a/Homework/cs5300/hw-MIPS/code/fee.asm b/Homework/cs5300/hw-MIPS/code/fee.asm
new file mode 100644
index 0000000..c38b5d6
--- /dev/null
+++ b/Homework/cs5300/hw-MIPS/code/fee.asm
@@ -0,0 +1,44 @@
+.text
+
+.globl main
+main:
+ # put 3 and 4 on the stack using the register $sp
+ subi $sp, $sp, 8
+ li $s0, 3
+ li $s1, 4
+
+ sw $s0, 0($sp)
+ sw $s1, 4($sp)
+
+ # call fee. You'll probably want to use the jal instruction to
+ # store the current address in $ra
+
+ jal fee
+
+ # load results from stack to registers
+ lw $a0, 0($sp)
+ addi $sp, $sp, 4
+ # print result
+ li $v0, 1
+ syscall
+
+ # exit
+ li $v0, 10
+ syscall
+fee:
+ # copy a and b from stack to local registers
+ lw $s1, 4($sp)
+ lw $s0, 0($sp)
+
+ # add a and b
+ add $t0, $s1, $s0
+
+ # place result on stack
+ addi $sp, $sp, 4 # No need to keep $sp allocated for two words when we're just returning a result
+ sw $t0, 0($sp)
+
+ # return using jr instruction
+ jr $ra
+
+# Start .data segment (data!)
+.data