Question: . data prompt _ a: . asciiz Enter value for a: prompt _ b: . asciiz Enter value for b: prompt _ c:
data
prompta: asciiz "Enter value for a:
promptb: asciiz "Enter value for b:
promptc: asciiz "Enter value for c:
outputsolution: asciiz "Quadratic Equation Solver v by F Last
invalidinput: asciiz "Invalid input. Please enter a nonzero value for a andor b
imaginaryroots: asciiz "Roots are imaginary.
solution: asciiz xf xf
text
globl main
main:
# Print output header
li $v
la $a outputsolution
syscall
# Prompt user for coefficients
jal promptcoefficients
# Calculate discriminant
ld $f$f # Load a into $f
ld $f$f # Load b into $f
ld $f$f # Load c into $f
mul.d $f $f $f # b
mul.d $f $f $f # ac
mul.d $f $f $f # ac a
sub.d $f $f $f # bac
mov.d $f $f # Store discriminant
# Check for nonquadratic equation
beq $f $f notquadratic
beq $f $f notquadratic
# Check if roots are imaginary
blez $f imaginary
# Calculate roots
sqrtd $f $f
ld $f$f # Load b into $f
neg.d $f $f # b
add.d $f $f $f
div.d $f $f $f # xb sqrtbaca
ld $f$f # Load b into $f
sub.d $f $f $f
div.d $f $f $f # xb sqrtbaca
# Print solutions
li $v
mov.d $f $f
syscall
li $v
la $a solution
syscall
mov.d $f $f
syscall
j exit
notquadratic:
# Print error message for nonquadratic equation
li $v
la $a invalidinput
syscall
j exit
imaginary:
# Print error message for imaginary roots
li $v
la $a imaginaryroots
syscall
j exit
promptcoefficients:
# Prompt for coefficient a
li $v
la $a prompta
syscall
li $v
syscall
mfc $f $v
# Prompt for coefficient b
li $v
la $a promptb
syscall
li $v
syscall
mfc $f $v
# Prompt for coefficient c
li $v
la $a promptc
syscall
li $v
syscall
mfc $f $v
jr $ra
exit:
# Exit program
li $v
syscall
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
