Question: Edit my MIPS/Assembly factorial code. Hello, I'm asked to write a program that asks user for integer n, between 0 to 20. The program should
Edit my MIPS/Assembly factorial code.
Hello, I'm asked to write a program that asks user for integer n, between 0 to 20. The program should find n!. I think I put my error message in the wrong place but i want it to loop to enter another number if the first number gives an error. Please try to use as much as possible as my original code, feel free to add stuff but it should not be too advance as we are just now learning how to use assembly
An Example of sample input and output would be:
Enter an integer value between 0-10? 11 ==> **** ERROR: 11 is not within the range. Enter another number.
Enter an integer value between 0-10? -3 ==> **** ERROR: -3 is not within the range. Enter another number.
Enter an integer value between 0-10? 0 0! =1
Enter an integer value between 0-10? 4 4! =24
.data
enter: .asciiz "Please enter an integer value between 0-20" error: .asciiz "Error, the number is not within the range. Enter another number"
.text
li $v0,4 la $a0, enter syscall
li $v0, 5 syscall add $s0, $v0, $0
li $t2, 1 li $t3, 20
fact: li $t0, 1 move $t1, $a0
loop: blez $t1, done blt $t1, $t2, errormessage bgt $t1, $t3, errormessage mul $t0, $t0, $t1 addi $t1, $t1, -1 j loop
done: move $v0, $t0
li $v0, 10 syscall
errormessage: li $v0,4 la $a0, error syscall j loop
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
