Question: Create a function for quadratic equation in MIPS assembly . I would really appreciate this. I'm kind of struggling with the whole thing. Here is
Create a function for quadratic equation in MIPS assembly. I would really appreciate this. I'm kind of struggling with the whole thing.
Here is the C++ code:
# using namespace std;
#
# 2x^2 -8x - 24 = 0
#
# -b +- SQR( b^2 - 4ac)
# x = ---------------------
# 2a
#
# x = 6.0, -2.0
#
#
# void main()
# {
# float a = 2.0, b = -8.0, c = -24.0;
# float sqroot = sqr( b*b - 4*a*c );
# float root1 = (-b + sqroot)/2*a;
# float root2 = (-b - sqroot)/2*a;
# cout << "Root1:\t" << root1 << endl;
# cout << "Root2:\t" << root2 << endl;
# }
# OUTPUT:
# Root1: 6
# Root2: -2
This is the partial MIPS assembly code
.data
.eqv SYS_PRINT_FLOAT 2 #float .eqv SYS_PRINT_TEXT 4 #text (zero terminated) .eqv SYS_EXIT 10 #terminate endl: .asciiz " " lblRoot1: .asciiz "Root1:\t" lblRoot2: .asciiz "Root2:\t"
a: .float 2.0 b: .float -8.0 c: .float -24.0 mytwo: .float 2.0 myfour: .float 4.0
.text .globl main main: # Get Determinate: b^2 - 4ac into $f0
#get square root jal sqrt #f0 input; f1 output
# plus root in $f0 #-b + sqrt(b^2 - 4ac) # /2a # minus root in $f1 #-b - sqrt(b^2 - 4ac) # /2a
# PRINT root1 in $f0 # PRINT root2 in f1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
