Question: . data result: . word 0 prompt: . asciz Enter a number ( 0 - 5 ) : output: . asciiz The factorial is:

.data
result: .word 0
prompt: .asciz "Enter a number (0-5): "
output: .asciiz "The factorial is: *
.text
.globl main
main:
Ii $v0,4
la $a0, prompt
syscall
li $v0,5
syscall
move $t0, $t0
beqz $t0, factorial_zero
li $ t1,1,#11
beq $t0, $t1, factorial_one
li $t1,1
beq $t0,2, factorial_two
beq $t0,3, factorial three
beq $t0,4, factorial_four
beq $t0,5, factorial_five
J exit
factorial_zero:
li $t1,1
j store_result
factorial_one:
li $t1,1
j store_result
factorial_two:
li $t1,2
j store_result
factorial_three:
li $t1,6
j store_result
factorial_four:
li $t1,24
j store_result
factorial five:
li $t1,120
j store_result
Store_result:
sw $t1, result
# Print the result
li $v0,4
la $a0, output
syscall
Iw $a0, result
li $v0,1
syscall
exit:
li $v0,10
syscall
Explain every line of code and what it does. If any mistakes fix them please. Would also like the output of the code. Will give a thumbs up.

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 Programming Questions!