In the class lecture we have compiled the following C code i

In the class lecture, we have compiled the following C code: int fact (int n) {if (n =1, so decrement n jal fact #call fact with (n-1) #this is where fact returns lw $a0, 0($sp) #restore argument n lw $ra. 4($sp) #restore return address addi $sp. $sp, 8 # adjust stack pointer mul $v0, $a0, $v0 #$v0 = n * fact(n-1) jr $ra #return to caller Assume the memory address for the first instruction (fact: ...) is 0x00400020. Now, you are expected to assemble the program (SKIP the instruction: mul $v0, $a0, $v0) into machine code. Your solution should contain three columns: the first column being the memory address of the instruction, the second column being the binary representation of the machine code, and the third column being the hexadecimal representation of the machine code.

Solution

addi r0, #1, r26 !addi zero_r, #1, return_r
05000126
beq r25, r0, #retfact !beq send_r, zero_r, retfact
21250047
subi r31, #1, r31 !push accum_r
06310131
stom r5, r31
16053100
copy r25, r5 !copy input parm into accum
10250500
subi r25, #1, r25 !subi send_r, 1, send_r
06250125
subi r31, #1, r31 !jsr fact
06310131
stpo #1, r31
35000131
ldpi #fact
31000035
mul r5, r26, r26 !mul accum_r, return_r, return_r
02052626
lodm r31, r5 !pop accum_r
12310500
addi r31, #1, r31
05310131

 In the class lecture, we have compiled the following C code: int fact (int n) {if (n =1, so decrement n jal fact #call fact with (n-1) #this is where fact retu

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site