In: Computer Science
Translate the C function code below to the MIPS True Assembler Language code (machine instructions only). The function code should follow the conventions for MIPS function calls including passing parameters and returning results. Your function code must be written with the minimum number of machine instructions to be executed and without any use of MIPS pseudo-instructions.
Myfunction(unsigned int a, unsigned int b, unsigned int c) {
int i=0;
while (a > c) {
a /= b;
i++; }
return i; }
Greetings!!
Code:
.text
main:
addi $a0,$0,100 #load a into a0 for
passing parameter
addi $a1,$0,4 #load b into a1 for
passing parameter
addi $a2,$0,5 #load c into a2 for
passing parameter
addi $a3,$0,0 #load i into a3 for
passing parameter
#function call
jal Myfunction #function call
#termination
addi $v0,$0,10
syscall
#function definition
Myfunction:
loop:
#check a>c
slt $1,$a0,$a2
bne $1,$0,done
#division a=a/b
bne $a1,$0,d
break
d:
div $a0,$a1
mflo $a0
#i++
addi $a3,$a3,1
#repeat
j loop
done:
#return result to main
add $v0,$0,$a3
jr $ra
Machine code:
20040064
20050004
20060005
20070000
0c100007
2002000a
0000000c
0086082a
14200006
14a00001
0000000d
0085001a
00002012
20e70001
08100007
00071020
03e00008
Output screenshot:
Hope this helps