Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

. this code is a simple calculator written in mips but there is a problem the code dose not loop i want to alter it

.this code is a simple calculator written in mips but there is a problem the code dose not loop i want to alter it so that it loop.
.data
number1 : .asciiz "Enter number1:"
number2 : .asciiz "Enter number2:"
addChoice: .asciiz "1. to add numbers
"
subChoice: .asciiz "2. to subtract numbers
"
mulChoice: .asciiz "3. to multiply numbers
"
divChoice: .asciiz "4. to divide numbers
"
quitChoice: .asciiz "5. Quit
"
enterChoice: .asciiz "Enter Choice:"
Result: .asciiz "Result:"
endl : .asciiz "
"
.text
main:
addi $s0,$zero,0 #number 1
addi $s1,$zero,0 #number 2
li $v0,4 #print String to input number 1
la $a0,number1
syscall
li $v0,5 #get input from user
syscall
move $s0,$v0 #move user input to $s0
li $v0,4 #print String to input number 2
la $a0,number2
syscall
li $v0,5 #get second user input
syscall
move $s1,$v0 #move user input to $s1
#print menu system
li $v0,4 #addition
la $a0,addChoice
syscall
#subtraction
li $v0,4
la $a0,subChoice
syscall
#multipication
li $v0,4
la $a0,mulChoice
syscall
#divide
li $v0,4
la $a0,divChoice
syscall
#quit
li $v0,4
la $a0,quitChoice
syscall
#enter choice
li $v0,4
la $a0,enterChoice
syscall
#get choice from user
li $v0,5
syscall
#move $v0 to $t0
addi $t0,$v0,0
beq $t0,1,ADD #if choice ==1 go to ADD
beq $t0,2,SUB #if choice ==2 go to SUB
beq $t0,3,MUL #if choice ==3 go to MUL
beq $t0,4,DIV #if choice ==4 go to DIVIDE
beq $t0,5,Exit # to quit enter 5
j Exit #jump to Quit anything else entered
DIV:
#divide $s0 with $s1
div $s0,$s1
#move divide quotient into $t1
mflo $t1
#print result string
li $v0,4
la $a0,Result
syscall
#print divide quotient
move $a0,$t1
li $v0,1
syscall
#print new line
li $v0,4
la $a0,endl
syscall
j Exit
MUL :
#multiply $s0 and $s1
mult $s0,$s1
#move low order 32 bit in $t1
mflo $t1
#print result string
li $v0,4
la $a0,Result
syscall
#print multiplication
move $a0,$t1
li $v0,1
syscall
#print new line
li $v0,4
la $a0,endl
syscall
j Exit
SUB :
#sub tract $s0-$s1
#result save to $t1
sub $t1,$s0,$s1
li $v0,4
la $a0,Result
syscall
#print t1
move $a0,$t1
li $v0,1
syscall
li $v0,4
la $a0,endl
syscall
j Exit
ADD:
#add $s0,$s1
add $t1,$s0,$s1
li $v0,4
la $a0,Result
syscall
#print t1
move $a0,$t1
li $v0,1
syscall
li $v0,4
la $a0,endl
syscall
j Exit
Exit:
#terminate the program
li $v0,10
syscall

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

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

Students also viewed these Databases questions

Question

Do the measurement items or tools have content relevance?

Answered: 1 week ago