In: Computer Science
Write a MIPS Assembly program function to calculate the factorial of an input number. Analyze the program for the value 10 and compute the Execution time in a MIPS processor at 2.4GHz. The CPI is 1.
Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate
the question. Thank You So Much.
.data
printmsg: .asciiz " \nEnter a number to find factorial : "
printmsg2: .asciiz "Factorial of the number is : "
.text
.globl main
main:
doAgain :
la $a0,printmsg # Load the address of prompt
li $v0,4 # The string print service is specified
syscall # System call is made
li $v0,5 # The integer print service is specified
syscall # System call is made
#move data to s0
move $s0,$v0
#if s0 less than or equal to zero exit
blez $s0,exit
#load 1 to s1 store the factorial
li $s1,1
loop:
mul $s1,$s1,$s0
sub $s0,$s0,1
bnez $s0,loop
la $a0,printmsg2 # Load the address of prompt
li $v0,4 # The string print service is specified
syscall # System call is made
#print result
move $a0,$s1
li $v0,1 # The string print service is specified
syscall # System call is made
j doAgain
exit: