Answer to Question #159063 in Assembler for xherry

Question #159063

a) Write a program that multiply and then add four double precision point values through MIPS.

b.) Write a program to calculate roots of equation using quadratic formula using MIPS simulator.

                                              5x2 -4x-12=0



1
Expert's answer
2021-01-27T17:31:19-0500

a)

           .data

double1:        .double 4.0     

double2:        .double 5.0

double3:        .double 12.0

double4:        .double 1.0                

Rezult1Prompt: .asciiz "\nMUL:  "

Rezult2Prompt: .asciiz "\nSUM:  "

 

# code segment

       .text

       .globl main

main:

 l.d $f0, double1         # $f0 = 4.0

 l.d $f2, double2         # $f0 = 5.0

 l.d $f4, double3         # $f0 = 12.0

 l.d $f6, double4         # $f0 = 1.0

 

 

           mul.d $f12, $f0,$f2               # double1*double2

           mul.d $f12, $f12,$f4  # double1*double2*double3

           mul.d $f12, $f12,$f6  # $f12 = double1*double2*double3*double4         

 

           li $v0, 4 # printing string 

           la $a0,Rezult1Prompt            # "\nMUL:  "

           syscall 

           

           li $v0, 3 # system call code for printing a double

           syscall 

 

           li $v0, 4 # printing a string

           la $a0,Rezult2Prompt                       #"\nSUM:  "

           syscall            

           

           add.d $f12, $f0,$f2                # double1+double2

           add.d $f12, $f12,$f4  # double1+double2+double3

           add.d $f12, $f12,$f6  # $f12 = double1+double2+double3+double4

           

           li $v0, 3 # system call code for printing a float

           syscall            

           

           li $v0, 10         # finished .. stop .. return

syscall            # make the syscall

      

                 

 

 

 

 

 

b)

# 5x^2-4x-12=0

# x1=2.0

# x2=-1.2

           .data

Rezult1Prompt: .asciiz "\nx1 = "

Rezult2Prompt: .asciiz "\nx2 = "

 

fourFloat:       .float -4.0       

fiveFloat:        .float 5.0

twelveFloat: .float -12.0        

 

two: .word 2

four: .word 4

 

# code segment

       .text

       .globl main

main:

 lwc1 $f0, fiveFloat    # $f0 = 5.0

 lwc1 $f1, fourFloat   # $f1 = -4.0 

 lwc1 $f2, twelveFloat           # $f2 = -12.0

 

# calculate discriminant B^2-4AC

           mul.s $f8, $f1, $f1     # f8 = B^2

           mul.s $f9, $f0, $f2     # f9 = A*C

           l.s $f5, four

           cvt.s.w $f5, $f5                      # f5 = 4.0

           mul.s $f9, $f9, $f5     # f9 = 4*A*C 

           

# test: B^2 < 4*A*C

           c.lt.s $f8, $f9  # B^2 < 4*A*C?

           bc1f YesSolution        # if not, compute solutions

           j notSolution              # else, not solutions

           

# compute solutions

YesSolution:

           neg.s $f9, $f9                        # -4*A*C

           add.s $f9, $f8, $f9     # B^2 - 4*A*C

           sqrt.s $f9, $f9            # f9 = sqrt(B^2 - 4*A*C)

           mov.s $f7, $f1

           neg.s $f7, $f7                         # f7 = -B

           l.s $f5, two

           cvt.s.w $f5, $f5

           mul.s $f8, $f5, $f0     # f8 = 2*A

           add.s $f10, $f7, $f9

           div.s $f10, $f10, $f8   # f10 = x1

           neg.s $f9, $f9

           add.s $f11, $f7, $f9

           div.s $f11, $f11, $f8   # f11 = x2

 

           li $v0, 4 # printing string 

           la $a0,Rezult1Prompt # "\nx1 = "

           syscall 

           

           li $v0, 2 # system call code for printing a float

           mov.s $f12,$f10

           syscall 

           

           

           li $v0, 4 # printing a string

           la $a0,Rezult2Prompt

           syscall            

           

           li $v0, 2 # system call code for printing a float

           mov.s $f12,$f11

           syscall            

           

notSolution:   

 

           li $v0, 10         # finished .. stop .. return

syscall            # make the syscall



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS