In: Computer Science
Convert the C program shown below to MIPS program. You may choose the $t registers, but must correctly apply the $a and $v registers used in function calls. Please do not include an exit syscall in your MIPS solution. Hint: review jr and jal instructions.
int fun( int a, int b ) { if ( a >= b )
return b + 2*a; else
return b + a;
} void main() {
}
int a = 10;
int b = 20;
int c = fun( a, b );
Greetings!!
.text
main:
#load arguements into a0 and a1
addi $a0,$0,10
addi $a1,$0,20
#function call
jal fun
#termination
addi $v0,$0,10
syscall
#function definition
fun:
blt $a0,$a1,else
sll $a0,$a0,1 #2*a
add $v0,$a0,$a1 #b+2*a into v0 for
return
jr $ra
else:
add $v0,$a0,$a1 #a+b into v0 for
return
jr $ra
Output:
Hope this helps