Question: . data prompt _ a: . asciiz Enter value for a: prompt _ b: . asciiz Enter value for b: prompt _ c:

.data
prompt_a: .asciiz "Enter value for a: "
prompt_b: .asciiz "Enter value for b: "
prompt_c: .asciiz "Enter value for c: "
output_solution: .asciiz "Quadratic Equation Solver v0.1 by F. Last
"
invalid_input: .asciiz "Invalid input. Please enter a non-zero value for a and/or b.
"
imaginary_roots: .asciiz "Roots are imaginary.
"
solution: .asciiz "x1=%.2f, x2=%.2f
"
.text
.globl main
main:
# Print output header
li $v0,4
la $a0, output_solution
syscall
# Prompt user for coefficients
jal prompt_coefficients
# Calculate discriminant
l.d $f4,0($f12) # Load a into $f4
l.d $f6,0($f14) # Load b into $f6
l.d $f8,0($f16) # Load c into $f8
mul.d $f10, $f6, $f6 # b^2
mul.d $f12, $f4, $f8 # 4ac
mul.d $f12, $f12, $f2 # 4ac * a
sub.d $f10, $f10, $f12 # b^2-4ac
mov.d $f12, $f10 # Store discriminant
# Check for non-quadratic equation
beq $f4, $f0, not_quadratic
beq $f6, $f0, not_quadratic
# Check if roots are imaginary
blez $f10, imaginary
# Calculate roots
sqrt.d $f10, $f10
l.d $f12,0($f12) # Load -b into $f12
neg.d $f12, $f12 # -b
add.d $f10, $f12, $f10
div.d $f10, $f10, $f4 # x1=(-b + sqrt(b^2-4ac))/2a
l.d $f12,0($f12) # Load -b into $f12
sub.d $f12, $f12, $f10
div.d $f12, $f12, $f4 # x2=(-b - sqrt(b^2-4ac))/2a
# Print solutions
li $v0,2
mov.d $f12, $f10
syscall
li $v0,4
la $a0, solution
syscall
mov.d $f12, $f10
syscall
j exit
not_quadratic:
# Print error message for non-quadratic equation
li $v0,4
la $a0, invalid_input
syscall
j exit
imaginary:
# Print error message for imaginary roots
li $v0,4
la $a0, imaginary_roots
syscall
j exit
prompt_coefficients:
# Prompt for coefficient a
li $v0,4
la $a0, prompt_a
syscall
li $v0,7
syscall
mfc1 $f12, $v0
# Prompt for coefficient b
li $v0,4
la $a0, prompt_b
syscall
li $v0,7
syscall
mfc1 $f14, $v0
# Prompt for coefficient c
li $v0,4
la $a0, prompt_c
syscall
li $v0,7
syscall
mfc1 $f16, $v0
jr $ra
exit:
# Exit program
li $v0,10
syscall

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!