diff options
| author | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-07-02 11:55:17 -0700 |
|---|---|---|
| committer | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-07-02 11:55:17 -0700 |
| commit | 6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6 (patch) | |
| tree | ed97e39ec77c5231ffd2c394493e68d00ddac5a4 /Homework/cs5300/hw-MIPS/code/fee.asm | |
| download | misc-undergrad-6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6.tar.gz misc-undergrad-6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6.zip | |
Diffstat (limited to 'Homework/cs5300/hw-MIPS/code/fee.asm')
| -rw-r--r-- | Homework/cs5300/hw-MIPS/code/fee.asm | 44 |
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 |
