Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

6th Edition

1943153035, 978-1943153039

More Books

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago