Translate function f into MIPS assembly language. If you need to use registers $
ID: 3668813 • Letter: T
Question
Translate function f into MIPS assembly language. If you need to use registers $t0 through $t7, use the lower-numbered registers fi rst.
Assume the function declaration for func is "int function (int a, int b);". The code for function f is as follows:
int f(int a, int b, int c, int d) {
return func(func(a,b),c+d);
}
note: you really don't need to know what func does to be able to create the function f.
You do need to know the number and type of the parameters for func and the type of the return value of func (to make sure that you are making an appropriate call)
Explanation / Answer
f: addiu $sp, $sp, -8 # allocate frame = 8 bytes
sw $ra, 0($sp) # save return address
sw $a2, 4($sp) # save c
jal func # call func(a,b)
move $a0, $v0 # $a0 = result of func(a,b)
lw $a1, 4($sp) # $a1 = c
jal func # call func(func(a,b),c)
lw $ra, 0($sp) # restore return address
addiu $sp, $sp, 8 # free stack frame
jr $ra # return to caller
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.