Question

In: Computer Science

Write code in MIPS ,read tow number from the user that do the following: 1- multiply...

Write code in MIPS ,read tow number from the user that do the following:

1- multiply

2- Dividing

3- sum

4- average

5- minimum

6- maximum

7- print message to thank the user for using my program


Solutions

Expert Solution

Greetings!!

Code:

.data
prompt: .asciiz "\nSelect the operation: \n1. X x Y\n2. X / Y\n3. X + Y\n4. AVERAGE\n5. MINIMUM\n6. MAXIMUM\n7. EXIT\n"
prompt1: .asciiz "Enter first number X\n "
prompt2: .asciiz "Enter second number Y\n "
out: .asciiz "Result= "
thank: .asciiz "Thank You!!"
.text
main:   #DISPLAY PROMPT
   la $a0,prompt
   li $v0,4
   syscall
   #READ OPTION
   li $v0,5
   syscall
   move $t0,$v0   #save the value to t0
   beq $t0,7,exit   #if the option is 7,then exit from the program
   #PROMPT FOR X
   la $a0,prompt1
   li $v0,4
   syscall
   #READ X
   li $v0,5
   syscall
   move $t1,$v0   #save X to t1
   #PROMPT FOR Y  
   la $a0,prompt2
   li $v0,4
   syscall
   #READ Y
   li $v0,5
   syscall
   move $t2,$v0   #save Y to t2
   beq $t0,1,mmul   #if the option is 1 then do multiplication
   beq $t0,2,ddiv   #if the option is 2 then do division
   beq $t0,3,ssum   #if the option is 2 then do addition
   beq $t0,4,aav   #if the option is 4 then calculate average
   beq $t0,5,min   #if the option is 5 then find minimum
   beq $t0,6,max   #if the option is 6 then find maximum
   j main       #repeat the loop
   #MUL OPERATION
mmul:   mul $t3,$t1,$t2   #if the option is 1 then do mul operation
   j display   #goto display
   #DIV OPERATION
ddiv:   div $t3,$t1,$t2   #if the option is 2 then go division operation
   j display   #goto display
   #SUM OPERATION
ssum:   add $t3,$t1,$t2   #if the option is 3 then do addition
   j display   #goto display
   #AVERAGE OPERATION
aav:   add $t3,$t1,$t2   #if the option is 4 then do avearge
   div $t3,$t3,2   #average
   j display   #goto display
   #MIN
min:   bgtu $t1,$t2,else   #if the option is 5 then do the addition
   move $t3,$t1   #copy the minimum to t3
   j display
else:   move $t3,$t2   #copy the minimum to t3
   j display   #goto display
   #MAX
max:   bltu $t1,$t2,elsem   #if the option is 5 then do the addition
   move $t3,$t1   #copy the maximum to t3
   j display
elsem:   move $t3,$t2   #copy the maximum to t3
   #DISPLAY RESULTS= MESSAGE
display:la $a0,out
   li $v0,4
   syscall
   #DISPLAY THE RESULT
   li $v0,1
   move $a0,$t3   #loading the answer from t3 to a0 for display
   syscall
   j main       #repeat
   #DISPLAY THANK YOU
exit:   la $a0,thank
   li $v0,4
   syscall
   #STANDARD TERMINATION
   li $v0,10  
   syscall
  

Output screenshot:

Hope this helps


Related Solutions

Write MIPs program that will read two integers from the user and compute for the sum...
Write MIPs program that will read two integers from the user and compute for the sum and difference of the two integers. Ask the user whether he wants to repeat the program : "[Y/y] / [N/n] ?".
Write MIPs program that will read two intergers from the user and compute for the sum...
Write MIPs program that will read two intergers from the user and compute for the sum and difference of the two intergers. Ask the user whether he wants to repeat the program : "[Y/y] / [N/n] ?".
Write a program that will read user input, and do the following: 1. The user can...
Write a program that will read user input, and do the following: 1. The user can input letters [A-Z] as much as he wants (ignore case). 2. If the user input other than letters or two characters, stop the input process and start to print unduplicated sorted pairs such as the below examples: User input: A a e b d d D E a B 1 Output: AB AD AE BD BE DE User Input: a q w e dd...
Write a MIPS assembly language program to read an arbitrary number of integer pairs from a...
Write a MIPS assembly language program to read an arbitrary number of integer pairs from a file. Each pair will then be multiplied together with the results being accumulated (added together) forming a sum-of-products operation. Submit your report and code here.
Count the number of 1’s and 0’s Write a MIPS program that will ask the user...
Count the number of 1’s and 0’s Write a MIPS program that will ask the user to enter an integer, and then output the number of 1’s and 0’s that are present in the integer’s signed 32-bit binary representation. For example, 15 has a binary representation of 0000 0000 0000 0000 0000 0000 0000 1111, which has 28 zeroes and 4 ones. We have provided you the starter code that deals with the input/output logic. The integer input is saved...
MIPS code to calculate The 1- minimum 2- maximum 3- mid value of three number, user...
MIPS code to calculate The 1- minimum 2- maximum 3- mid value of three number, user will enter the numbers
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.
Prompt user to enter an integer number from console. Use 2 methods to multiply this number...
Prompt user to enter an integer number from console. Use 2 methods to multiply this number by factor 7, display result. This is required to be done in MIPS Assembly Language.
Write a mips assembly language program that asks the user to enter an unsigned number and...
Write a mips assembly language program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.
Write a MIPS assembly program that prompts the user for some number of cents (integer) and...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT