In: Computer Science
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
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