Question: Write a procedure that: Accepts four values a, b, c and d. Use $a0 to accept a, etc. Computes (a * c) - (b /
Write a procedure that:
Accepts four values a, b, c and d. Use $a0 to accept a, etc.
Computes (a * c) - (b / d).
Returns the result in $v0.
Handles the stack correctly as we described in class.
Write a main program that:
Reads four values a, b, c and d from data locations in memory.
Calls the above procedure properly.
Prints the returned result using a system call.
Exits properly.
Don't worry about overflow or remainder. Submit your code here as a single .a file.
My code is as follows, missing the function call.
Please comment the part that was added.
.data
A: .word 24
B: .word 8
C: .word 6
D: .word 4
.text
main:
#data from memory push into stack
lw $a0,A
#store A at the bottom of the stack i.e at -12
sw $a0,-12($sp)
lw $a0,B
#store B at the one place above the bottom of the stack i.e at -8
sw $a0,-8($sp)
lw $a0,C
sw $a0,-4($sp) #store C at the second place of the stack i.e at -4
lw $a0,D
sw $a0,0($sp) #store D at the top of the stack i.e at 0
#data is pop from the stack
lw $a0,0($sp)
move $t1,$a0 #$t1 = D = 4
lw $a0,-4($sp)
move $t2,$a0 #$t2 = C = 6
lw $a0,-8($sp)
move $t3,$a0 #$t3 = B = 8
lw $a0,-12($sp)
move $t4,$a0 #$t4 = A = 24
div $t1,$t3,$t1 #$t1 = (B/D) = 8/4 =2
mul $t2,$t2,$t4 #$t2 = (A*C) = 24*6 = 144
sub $t1,$t2,$t1 #$t1 = (A*C)-(B/D) = 144-2 = 142
li $v0, 1
move $a0, $t1
syscall
#exit
li $v0, 10
syscall
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
