summaryrefslogtreecommitdiff
path: root/Homework/cs5300/hw-MIPS/code/fee.asm
blob: c38b5d6dd21a05df0dba294abfebf0908938180e (plain) (blame)
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
35
36
37
38
39
40
41
42
43
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