Question

In: Computer Science

in MIPS assembly, ask a user for two numbers and to either enter a '1' for...

in MIPS assembly, ask a user for two numbers and to either enter a '1' for addition or '2' for subtraction. using jal, jump to the appropriate procedure for additing or subtracting. then print out result and ask if there is another calculation (terminate program if 'no').

Solutions

Expert Solution

Program:

.data
   msg1: .asciiz "\nEnter number 1: "
   msg2: .asciiz "Enter number 2: "
   msg3: .asciiz "Enter operation to be performed (1-addition,2-subtraction):   "
   error_msg: .asciiz "\n\nInvalid input exitig the program."
   result: .asciiz "The result is:   "
   repeat: .asciiz "\nDo you want to perform another calculation?\n(Enter y for yes or n for no)\n"
   char: .space 1
   yes: .asciiz "y"
   no: .asciiz "n"


.text
.globl main
main:
again:   li $v0,4
   la $a0,msg1
   syscall
  
   li $v0,5
   syscall
   move $t0,$v0   #$t0 = number1

   li $v0,4
   la $a0,msg2
   syscall
  
   li $v0,5
   syscall
   move $t1,$v0   #$t1 = number2
  
   li $v0,4
   la $a0,msg3
   syscall
  
   li $v0,5
   syscall
   move $t2,$v0
  
   beq $t2,1,addtn
   beq $t2,2,subtn
  
   li $v0,4
   la $a0,error_msg
   syscall
   b exit
  
addtn:   add $t3,$t0,$t1
   b next

subtn:   sub $t3,$t0,$t1

next:   li $v0,4
   la $a0,result
   syscall
  
   li $v0,1
   move $a0,$t3
   syscall
  
   li $v0,4
   la $a0,repeat
   syscall
  
   li $v0,12
   syscall
   sb $v0,char
  
   lb $t0,yes
   lb $t1,no
  
   beq $v0,$t0,again
   beq $v0,$t1,exit
  
   li $v0,4
   la $a0,error_msg
   syscall  
exit:

OUTPUT:'


Related Solutions

In MIPS assembly: Ask the user to enter two numbers and an operation (+ - /...
In MIPS assembly: Ask the user to enter two numbers and an operation (+ - / *). Print the expression back to the user with a blank after the = sign (since the calculation is not being completed.  
using MIPs assembly, ask the user to enter two numbers. Then multiply the two numbers using...
using MIPs assembly, ask the user to enter two numbers. Then multiply the two numbers using bit shifting (not 'mul'). This should work multiplying 2 positive numbers, 2 negative numbers, and a positive/negative number. Then output the result and ask user if he/she has more calculations to complete.
Write a MIPS program that will ask the user to enter two numbers at the console...
Write a MIPS program that will ask the user to enter two numbers at the console and pass the values to a function that does multiplication
Write a MIPS program that will ask the user to enter two numbers at the console...
Write a MIPS program that will ask the user to enter two numbers at the console and compute xy
Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
Write a mips assembly code program that ask the user to enter an integer value, and...
Write a mips assembly code program that ask the user to enter an integer value, and then print the result of doubling that number.
Write a mips assembly language program that asks the user to enter an alphabetic character (either...
Write a mips assembly language program that asks the user to enter an alphabetic character (either lower or upper case)and change the case of the character from lower to upper and from upper to lower and display it.
C++ Programa that: // 1) Ask the user to enter two numbers greater than zero. Store...
C++ Programa that: // 1) Ask the user to enter two numbers greater than zero. Store the //    values into two variables named 'n' and 'm'. //    Additionally, implement a while-loop to keep asking the user to enter //    the numbers again if any of the two numbers are equal or smaller than zero. // 2) If the two numbers (n, m) are equal, display the message "The //    numbers are the same". If the two numbers are different, display...
This is to be done using MIPS assembly language. Display the following menus, ask user to...
This is to be done using MIPS assembly language. Display the following menus, ask user to select one item. If 1-3 is selected, display message “item x is selected”, (x is the number of a menu item), display menus again; if 0 is selected, quit from the program. 1. Menu item 1 2. Menu item 2 3. Menu item 3 0. Quit Please select from above menu (1-3) to execute one function. Select 0 to quit
This is to be done using MIPS assembly language. Display the following menus, ask user to...
This is to be done using MIPS assembly language. Display the following menus, ask user to select one item. If 1-3 is selected, display message “item x is selected”, (x is the number of a menu item), display menus again; if 0 is selected, quit from the program. 1. Menu item 1 2. Menu item 2 3. Menu item 3 0. Quit Please select from above menu (1-3) to execute one function. Select 0 to quit
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT