Question: How do I reject negative numbers in MIPS assembly language? My program below is to find the fibonnacci of the user's input. If the user

How do I reject negative numbers in MIPS assembly language? My program below is to find the fibonnacci of the user's input. If the user chooses to input a negative number, I want my program to respond appropriately by prompting the user that it is not possible.

.data prompt: .ascii "Factorial Example Program " .asciiz "Enter N value: " results: .asciiz " Factorial of N = " n: .word 0 answer: .word 0

.text .globl main main: li $v0, 4 # print prompt string la $a0, prompt syscall li $v0, 5

syscall sw $v0, n

lw $a0, n jal fact sw $v0, answer

li $v0, 4 # print prompt string la $a0, results syscall li $v0, 1 # print integer lw $a0, answer syscall

li $v0, 10 # call code for terminate syscall # system call .end main

.globl fact

.ent fact fact: subu $sp, $sp, 8 sw $ra, ($sp) sw $s0, 4($sp) li $v0, 1 # check base case beq $a0, 0, factDone move $s0, $a0 # fact(n1) sub $a0, $a0, 1 jal fact mul $v0, $s0, $v0 # n * fact(n1)

factDone: lw $ra, ($sp) lw $s0, 4($sp) addu $sp, $sp, 8 jr $ra .end fact

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!