In: Computer Science
Reg # |
14 |
X |
9 |
A1 |
240 |
B1 |
380 |
C1 |
300 |
D1 |
150 |
E1 |
105 |
A2 |
340 |
B2 |
260 |
C2 |
400 |
D2 |
190 |
E2 |
195 |
1 |
Write a MIPS Assembly program function to calculate the factorial of an input number. Analyze the program for the number X (calculated above) and compute the Execution time in a pipelined MIPS at 2.4GHz. |
MIPS Assembly |
.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:
************************************************************************************************************************************
In case of any doubt do ask in the comment section.Hope you like it