Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions