Question: . text main: li $a 0 , 5 hardcode factorial ( 5 ) jal factorial move $a 0 , $v 0 # copy return from

. text
main: li $a0,5 hardcode factorial(5)
jal factorial
move $a0, $v0 # copy return from factorialk into argument 0
li $v0,1, # integer print $a0 with syscall 1
syscall
exit: li $v0,10, # exit with syscall 10
syscall
# subroutine FACTORIAL(n)
# calculates n**(n-1)**(n-2)**dots**1
#IN: ,$a0=n, as unsigned integer
# OUT: ,$V0= FACTORIAL (n)
# CHANGES: $t0, $t1, $v0
factorial:
bne $a0, zero, nonzero , # special case N=0
li $a0,1 # same as FACTORIAL (1)
nonzero:
move $t0, $a0 #t0= a0
addi $t0, $t0,1,# t0=a0+1 for N+1 comparison
li $t1,1 # counter t1=1
li $v0,1 # result v0=1
loop: mul $v0,$v0,$t1,#v0**=t1
addi $t1,$t1,1,#t1+=1
bne $t0,$t, loop
jr $ ra
 . text main: li $a0,5 hardcode factorial(5) jal factorial move $a0,

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!