Question

Using Assembly Language (MIPS), design a program calculator that can perform the following: Addition, Subtraction, Multiplication,...

Using Assembly Language (MIPS), design a program calculator that can perform the following: Addition, Subtraction, Multiplication, Division, Power and Square Root Functions. Code must be able to accept floating point as well.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code (in MARS Editor):

.data

#for input
printExp1: .asciiz "Enter the First Number :"

#enter first number
printExp2: .asciiz "\nEnter the Second Number :"

#enter 2nd number
  
#user Choice
AddiExp: .asciiz "\nEnter 1 for Addition"
SubExp: .asciiz "\nEnter 2 for Substraction"
MulExp: .asciiz "\nEnter 3 for Multiplication"
DivExp: .asciiz "\nEnter 4 for Division"
  
UserChoice: .asciiz "\nchoice : >>"
  
resultExp: .asciiz "\nResult :"

.text
.globl main

main:

#Taking input 1 here:
#print Exp1
la $a0, printExp1
li $v0, 4
syscall

#taking input
li $v0, 7
syscall

#moving infrom from f0 to f4
mov.d $f4, $f0

#Taking input 2 here:
#print Exp2
la $a0, printExp2
li $v0, 4
syscall

#taking input
li $v0, 7
syscall
  
#moving infrom from f0 to f4
mov.d $f6, $f0
  
# Now user will choose what he wants to do

#additiion
la $a0, AddiExp
li $v0, 4
syscall
  
#substraction
la $a0, SubExp
li $v0, 4
syscall
  
#multiplication
la $a0, MulExp
li $v0, 4
syscall
  
#division
la $a0, DivExp
li $v0, 4
syscall
  
#choice
la $a0, UserChoice
li $v0, 4
syscall
  
#taking users choice
li $v0, 5
syscall
  
#moving input from v0 to t0
move $t0, $v0
  
#setting up the constants for comparison like 1 for addtion
addi $t1, $zero, 1
addi $t2, $zero, 2
addi $t3, $zero, 3
addi $t4, $zero, 4
  
#if user choose 1 for addition
beq $t0, $t1, Addition     #for Addition
beq $t0, $t2, Substraction #for Substraction
beq $t0, $t3, Multiplication #for Multiplication
beq $t0, $t4, Division #for Division

#program ends
li $v0, 10
syscall

#now addition:
Addition:
add.d $f4, $f4, $f6

#print exp
la $a0, resultExp
li $v0, 4
syscall
  
#print sum
mov.d $f12, $f4
li $v0, 3
syscall

#end program
li $v0, 10
syscall



#now substraction:
Substraction:
sub.d $f4, $f4, $f6

#print exp
la $a0, resultExp
li $v0, 4
syscall

#print sum
mov.d $f12, $f4
li $v0, 3
syscall

#end program
li $v0, 10
syscall

  
Multiplication:
#now multiplication:
mul.d $f4, $f4, $f6

#print exp
la $a0, resultExp
li $v0, 4
syscall

#print sum
mov.d $f12, $f4
li $v0, 3
syscall

#end program
li $v0, 10
syscall
  

#now division:
Division:
div.d $f4, $f4, $f6

#print exp
la $a0, resultExp
li $v0, 4
syscall

#print sum
mov.d $f12, $f4
li $v0, 3
syscall

#end program
li $v0, 10
syscall
  

Add a comment
Know the answer?
Add Answer to:
Using Assembly Language (MIPS), design a program calculator that can perform the following: Addition, Subtraction, Multiplication,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT