Question: Why am I getting an error in this mips code? #calculate and print (a + b) - (c + d) .data A: .word 3 B:
Why am I getting an error in this mips code?
#calculate and print (a + b) - (c + d)
.data A: .word 3 B: .word 4 C: .word 2 D: .word 2
.text main: lw $a0, A lw $a1, B lw $a2, C lw $a3, D
jal calculate # make the call
move $a0, $v0 # return value will be in $v0 li $v0, 1 # system call code for print_int syscall j exit
li $v0,10 syscall
calculate: addi $sp, $sp, -4 # adjust stack pointer to make # room for 1 item sw $s0, 0($sp) # save the value that was in # $s0 when the call occurred add $t0, $a0, $a1 # $t0 = a + b add $t1, $a2, $a3 # $t1 = c + d sub $s0, $t0, $t1 # $s0 = (a+ b) - (c + d) move $v0, $s0 # put return value into $v0 lw $s0, 0($sp) # restore value of $s0 addi $sp, $sp, 4 # restore the stack pointer jr $ra # jump back to the return # address
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
