Question: Question 4 - Use of the stack ( 2 5 points ) The following code has three different functions, Main, SumFung, and LoddFunc. The functions

Question 4- Use of the stack (25 points)
The following code has three different functions, Main, SumFung, and LoddFunc. The
functions do not implement MIPS caller/callee conventions. Each function has a
description above it to give you an overview of the function. An example .data section is
given at the end of the code section.
The purpose of this question is to evaluate your understanding of stack operations in
MIPS.
Add as many instructions as needed to implement caller/callee conventions. Do not put
unnecessary data on the stack. There might be more than one correct answer. Use the
provided callouts to insert your instructions. Some callouts may remain empty.
. text
## main is a test case for the SumFunc internal function.
# In memory, are the value A and the value B.
# The compute sum will be stored in memory at Result.
main: la $t0, A #loads address of A
la st1, B #loads address of B
la $t3, Result #loads address of Result
move $a0, $to #address of A is input to SumFunc
move sal, $t1 #address of B input to SumFunc
jal SumFunc #calls SumFune
sw $v1,0($t3) #saves sum into Result
##SumFunc takes two inputs
# ( $a0-address of A, $al-address of B)
# and returns a value in $v0
# returned is the sum of the values at those memory locations
SumFunc:
move $30, $a0 #moves addr of A into saved register
move $s1, $al #moves addr of B into saved register
move $a0,$s0 #addr of A is input to lst LoadFunc call
jal LoadFunc #call LoadFunc to get value of A
move $30,$v0 #moves returned value to $30
move $a0, $s1 #base addr of array is AddressFunc input
jal LoadFunc #call LoadFunc to get value of B??
move $31,$v0 #moves returned value to $30
#(this is now the value of B)
add $s1,$s1,$s0 #adds the two values together
move $v0,$31 #return sum as output of SumFunc
jr Sra # return to main
## AddressFunc takes one input ( $a0- address of value)
# and returns a value in $v0- the value at addr passed in
LoadFunc:
lw $v0,0($a0) #loads value of address
ir sra #return to SumFunc
 Question 4- Use of the stack (25 points) The following code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!