Question: Translate function f into MIPS assembly language. If you need to use registers $t0 through $t7, use the lower numbered registers first. Assume the function

Translate function f into MIPS assembly language. If you need to use registers $t0 through $t7, use the lower numbered registers first. Assume the function

declaration for func is "int func(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);

}

Answer:

f: addi $sp,$sp, -12

sw $ra,8($sp)

sw $s1,4($sp)

sw $s0,0($sp)

move $s1,$a2

move $s0,$a3

jal func

move $a0,$v0

add $a1,$s0,$s1

jal func

lw $ra,8($sp)

lw $s1,4($sp)

lw $s0,0($sp)

addi $sp,$sp,12

jr $ra

Can someone please explain why we only defined 3 variblaes and ignorerege int d and why we sayed jal func and then move $a0, $v0, and are we assuming $a0 and $a1 are and b respectivly too?(it would be great if you could explain each process and its reasoning). Thank you so much!

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!