News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Quadratic Equation Problem

Started by infoMASM, March 15, 2014, 09:10:30 AM

Previous topic - Next topic

infoMASM

Hey everyone!! I am attempting to write a program that takes the a, b, and c coefficients from the uswer and calculates and diplays the real roots of the polynomial using the quadratif formula. I also have to take any roots that are imaginary and display a message saying they are imaginary but that isn't my problem. Its getting how to use the quadratic formula in assembly.

If anyone can help I would really appreciate it!! Thank you!

Code I have:

INCLUDE Irvine32.inc
.data

Mssg1 BYTE "Please enter a: ",0
Mssg2 BYTE "Please enter b: ",0
Mssg3 BYTE "Please enter c: ",0

tempA DWORD ?
tempB DWORD ?
tempC DWORD ?

.code
main PROC
call Clrscr

mov edx,OFFSET Mssg1
call WriteString
call ReadDec
mov tempA, eax
call WriteDec
call Crlf

mov edx, OFFSET Mssg2
call WriteString
call ReadDec
mov tempB, eax
call WriteDec
call Crlf

mov edx, OFFSET Mssg3
call WriteString
call ReadDec
mov tempC, eax
call WriteDec
call Crlf

exit
main ENDP

END main


All I am doing is storing the values in a temp to use later on and printing the values to make sure the temps are holding the correct value.

raymond

Why not trying it first based on what you should have learned already, then try to find out yourself why it may not work based on a bit more study. Then you could submit your code for help. Whatever you learn from such experience would then accelerate your learning curve as compared to being spoon fed.
Whenever you assume something, you risk being wrong half the time.
https://masm32.com/masmcode/rayfil/index.html

Gunther

Hi infoMASM,

do the following steps:

1. calculate p = b/a and q = c/a
2. calculate D = p*p/4 - q
3. a) if D > 0: the quadratic equation  has two real solutions
    b) if D = 0: the quadratic equation has a real double solution
    c) if D < 0: the quadratic equation has two conjugated complex solutions

That leads to the following C pseudo code (if you're only interested in the real solutions):

double p = b/a;
double q = c/a;
double D = p*p/4-q;
double x1, x2;
if(D >= 0){
  x1 = -p/2 + sqrt(D);
  x2 = -p/2 -  sqrt(D);
  print x1 and x2;
}
else{
  print "No real solution";
}

I hope that helps.

Gunther
You have to know the facts before you can distort them.

MichaelW

The attachment contains a C source that is hopefully easy to understand and relate to the available information, along with the compiled executable.

For an explanation of the error that triggers the exception and returns the "-1.#IND00" result, see INDEFINITE in Raymond's FPU tutorial.

And here is the output:

17.000000
-0.438447
-4.561553

0.000000
-2.000000
-2.000000

-27.000000
        Exception type: _DOMAIN
        Function name : sqrt
        Function arg  : -27.000000
-1.#IND00
        Exception type: _DOMAIN
        Function name : sqrt
        Function arg  : -27.000000
-1.#IND00
Well Microsoft, here's another nice mess you've gotten us into.