Question: Im creating a solve quadratic formula HLA program but im having issues finding the error program solveQuadratic; #include ( stdlib.hhf ) ; static a:

Im creating a solve quadratic formula HLA program but im having issues finding the error
program solveQuadratic;
#include( "stdlib.hhf");
static
a: real32;
b: real32;
c: real32;
discriminant: real32;
root1: real32;
root2: real32;
begin solveQuadratic;
// Prompt and read values for a, b, and c
stdout.put("Gimme a value for a: ");
stdin.get(a);
stdout.put("Gimme a value for b: ");
stdin.get(b);
stdout.put("Gimme a value for c: ");
stdin.get(c);
// Calculate the discriminant
mov(b, eax);
fld(eax);
fmul(st0, st1); // b^2
fld(a);
fld(c);
fmul(st0, st1); // a * c
fadd(st0, st1); //2ac
fsub(); // b^2-4ac
fstp(discriminant);
// Compute the roots
fld(discriminant);
fsqrt();
fstp(root1); // store sqrt(discriminant) in root1
// Calculate the positive root
fld(b);
fchs(); //-b
fld(root1);
fadd(); //-b + sqrt(discriminant)
fld(a);
fadd(st0, st0); //2a
fdiv(); //(-b + sqrt(discriminant))/(2a)
fstp(root1);
// Calculate the negative root
fld(b);
fchs(); //-b
fld(root1);
fsub(); //-b - sqrt(discriminant)
fld(a);
fadd(st0, st0); //2a
fdiv(); //(-b - sqrt(discriminant))/(2a)
fstp(root2);
// Output the roots
stdout.put("x is ", root1:0:5," and x is also ", root2:0:5,"
");
end solveQuadratic;

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!