Question: the given MIPS 3 2 benchmark program below computes factorial, Suppose you implemented PUSH $n and POP the former pushes ( Sn ) onto the

the given MIPS32 benchmark program below computes factorial, Suppose you implemented PUSH $n and POP the former pushes (Sn) onto the stack and the latter pops off TOS into $n while SP is adjusted automatically. Rewrite this program PUSH and POP. b) How many memory cycles do you save when calculating m!?
fact: addi$1, $0,1 # initialize reg. 1 to 1
beq$4, $0, return1# if (n ==0) then gotoreturn1:
bne$4, $1, continue # if (n !=1) then gotocontinue:
return1: addi$2, $1,0 # assign result =1
jr$31 # return
continue: addi$29, $29,-12 # allocate stack space for fp, ra, n
sw$30,8($29) # save frame pointer
sw$31,4($29) # save return address
addi$30, $29,8 # update frame pointer
sw $4,0($29)# save n
addi$4, $4,-1 # make n-1
jalfact # recursive call to fact(n-1)
lw $4,0($29) # restore n
mult $2, $4 # fact (n-1)* n
mflo$2 # put product in result reg.
lw$31,4($29) # restore return address
lw$30,8($29) # restore frame pointer
addi $29, $29,12 # restore stack pointer
jr$31 # return

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!