News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Quadratic Square Root Code Problem

Started by etow, January 30, 2008, 03:13:23 PM

Previous topic - Next topic

etow

Hi

My updated code below:

--------------------------------------------------------------------------

.686 ; create 32 bit code
.Model flat, StdCall  ;32 bit memory model
Option CaseMap :none  ; case sensitive

;The MASM32 Runtime Library include file.
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Include \masm32\include\masm32rt.inc


.Code

start:
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Call Main
    inkey        ; pause the screen while waiting for user to press any key
                   ; to continue
    exit
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

InputR10 Proc pR10:Ptr Real10
    LOCAL r8:REAL8
    invoke crt_scanf, SADD("%lf"), ADDR r8
    mov eax, pR10
    finit
    fld r8
    fstp REAL10 PTR [eax]
    ret
InputR10 EndP


calculateQuadraticRoots Proto:Real8, :Real8, :Real8

Main Proc
  Local WantContinue:DWord
  Local NumberA:Real8
  Local NumberB:Real8
  Local NumberC:Real8
  ; WantContinue is a sentinel value for while loop
  ; NumberA is the X^2 coefficient of the quadratic equation
  ; NumberB is the X coefficient of the quadratic equation
  ; NumberC is the constant of the quadratic equation
  ; NumberA, NumberB, and NumberC are user's integer values entered

    Mov WantContinue, 0  ; set WantContinue to 0 to start while loop

    .While ((WantContinue >= 0) && (WantContinue < -1))
       print chr$(13, 10) ; a carriage return line feed will be outputted to the
                          ; screen
       print chr$("Quadratic Equation : Ax^2 + Bx + C ", 13, 10, 13, 10)
       print chr$("Enter an integer value for Number A : ")
       Invoke InputR10, Addr NumberA
       print chr$("Enter an integer value for Number B : ")
       Invoke InputR10, Addr NumberB
       print chr$("Enter an integer value for Number C : ")
       Invoke InputR10, Addr NumberC
       Invoke calculateQuadraticRoots, NumberA, NumberB, NumberC
       print chr$(13, 10)
       Mov WantContinue, sval(input("Enter -1 to quit program : "))
       print chr$(13, 10)
    .EndW
  Ret
Main EndP

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;<<   calculateQuadraticRoots procedure will calculate two real roots    <<
;<<   of a quadratic equation by receiving three coefficients from       <<
;<<   user as input                                                      <<
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

calculateQuadraticRoots Proc A_Number:Real8, B_Number:Real8, C_Number:Real8
  Local squareRootNumber:Real8
   Local negativeB:Real8
   Local resultOfSquareRoot:Real8
   Local denominator:Real8
   Local signedRoot1:Real8
   Local signedRoot2:Real8
  ; squareRootNumber is the square root part of the quadratic formula
  ; negativeB is the negation of b of the quadratic formula
  ; resultOfSquareRoot is the result after getting square root of number
  ;  of the quadratic formula
  ; signedRoot1 and signedRoot2 are the string arrays which are the two X solutions
  ;  to the quadratic formula
  ; numerator1 and numerator2 are the numerator part of the quadratic formula
  ;  that has two solutions
  ; denominator is the denominator of the quadratic formula

  ; Eax, Ebx, Ecx, Edx, Esi, Edi are registers

  ; Quadratic Formula:  x = (-b +/- sqrt(b^2 - 4*a*c)) / (2*a)

.If (A_Number != 0.0)      ; if A_Number is not equal to zero

    Fld (A_Number)     ; st(0) = A_Number
    Fld (C_Number)     ; st(0) = C_Number , st(1) = A_Number
    Fmulp St(1), St    ; st(1) = st(1) * st(0) = A_Number * C_Number
    Fld (-4.0)         ; st(0) = -4.0 , st(1) = A_Number * C_Number
    Fmulp St(1), St    ; st(1) = st(1) * st(0) = A_Number * C_Number * -4.0
    Fld (B_Number)     ; st(0) = B_Number , st(1) = A_Number * C_Number * -4.0
    Fmul St, St        ; st(0) = st(0) * st(0) = B_Number * B_Number
    Faddp St(1), St    ; st(1) = st(1) + st(0)
                       ;       = A_Number * C_Number * -4.0 + B_Number * B_Number
    Fstp squareRootNumber ; squareRootNumber = St(1) + St(0)

   .If (squareRootNumber > SDWord Ptr - 1.0) ; if squareRootNumber > -1.0
      Fsqrt                                 ; Sqrt st(0)
      Fstp resultOfSquareRoot      ; resultOfSquareRoot = sqrt st(0)
      Fld (B_Number)                  ; st(0) = B_Number
      Fchs                                 ; st(0) = -B_Number
      Fstp negativeB                  ; negativeB = st(0)
      Fld negativeB                    ; st(0) = negativeB
      Fld resultOfSquareRoot       ; st(0) = resultOfSquareRoot , st(1) = negativeB
      Faddp St(1), St                 ; st(1) = st(1) + st(0) = negativeB + resultOfSquareRoot
      Fstp numerator1               ; numerator1  = st(0)
      Fld (A_Number)                ; st(0) = A_Number     
      Fld (2.0)                          ; st(0) = 2.0 , st(1) = A_Number
      Fmulp St(1), St                ; st(1) = st(1) * st(0) = A_Number * 2.0
      Fstp denominator             ; denominator = st(0)
      Fld (numerator1)            ; st(0) = numerator1
      Fld (denominator)             ; st(0) = denominator , st(1) numerator1
      Fdivp St(1), St                ; st(1) = st(1) / st(0) = numerator1 / denominator
      Fstp signedRoot1            ; signedRoot1 = st(1) = numerator1 / denominator

      Fld negativeB                ;   st(0) = negativeB
      Fld resultOfSquareRoot  ;    st(0) = resultOfSquareRoot , st(1) = negativeB
      Fchs                           ;    st(0) = -resultOfSquareRoot
      Faddp St(1), St            ;    st(1) = st(1) + st(0) = negativeB + -resultOfSquareRoot
      Fld denominator           ;    st(0) = denominator , st(1) = negativeB + resultOfSquareRoot
      Fdivp St(1), St            ;    st(1) = st(1) / st(0) = (negativeB + resultOfSquareRoot) / denominator
      Fstp signedRoot2        ;    signedRoot2 = st(1)

      print chr$(13, 10)  ; a carriage return line feed will be outputted to the
                          ; screen
      print chr$(" Solutions for quadratic equation : ")

      ; The following if else statements output the format of the quadratic
      ; equation

      .If (A_Number == -1.0)  ; if A_Number equals to -1.0
      print chr$("-X^2 ")
      .ElseIf (A_Number == 1.0) ; if A_Number equals to 1.0
        print chr$("X^2 ")
      .ElseIf ((A_Number > 1.0) || (A_Number < SDWord Ptr - 1.0))
      ; if A_Number greater than 1.0 Or A_Number less than - 1.0
        print real8$ (A_Number)
        print chr$("X^2 ")
      .EndIf

      .If (B_Number < SDWord Ptr - 1.0) ; if B_Number less than -1.0
      print real8$ (B_Number)
      print chr$("X ")
      .ElseIf (B_Number == -1.0) ; if B_Number equals to -1.0
      print chr$("- X ")
      .ElseIf (B_Number == 1.0)  ; if B_Number equals to 1.0
      print chr$("+ X ")
      .ElseIf (B_Number > 1.0)   ; if B_Number greater than 1.0
      print chr$("+ ")
      print real8$ (B_Number)
        print chr$("X ")
      .EndIf

      .If (C_Number < SDWord Ptr - 1.0) ; if C_Number less than -1.0
        print real8$ (C_Number)
      .ElseIf (C_Number == -1.0)  ; if C_Number equals to -1.0
      print chr$("- ")
        print chr$("1")
      .ElseIf (C_Number > 0.0)  ; if C_Number greater than 0.0
      print chr$("+ ")
    print real8$ (C_Number)
      .EndIf

      print chr$(13, 10, 13, 10) ; two carriage return line feeds will be
                                 ; outputted to the screen
      print chr$(" X = ")
      print real8$ (signedRoot1)   ; print signedRoot1 string array
      print chr$(13, 10)
      print chr$("  1 ", 13, 10)
      print chr$(" X = ")
      print real8$ (signedRoot2)  ; print signedRoot2 string array
      print chr$(13, 10)
      print chr$("  2 ", 13, 10)
      print chr$(13, 10)

   .ElseIf (squareRootNumber <= SDWord Ptr - 1.0) ;
      ; if squareRootNumber less than or equal to -1.0
      print chr$(13, 10)
      print chr$("There are no real solutions for the quadratic equation : ")

      ; The following if else statements output the format of the quadratic
      ; equation

      .If (A_Number == -1.0)  ; if A_Number equals to -1.0
      print chr$("-X^2 ")
      .ElseIf (A_Number == 1.0) ; if A_Number equals to 1.0
        print chr$("X^2 ")
      .ElseIf ((A_Number > 1.0) || (A_Number < SDWord Ptr - 1.0))
      ; if A_Number greater than 1.0 OR A_Number less than -1.0
        print real8$ (A_Number)
        print chr$("X^2 ")
      .EndIf

      .If (B_Number < SDWord Ptr - 1.0) ; if B_Number less than -1.0
      print real8$ (B_Number)
      print chr$("X ")
      .ElseIf (B_Number == -1.0) ; if B_Number equals to -1.0
      print chr$("- X ")
      .ElseIf (B_Number == 1.0)  ; if B_Number equals to 1.0
      print chr$("+ X ")
      .ElseIf (B_Number > 1.0)   ; if B_Number greater than 1.0
      print chr$("+ ")
      print real8$ (B_Number)
        print chr$("X ")
      .EndIf

      .If (C_Number < SDWord Ptr - 1.0) ; if C_Number less than -1.0
        print real8$ (C_Number)
      .ElseIf (C_Number == -1.0)  ; if C_Number equals to -1.0
      print chr$("- ")
        print chr$("1")
      .ElseIf (C_Number > 0.0)  ; if C_Number greater than 0.0
      print chr$("+ ")
    print real8$ (C_Number)
      .EndIf

      print chr$(" !", 13, 10, 13, 10) ; ! will be outputted along with two
                                       ; carriage return line feeds to the screen
   .EndIf
.ElseIf
print chr$(13, 10)
print chr$("Error, Division by zero!", 13, 10, 13, 10) ; if A_Number == 0
.EndIf
  Ret
calculateQuadraticRoots EndP

End start


----------------------------------------------------------------------------------------
The following are my debug error messages:

============== QuadraticSolutions - Debug ==============

Assembling: Module1
Module1.asm(2) : warning A4011: multiple .MODEL directives found : .MODEL ignored
\masm32\include\masm32rt.inc(33) : warning A4011: multiple .MODEL directives found : .MODEL ignored
------------------------------------------
WARNING Duplicate include file windows.inc
------------------------------------------
-----------------------------------------
WARNING Duplicate include file user32.inc
-----------------------------------------
-----------------------------------------
WARNING Duplicate include file kernel32.inc
-----------------------------------------
Module1.asm(91) : error A2050: real or BCD number not allowed
Module1.asm(96) : error A2009: syntax error in expression
Module1.asm(104) : error A2009: syntax error in expression
Module1.asm(112) : error A2050: real or BCD number not allowed
Module1.asm(133) : error A2050: real or BCD number not allowed
Module1.asm(135) : error A2050: real or BCD number not allowed
Module1.asm(137) : error A2050: real or BCD number not allowed
Module1.asm(137) : error A2009: syntax error in expression
Module1.asm(143) : error A2009: syntax error in expression
Module1.asm(146) : error A2050: real or BCD number not allowed
Module1.asm(148) : error A2050: real or BCD number not allowed
Module1.asm(150) : error A2050: real or BCD number not allowed
Module1.asm(156) : error A2009: syntax error in expression
Module1.asm(158) : error A2050: real or BCD number not allowed
Module1.asm(161) : error A2050: real or BCD number not allowed
Module1.asm(178) : error A2009: syntax error in expression
Module1.asm(186) : error A2050: real or BCD number not allowed
Module1.asm(188) : error A2050: real or BCD number not allowed
Module1.asm(190) : error A2050: real or BCD number not allowed
Module1.asm(190) : error A2009: syntax error in expression
Module1.asm(196) : error A2009: syntax error in expression
Module1.asm(199) : error A2050: real or BCD number not allowed
Module1.asm(201) : error A2050: real or BCD number not allowed
Module1.asm(203) : error A2050: real or BCD number not allowed
Module1.asm(209) : error A2009: syntax error in expression
Module1.asm(211) : error A2050: real or BCD number not allowed
Module1.asm(214) : error A2050: real or BCD number not allowed

Errors ocurred.
--------------------------------------------------------------------

How do I solve these error messages with comparision run time operators related to integers that can be used for floating point or real numbers and floating point instructions.

Please help me.

Thanks

GregL

etow,

You need to go back and read what people have told you, more than once, about include files. Take a look at what 'masm32rt.inc' contains. Whatever it contains does not need to be included in your code again.

You cannot use real numbers with the MASM high-level directives like .IF. To compare real numbers you must use an FPU instruction like FCOM. Read about FCOM in SimplyFPU, there is example code too.


RuiLoureiro

#32
Hi etow,
            1. It is too hard to follow, yet.

            2. I think you cannot load constants like  *** fld     -4   ***, ***  fld    2 ****

            3. To calculate 2a:   fld          A_Number
                                         fld          st(0)              ; copy to new st(0)
                                         fadd                            ; st0= 2a

            4. To test b^2-4ac:
                                            ftst           
                                            fwait
                                            fstsw   ax

            5.  Why not to use global variables ?
                 .DATA
                  Number4       REAL10   4.0                 then        fld     Number4

            6. Cannot you divide calculateQuadraticRoots in such a way that it only calculate
                signedRoot1 and signedRoot2 ? It can exit with EAX = 0 meaning OK, EAX=1 -> error
                EAX= 2 ... etc. Put the other things in another proc if you can

            7. Cannot you test A_Number before calling calculateQuadraticRoots ? You dont call if
                 it is 0.

            8. You can calculate Root1 and Root2 without using local variables. FPU has 8 registers and
                you can use it. Think about this. How to use them better


RuiLoureiro


GregL

#33
Quote from: RuiLoureiro2. I think you cannot load constants like  *** fld     -4   ***, ***  fld    2 ****

That's right, you can't.

There are some MASM32 macros for doing this called FP4, FP8 and FP10. Also see the fld4, fld8 and fld10 macros.


fld FP10(5.5)
fld FP10(2.5)

fld10 5.5
fld10 2.5



GregL

Some macros I wrote for comparing real numbers:


; ====================================
isgreater MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    ja    true
    jbe   false
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM
; ====================================
isgreaterequal MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    jae   true
    jb    false
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM 
; ====================================
isless MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    jae   false
    jb    true
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM 
; ====================================
islessequal MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    ja    false
    jbe   true
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM 
; ====================================
isnotequal MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    ja    true
    jb    true
    jz    false
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM 
; ====================================
isequal MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    ja    false
    jb    false
    jz    true
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM 
; ====================================
islessgreater MACRO r1:REQ, r2:REQ
    EXITM <isnotequal(r1, r2)>
ENDM
; ====================================
isapproxequal MACRO r1:REQ, r2:REQ, tolerance:REQ
    LOCAL diff
    .DATA?
        diff REAL10 ?
    .CODE   
    finit
    .IF isgreater(r1, r2)
        fld   r2
        fld   r1
    .ELSE
        fld   r1
        fld   r2
    .ENDIF   
    fsub
    fstp  diff
    fwait
    EXITM <islessequal(diff, tolerance)>
ENDM
; ====================================


Usage:


.IF isgreater(r1, r2)
    ...
.ENDIF



etow

Hi Greg,

for example in one of your macros isgreater than what is REQ data type means for r1 and r2
Can you use for example do this?,

                                      .If isgreater(st(0),-1.0)
                                            ....
                                      .Endif




etow

hi Greg,

Can you do this,

.If isgreater(Real10 Ptr [Eax],-1.0)
  ....
.Endif

etow

Here is my updated code below:


.686 ; create 32 bit code
;The MASM32 Runtime Library include file.
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Include \masm32\include\masm32rt.inc
Include \masm32\fpulib\fpu.inc
IncludeLib \masm32\fpulib\fpu.lib

.Data
Number2  Real10  2.0
NumberNegative4 Real10 - 4.0

.Code

start:
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Call Main
    inkey        ; pause the screen while waiting for user to press any key
                   ; to continue
    exit
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

InputR10 Proc pR10:Ptr Real10
    LOCAL r8:REAL8
    invoke crt_scanf, SADD("%lf"), ADDR r8
    mov eax, pR10
    finit
    fld r8
    fstp REAL10 PTR [eax]
    ret
InputR10 EndP


; ====================================
isgreater MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    ja    true
    jbe   false
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM
; ====================================
isgreaterequal MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    jae   true
    jb    false
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM 
; ====================================
isless MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    jae   false
    jb    true
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM 
; ====================================
islessequal MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    ja    false
    jbe   true
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM 
; ====================================
isnotequal MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    ja    true
    jb    true
    jz    false
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM 
; ====================================
isequal MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    ja    false
    jb    false
    jz    true
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM 
; ====================================
islessgreater MACRO r1:REQ, r2:REQ
    EXITM <isnotequal(r1, r2)>
ENDM
; ====================================
isapproxequal MACRO r1:REQ, r2:REQ, tolerance:REQ
    LOCAL diff
    .DATA?
        diff REAL10 ?
    .CODE   
    finit
    .IF isgreater(r1, r2)
        fld   r2
        fld   r1
    .ELSE
        fld   r1
        fld   r2
    .ENDIF   
    fsub
    fstp  diff
    fwait
    EXITM <islessequal(diff, tolerance)>
ENDM
; ====================================


calculateQuadraticRoots Proto:Ptr Real10, Ptr Real10, Ptr Real10
printFormat Proto:Ptr Real10, Ptr Real10, Ptr Real10

Main Proc
  Local WantContinue:DWord
  Local NumberA:Real10
  Local NumberB:Real10
  Local NumberC:Real10
  ; WantContinue is a sentinel value for while loop
  ; NumberA is the X^2 coefficient of the quadratic equation
  ; NumberB is the X coefficient of the quadratic equation
  ; NumberC is the constant of the quadratic equation
  ; NumberA, NumberB, and NumberC are user's integer values entered

    Mov WantContinue, 0  ; set WantContinue to 0 to start while loop

    .While ((WantContinue >= 0) && (WantContinue < -1))
       print chr$(13, 10) ; a carriage return line feed will be outputted to the
                          ; screen
       print chr$("Quadratic Equation : Ax^2 + Bx + C ", 13, 10, 13, 10)
       print chr$("Enter an integer value for Number A : ")
       Invoke InputR10, Addr NumberA
       print chr$("Enter an integer value for Number B : ")
       Invoke InputR10, Addr NumberB
       print chr$("Enter an integer value for Number C : ")
       Invoke InputR10, Addr NumberC

     .If isnotequal(Addr NumberA, 0.0) ; if NumberA != 0.0
       Invoke calculateQuadraticRoots, Addr NumberA, Addr NumberB, Addr NumberC
       print chr$(13, 10)
     .ElseIf isequal(Addr NumberA, 0.0)
    print chr$(13, 10)
    print chr$("Error, Division by zero!", 13, 10, 13, 10) ; if NumberA == 0
     .EndIf
       Mov WantContinue, sval(input("Enter -1 to quit program : "))
       print chr$(13, 10)
    .EndW
  Ret
Main EndP

printFormat Proc A_Number:Ptr Real10, B_Number:Ptr Real10, C_Number:Ptr Real10
    Mov Eax, A_Number
    Mov Ebx, B_Number
    Mov Ecx, C_Number

    .If isequal(Real10 Ptr [Eax], -1.0)
    ; if A_Number equals to -1.0
     print chr$("-X^2 ")
    .ElseIf isequal(Real10 Ptr [Eax], 1.0)
     ; if A_Number equals to 1.0
       print chr$("X^2 ")
    .ElseIf (isgreater(Real10 Ptr [Eax], 1.0) || islessthan (Real10 Ptr [Eax, -1.0))
     ; if A_Number greater than 1.0 Or A_Number less than - 1.0
       print real10$ (A_Number)
       print chr$("X^2 ")
    .EndIf

    .If isless(Real10 Ptr [Ebx], -1.0)
    ; if B_Number less than -1.0
       print real10$ (B_Number)
       print chr$("X ")
    .ElseIf isequal(Real10 Ptr [Ebx], -1.0)
    ; if B_Number equals to -1.0
       print chr$("- X ")
    .ElseIf isequal(Real10 Ptr [Ebx], 1.0)
    ; if B_Number equals to 1.0
       print chr$("+ X ")
    .ElseIf isgreater(Real10 Ptr [Ebx], 1.0)
    ; if B_Number greater than 1.0
       print chr$("+ ")
       print real10$ (B_Number)
       print chr$("X ")
    .EndIf

    .If isless(Real10 Ptr [Ecx], -1.0)
    ; if C_Number less than -1.0
       print real10$ (C_Number)
    .ElseIf isequal(Real10 Ptr [Ecx], -1.0)
    ; if C_Number equals to -1.0
       print chr$("- ")
       print chr$("1")
    .ElseIf isgreater(Real10 Ptr [Ecx], 0.0)
    ; if C_Number greater than 0.0
       print chr$("+ ")
       print real10$ (C_Number)
    .EndIf

Ret
printFormat EndP

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;<<   calculateQuadraticRoots procedure will calculate two real roots    <<
;<<   of a quadratic equation by receiving three coefficients from       <<
;<<   user as input                                                      <<
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

calculateQuadraticRoots Proc A_Number:Ptr Real10, B_Number:Ptr Real10, C_Number:Ptr Real10
   Local squareRootNumber:Real10
   Local negativeB:Real10
   Local resultOfSquareRoot:Real10
   Local numerator1:Real10
   Local denominator:Real10
   Local signedRoot1:Real10
   Local signedRoot2:Real10
  ; squareRootNumber is the square root part of the quadratic formula
  ; negativeB is the negation of b of the quadratic formula
  ; resultOfSquareRoot is the result after getting square root of number
  ;  of the quadratic formula
  ; signedRoot1 and signedRoot2 are the string arrays which are the two X solutions
  ;  to the quadratic formula
  ; numerator1 and numerator2 are the numerator part of the quadratic formula
  ;  that has two solutions
  ; denominator is the denominator of the quadratic formula

  ; Eax, Ebx, Ecx, Edx are registers
  ; St(i) are Fpu registers

  ; Quadratic Formula:  x = (-b +/- sqrt(b^2 - 4*a*c)) / (2*a)

   Mov Eax, A_Number
   Mov Ebx, B_Number
   Mov Ecx, C_Number

   Fld Real10 Ptr [Eax] ; st(0) = A_Number
   Fld Real10 Ptr [Ecx] ; st(0) = C_Number , st(1) = A_Number
   Fmulp St(1), St    ; st(1) = st(1) * st(0) = A_Number * C_Number
   Fld (NumberNegative4) ; st(0) = -4.0 , st(1) = A_Number * C_Number
   Fmulp St(1), St    ; st(1) = st(1) * st(0) = A_Number * C_Number * -4.0
   Fld Real10 Ptr [Ebx] ; st(0) = B_Number , st(1) = A_Number * C_Number * -4.0
   Fmul St, St        ; st(0) = st(0) * st(0) = B_Number * B_Number
   Faddp St(1), St ; st(1) = st(1) + st(0)
                   ;       = A_Number * C_Number * -4.0 + B_Number * B_Number
   Fstp squareRootNumber ; squareRootNumber = St(1) + St(0)

   Fld squareRootNumber  ; st(0) = squareRootNumber

   .If isgreater(squareRootNumber, -1.0)
      ; if squareRootNumber greater than -1.0
      Fsqrt                   ; Sqrt st(0)
      Fstp resultOfSquareRoot ; resultOfSquareRoot = sqrt st(0)
      Fld Real10 Ptr [Ebx]    ; st(0) = B_Number
      Fchs                    ; st(0) = -B_Number
      Fstp negativeB          ; negativeB = st(0)
      Fld negativeB          ; st(0) = negativeB
      Fld resultOfSquareRoot ; st(0) = resultOfSquareRoot , st(1) = negativeB
      Faddp St(1), St        ; st(1) = st(1) + st(0) = negativeB + resultOfSquareRoot
      Fstp numerator1        ; numerator1  = st(0)
      Fld Real10 Ptr [Eax]   ; st(0) = A_Number
      Fld (Number2)          ; st(0) = 2.0 , st(1) = A_Number
      Fmulp St(1), St        ; st(1) = st(1) * st(0) = A_Number * 2.0
      Fstp denominator       ; denominator = st(0)
      Fld (numerator1)       ; st(0) = numerator1
      Fld (denominator)      ; st(0) = denominator , st(1) numerator1
      Fdivp St(1), St        ; st(1) = st(1) / st(0) = numerator1 / denominator
      Fstp signedRoot1       ; signedRoot1 = st(1) = numerator1 / denominator

      Ffree St(0)
      Fld negativeB           ; st(0) = negativeB
      Fld resultOfSquareRoot  ; st(0) = resultOfSquareRoot , st(1) = negativeB
      Fchs                    ; st(0) = -resultOfSquareRoot
      Faddp St(1), St         ; st(1) = st(1) + st(0) = negativeB + -resultOfSquareRoot
      Fld denominator         ; st(0) = denominator , st(1) = negativeB + resultOfSquareRoot
      Fdivp St(1), St         ; st(1) = st(1) / st(0) = (negativeB + resultOfSquareRoot) / denominator
      Fstp signedRoot2        ; signedRoot2 = st(1)

      print chr$(13, 10)  ; a carriage return line feed will be outputted to the
                          ; screen
      print chr$(" Solutions for quadratic equation : ")

      ; The following statement call output format procedure of the quadratic
      ; equation

      Invoke printFormat, Addr A_Number, Addr B_Number, Addr C_Number

      print chr$(13, 10, 13, 10) ; two carriage return line feeds will be
                                 ; outputted to the screen
      print chr$(" X = ")
      print real10$ (signedRoot1)   ; print signedRoot1 string array
      print chr$(13, 10)
      print chr$("  1 ", 13, 10)
      print chr$(" X = ")
      print real10$ (signedRoot2)  ; print signedRoot2 string array
      print chr$(13, 10)
      print chr$("  2 ", 13, 10)
      print chr$(13, 10)

    .ElseIf islessequal(squareRootNumber, -1.0)
      ; if squareRootNumber less than or equal to -1.0
      print chr$(13, 10)
      print chr$("There are no real solutions for the quadratic equation : ")

      ; The following statement call output format procedure of the quadratic
      ; equation

      Invoke printFormat, Addr A_Number, Addr B_Number, Addr C_Number

      print chr$(" !", 13, 10, 13, 10) ; ! will be outputted along with two
                                       ; carriage return line feeds to the screen
   .EndIf
  Ret
calculateQuadraticRoots EndP

End start

-------------------------------------------------------------------

Here are my debugger error messages below:

============== QuadraticSolutions - Debug ==============

Module1.asm(217) : error A2008: syntax error : ptr
Module1.asm(218) : error A2008: syntax error : ptr
Module1.asm(244) : error A2008: syntax error : Addr
isnotequal(4): Macro Called From
  Module1.asm(244): Include File
Module1.asm(247) : error A2008: syntax error : Addr
isequal(4): Macro Called From
  Module1.asm(247): Include File
Module1.asm(268) : error A2008: syntax error : ,
-------------------------
real10$ - requires REAL10
-------------------------
-------------------------
real10$ - requires REAL10
-------------------------
-------------------------
real10$ - requires REAL10
-------------------------
-------------------------
real10$ - requires REAL10
-------------------------
-------------------------
real10$ - requires REAL10
-------------------------
Module1.asm(243) : error A2050: real or BCD number not allowed
isnotequal(3): Macro Called From
  Module1.asm(243): Include File
Module1.asm(246) : error A2050: real or BCD number not allowed
isequal(3): Macro Called From
  Module1.asm(246): Include File
Module1.asm(261) : error A2050: real or BCD number not allowed
isequal(3): Macro Called From
  Module1.asm(261): Include File
Module1.asm(264) : error A2050: real or BCD number not allowed
isequal(3): Macro Called From
  Module1.asm(264): Include File
Module1.asm(267) : error A2050: real or BCD number not allowed
isgreater(3): Macro Called From
  Module1.asm(267): Include File
Module1.asm(273) : error A2050: real or BCD number not allowed
isless(3): Macro Called From
  Module1.asm(273): Include File
Module1.asm(277) : error A2050: real or BCD number not allowed
isequal(3): Macro Called From
  Module1.asm(277): Include File
Module1.asm(280) : error A2050: real or BCD number not allowed
isequal(3): Macro Called From
  Module1.asm(280): Include File
Module1.asm(283) : error A2050: real or BCD number not allowed
isgreater(3): Macro Called From
  Module1.asm(283): Include File
Module1.asm(290) : error A2050: real or BCD number not allowed
isless(3): Macro Called From
  Module1.asm(290): Include File
Module1.asm(293) : error A2050: real or BCD number not allowed
isequal(3): Macro Called From
  Module1.asm(293): Include File
Module1.asm(297) : error A2050: real or BCD number not allowed
isgreater(3): Macro Called From
  Module1.asm(297): Include File
Module1.asm(352) : error A2050: real or BCD number not allowed
isgreater(3): Macro Called From
  Module1.asm(352): Include File
Module1.asm(402) : error A2050: real or BCD number not allowed
islessequal(3): Macro Called From
  Module1.asm(402): Include File
Module1.asm(270) : error A2052: forced error
real10$(14): Macro Called From
  print(0): Macro Called From
   Module1.asm(270): Include File
Module1.asm(276) : error A2052: forced error
real10$(12): Macro Called From
  print(0): Macro Called From
   Module1.asm(276): Include File
Module1.asm(287) : error A2052: forced error
real10$(12): Macro Called From
  print(0): Macro Called From
   Module1.asm(287): Include File
Module1.asm(293) : error A2052: forced error
real10$(12): Macro Called From
  print(0): Macro Called From
   Module1.asm(293): Include File
Module1.asm(301) : error A2052: forced error
real10$(12): Macro Called From
  print(0): Macro Called From
   Module1.asm(301): Include File

Errors ocurred.

etow

.686 ; create 32 bit code
;The MASM32 Runtime Library include file.
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Include   \masm32\include\masm32rt.inc
Include   \masm32\fpulib\fpu.inc
IncludeLib   \masm32\fpulib\fpu.lib

.Data
Number2  Real10  2.0
NumberNegative4 Real10 - 4.0

.Code

start:
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Call Main
    inkey        ; pause the screen while waiting for user to press any key
                   ; to continue
    exit
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

InputR10 Proc pR10:Ptr Real10
    LOCAL r8:REAL8
    invoke crt_scanf, SADD("%lf"), ADDR r8
    mov eax, pR10
    finit
    fld r8
    fstp REAL10 PTR [eax]
    ret
InputR10 EndP


; ====================================
isgreater MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    ja    true
    jbe   false
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM
; ====================================
isgreaterequal MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    jae   true
    jb    false
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM 
; ====================================
isless MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    jae   false
    jb    true
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM 
; ====================================
islessequal MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    ja    false
    jbe   true
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM 
; ====================================
isnotequal MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    ja    true
    jb    true
    jz    false
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM 
; ====================================
isequal MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    ja    false
    jb    false
    jz    true
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM 
; ====================================
islessgreater MACRO r1:REQ, r2:REQ
    EXITM <isnotequal(r1, r2)>
ENDM
; ====================================
isapproxequal MACRO r1:REQ, r2:REQ, tolerance:REQ
    LOCAL diff
    .DATA?
        diff REAL10 ?
    .CODE   
    finit
    .IF isgreater(r1, r2)
        fld   r2
        fld   r1
    .ELSE
        fld   r1
        fld   r2
    .ENDIF   
    fsub
    fstp  diff
    fwait
    EXITM <islessequal(diff, tolerance)>
ENDM
; ====================================


calculateQuadraticRoots Proto:Ptr Real10, Ptr Real10, Ptr Real10
printFormat Proto:Ptr Real10, Ptr Real10, Ptr Real10

Main Proc
  Local WantContinue:DWord
  Local NumberA:Real10
  Local NumberB:Real10
  Local NumberC:Real10
  Local counter:DWord
  ; WantContinue is a sentinel value for while loop
  ; NumberA is the X^2 coefficient of the quadratic equation
  ; NumberB is the X coefficient of the quadratic equation
  ; NumberC is the constant of the quadratic equation
  ; NumberA, NumberB, and NumberC are user's integer values entered

    Mov WantContinue, 0  ; set WantContinue to 0 to start while loop

    .While ((WantContinue >= 0) && (WantContinue < -1))
       print chr$(13, 10) ; a carriage return line feed will be outputted to the
                          ; screen
       print chr$("Quadratic Equation : Ax^2 + Bx + C ", 13, 10, 13, 10)
       print chr$("Enter an integer value for Number A : ")
       Invoke InputR10, Addr NumberA
       print chr$("Enter an integer value for Number B : ")
       Invoke InputR10, Addr NumberB
       print chr$("Enter an integer value for Number C : ")
       Invoke InputR10, Addr NumberC

     .If isnotequal(Addr NumberA, 0.0) ; if NumberA != 0.0
       Invoke calculateQuadraticRoots, Addr NumberA, Addr NumberB, Addr NumberC
       print chr$(13, 10)
     .ElseIf isequal(Addr NumberA, 0.0) ; if NumberA == 0.0
       print chr$(13, 10)
       print chr$("Error, Division by zero!", 13, 10, 13, 10)
     .EndIf
       Mov WantContinue, sval(input("Enter -1 to quit program : "))
       print chr$(13, 10)

       Mov counter, 0
       .While counter <= 8
            Ffree St (counter)
            Inc counter
       .EndW

    .EndW
  Ret
Main EndP

printFormat Proc A_Number:Ptr Real10, B_Number:Ptr Real10, C_Number:Ptr Real10
    Mov Eax, A_Number
    Mov Ebx, B_Number
    Mov Ecx, C_Number

    Fld Real10 Ptr [Eax]
    .If isequal(St(0), -1.0)
    ; if A_Number equals to -1.0
        print chr$("-X^2 ")
    .ElseIf isequal(St(0), 1.0)
     ; if A_Number equals to 1.0
       print chr$("X^2 ")
    .ElseIf (isgreater(St(0), 1.0) || islessthan (St(0), -1.0))
     ; if A_Number greater than 1.0 Or A_Number less than - 1.0
       print real10$ (A_Number)
       print chr$("X^2 ")
    .EndIf

    Fld Real10 Ptr [Ebx]

    .If isless(St(0), -1.0)
    ; if B_Number less than -1.0
       print real10$ (B_Number)
       print chr$("X ")
    .ElseIf isequal(St(0), -1.0)
    ; if B_Number equals to -1.0
       print chr$("- X ")
    .ElseIf isequal(St(0), 1.0)
      ; if B_Number equals to 1.0
       print chr$("+ X ")
    .ElseIf isgreater(St(0), 1.0)
    ; if B_Number greater than 1.0
       print chr$("+ ")
       print real10$ (B_Number)
       print chr$("X ")
    .EndIf

    Fld Real10 Ptr [Ecx]

    .If isless(St(0), -1.0)
    ; if C_Number less than -1.0
       print real10$ (C_Number)
    .ElseIf isequal(St(0), -1.0)
    ; if C_Number equals to -1.0
       print chr$("- ")
       print chr$("1")
    .ElseIf isgreater(St(0), 0.0)
    ; if C_Number greater than 0.0
       print chr$("+ ")
       print real10$ (C_Number)
    .EndIf

   Ret
printFormat EndP

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;<<   calculateQuadraticRoots procedure will calculate two real roots    <<
;<<   of a quadratic equation by receiving three coefficients from       <<
;<<   user as input                                                      <<
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

calculateQuadraticRoots Proc A_Number:Ptr Real10, B_Number:Ptr Real10, C_Number:Ptr Real10
   Local squareRootNumber:Real10
   Local negativeB:Real10
   Local resultOfSquareRoot:Real10
   Local numerator1:Real10
   Local denominator:Real10
   Local signedRoot1:Real10
   Local signedRoot2:Real10
  ; squareRootNumber is the square root part of the quadratic formula
  ; negativeB is the negation of b of the quadratic formula
  ; resultOfSquareRoot is the result after getting square root of number
  ;  of the quadratic formula
  ; signedRoot1 and signedRoot2 are the string arrays which are the two X solutions
  ;  to the quadratic formula
  ; numerator1 is the numerator part of the quadratic formula
  ;  that has two solutions
  ; denominator is the denominator of the quadratic formula

  ; Eax, Ebx, Ecx, Edx are registers
  ; St(i) are Fpu registers

  ; Quadratic Formula:  x = (-b +/- sqrt(b^2 - 4*a*c)) / (2*a)

   Mov Eax, A_Number
   Mov Ebx, B_Number
   Mov Ecx, C_Number

   Finit

   Fld Real10 Ptr [Eax] ; st(0) = A_Number
   Fld Real10 Ptr [Ecx] ; st(0) = C_Number , st(1) = A_Number
   Fmulp St(1), St    ; st(1) = st(1) * st(0)
                      ;        = A_Number * C_Number
   Fld (NumberNegative4) ; st(0) = -4.0 , st(1) = A_Number * C_Number
   Fmulp St(1), St    ; st(1) = st(1) * st(0)
                      ;        = A_Number * C_Number * -4.0
   Fld Real10 Ptr [Ebx] ; st(0) = B_Number , st(1) = A_Number * C_Number * -4.0
   Fmul St, St        ; st(0) = st(0) * st(0)
                      ;       = B_Number * B_Number
   Faddp St(1), St ; st(1) = st(1) + st(0)
                   ;       = A_Number * C_Number * -4.0 + B_Number * B_Number
   Fstp squareRootNumber ; squareRootNumber = St(1) + St(0)

   Fld squareRootNumber  ; st(0) = squareRootNumber

   .If isgreater(squareRootNumber, -1.0)
      ; if squareRootNumber greater than -1.0
      Fsqrt                   ; Sqrt st(0)
      Fstp resultOfSquareRoot ; resultOfSquareRoot = sqrt st(0)
      Fld Real10 Ptr [Ebx]    ; st(0) = B_Number
      Fchs                    ; st(0) = -B_Number
      Fstp negativeB          ; negativeB = st(0)
      Fld negativeB          ; st(0) = negativeB
      Fld resultOfSquareRoot ; st(0) = resultOfSquareRoot , st(1) = negativeB
      Faddp St(1), St        ; st(1) = st(1) + st(0)
                             ;       = negativeB + resultOfSquareRoot
      Fstp numerator1        ; numerator1  = st(0)
      Fld Real10 Ptr [Eax]   ; st(0) = A_Number
      Fld (Number2)          ; st(0) = 2.0 , st(1) = A_Number
      Fmulp St(1), St        ; st(1) = st(1) * st(0)
                             ;       = A_Number * 2.0
      Fstp denominator       ; denominator = st(0)
      Fld (numerator1)       ; st(0) = numerator1
      Fld (denominator)      ; st(0) = denominator , st(1) numerator1
      Fdivp St(1), St        ; st(1) = st(1) / st(0)
                             ;       = numerator1 / denominator
      Fstp signedRoot1       ; signedRoot1 = st(1) = numerator1 / denominator

      Ffree St(0)
      Fld negativeB           ; st(0) = negativeB
      Fld resultOfSquareRoot  ; st(0) = resultOfSquareRoot , st(1) = negativeB
      Fchs                    ; st(0) = -resultOfSquareRoot
      Faddp St(1), St         ; st(1) = st(1) + st(0)
                              ;       = negativeB + -resultOfSquareRoot
      Fld denominator         ; st(0) = denominator , st(1) = negativeB + -resultOfSquareRoot
      Fdivp St(1), St         ; st(1) = st(1) / st(0)
                              ;       = (negativeB + -resultOfSquareRoot) / denominator
      Fstp signedRoot2        ; signedRoot2 = st(1)

      print chr$(13, 10)  ; a carriage return line feed will be outputted to the
                          ; screen
      print chr$(" Solutions for quadratic equation : ")

      ; The following statement call output format procedure of the quadratic
      ; equation

      Invoke printFormat, Addr A_Number, Addr B_Number, Addr C_Number

      print chr$(13, 10, 13, 10) ; two carriage return line feeds will be
                                 ; outputted to the screen
      print chr$(" X = ")
      print real10$ (signedRoot1)   ; print signedRoot1 string array
      print chr$(13, 10)
      print chr$("  1 ", 13, 10)
      print chr$(" X = ")
      print real10$ (signedRoot2)  ; print signedRoot2 string array
      print chr$(13, 10)
      print chr$("  2 ", 13, 10)
      print chr$(13, 10)

    .ElseIf islessequal(squareRootNumber, -1.0)
        ; if squareRootNumber less than or equal to -1.0
      print chr$(13, 10)
      print chr$("There are no real solutions for the quadratic equation : ")

      ; The following statement call output format procedure of the quadratic
      ; equation

      Invoke printFormat, Addr A_Number, Addr B_Number, Addr C_Number

      print chr$(" !", 13, 10, 13, 10) ; ! will be outputted along with two
                                       ; carriage return line feeds to the screen
   .EndIf
  Ret
calculateQuadraticRoots EndP

End start

etow

Hi

Here is my updated code below:


.686 ; create 32 bit code
;The MASM32 Runtime Library include file.
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Include \masm32\include\masm32rt.inc
Include \masm32\fpulib\fpu.inc
IncludeLib \masm32\fpulib\fpu.lib

.Data
Number2  Real10  2.0
NumberNegative4 Real10 - 4.0

.Code

start:
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Call Main
    inkey        ; pause the screen while waiting for user to press any key
                   ; to continue
    exit
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

InputR10 Proc pR10:Ptr Real10
    LOCAL r8:REAL8
    invoke crt_scanf, SADD("%lf"), ADDR r8
    mov eax, pR10
    finit
    fld r8
    fstp REAL10 PTR [eax]
    ret
InputR10 EndP

; ====================================
isgreater MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    ja    true
    jbe   false
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM
; ====================================
isgreaterequal MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    jae   true
    jb    false
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM 
; ====================================
isless MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    jae   false
    jb    true
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM 
; ====================================
islessequal MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    ja    false
    jbe   true
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM 
; ====================================
isnotequal MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    ja    true
    jb    true
    jz    false
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM 
; ====================================
isequal MACRO r1:REQ, r2:REQ
    LOCAL error, true, false, clear
    finit
    fld r2
    fld r1
    fcom
    fstsw ax
    fwait
    sahf
    jpe   error
    ja    false
    jb    false
    jz    true
  error:
    mov eax, -1
    jmp clear
  true:
    mov eax, 1
    jmp clear
  false:
    xor eax, eax
  clear:
    fstp st(0)
    fstp st(0)
    EXITM <eax>
ENDM 
; ====================================
islessgreater MACRO r1:REQ, r2:REQ
    EXITM <isnotequal(r1, r2)>
ENDM
; ====================================
isapproxequal MACRO r1:REQ, r2:REQ, tolerance:REQ
    LOCAL diff
    .DATA?
        diff REAL10 ?
    .CODE   
    finit
    .IF isgreater(r1, r2)
        fld   r2
        fld   r1
    .ELSE
        fld   r1
        fld   r2
    .ENDIF   
    fsub
    fstp  diff
    fwait
    EXITM <islessequal(diff, tolerance)>
ENDM
; ====================================

printQuadraticFormat Proto:Real10, Real10, Real10
calculateQuadraticRoots Proto:Real10, Real10, Real10


Main Proc
  Local WantContinue:DWord
  Local NumberA:Real10
  Local NumberB:Real10
  Local NumberC:Real10
  Local counter:DWord
  ; WantContinue is a sentinel value for while loop
  ; NumberA is the X^2 coefficient of the quadratic equation
  ; NumberB is the X coefficient of the quadratic equation
  ; NumberC is the constant of the quadratic equation
  ; NumberA, NumberB, and NumberC are user's integer values entered

    Mov WantContinue, 0  ; set WantContinue to 0 to start while loop

    .While ((WantContinue >= 0) && (WantContinue < -1))
       print chr$(13, 10) ; a carriage return line feed will be outputted to the
                          ; screen
       print chr$("Quadratic Equation : Ax^2 + Bx + C ", 13, 10, 13, 10)
       print chr$("Enter a real value for Number A : ")
       Invoke InputR10, Addr NumberA
       print chr$("Enter a real value for Number B : ")
       Invoke InputR10, Addr NumberB
       print chr$("Enter a real value for Number C : ")
       Invoke InputR10, Addr NumberC

     .If isnotequal(NumberA, 0.0) ; if NumberA != 0.0
       Invoke calculateQuadraticRoots, NumberA, NumberB, NumberC
       print chr$(13, 10)
     .ElseIf isequal(NumberA, 0.0) ; if NumberA == 0.0
    print chr$(13, 10)
    print chr$("Error, Division by zero!", 13, 10, 13, 10)
     .EndIf
       Mov WantContinue, sval(input("Enter -1 to quit program : "))
       print chr$(13, 10)

       Mov counter, 0
       .While counter <= 8
          Ffree St (counter)
          Inc counter
       .EndW

    .EndW
  Ret
Main EndP

printQuadraticFormat Proc A_Number:Real10, B_Number:Real10, C_Number:Real10
    Mov Eax, A_Number
    Mov Ebx, B_Number
    Mov Ecx, C_Number

    Fld Real10 Ptr [Eax]

    .If isequal(St(0), -1.0)
    ; if A_Number equals to -1.0
     print chr$("-X^2 ")
    .ElseIf isequal(St(0), 1.0)
     ; if A_Number equals to 1.0
       print chr$("X^2 ")
    .ElseIf (isgreater(St(0), 1.0) || isless(St(0), -1.0))
     ; if A_Number greater than 1.0 Or A_Number less than - 1.0
       print real10$ (St(0))
       print chr$("X^2 ")
    .EndIf

    Fld Real10 Ptr [Ebx]

    .If isless(St(0), -1.0)
    ; if B_Number less than -1.0
       print real10$ (St(0))
       print chr$("X ")
    .ElseIf isequal(St(0), -1.0)
    ; if B_Number equals to -1.0
       print chr$("- X ")
    .ElseIf isequal(St(0), 1.0)
    ; if B_Number equals to 1.0
       print chr$("+ X ")
    .ElseIf isgreater(St(0), 1.0)
    ; if B_Number greater than 1.0
       print chr$("+ ")
       print real10$ (St(0))
       print chr$("X ")
    .EndIf

    Fld Real10 Ptr [Ecx]

    .If isless(St(0), -1.0)
    ; if C_Number less than -1.0
       print real10$ (St(0))
    .ElseIf isequal(St(0), -1.0)
    ; if C_Number equals to -1.0
       print chr$("- ")
       print chr$("1")
    .ElseIf isgreater(St(0), 0.0)
    ; if C_Number greater than 0.0
       print chr$("+ ")
       print real10$ (St(0))
    .EndIf

Ret
printQuadraticFormat EndP

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;<<   calculateQuadraticRoots procedure will calculate two real roots    <<
;<<   of a quadratic equation by receiving three coefficients from       <<
;<<   user as input                                                      <<
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

calculateQuadraticRoots Proc A_Number:Real10, B_Number:Real10, C_Number:Real10
   Local squareRootNumber:Real10
   Local negativeB:Real10
   Local resultOfSquareRoot:Real10
   Local numerator1:Real10
   Local denominator:Real10
   Local signedRoot1:Real10
   Local signedRoot2:Real10
  ; squareRootNumber is the square root part of the quadratic formula
  ; negativeB is the negation of b of the quadratic formula
  ; resultOfSquareRoot is the result after getting square root of number
  ;  of the quadratic formula
  ; signedRoot1 and signedRoot2 are the string arrays which are the two X solutions
  ;  to the quadratic formula
  ; numerator1 is the numerator part of the quadratic formula
  ;  that has two solutions
  ; denominator is the denominator of the quadratic formula

  ; Eax, Ebx, Ecx, Edx are registers
  ; St(i) are Fpu registers

  ; Quadratic Formula:  x = (-b +/- sqrt(b^2 - 4*a*c)) / (2*a)

   Mov Eax, A_Number
   Mov Ebx, B_Number
   Mov Ecx, C_Number

   Finit

   Fld Real10 Ptr [Eax] ; st(0) = A_Number
   Fld Real10 Ptr [Ecx] ; st(0) = C_Number , st(1) = A_Number
   Fmulp St(1), St    ; st(1) = st(1) * st(0)
                      ;       = A_Number * C_Number
   Fld (NumberNegative4) ; st(0) = -4.0 , st(1) = A_Number * C_Number
   Fmulp St(1), St    ; st(1) = st(1) * st(0)
                      ;       = A_Number * C_Number * -4.0
   Fld Real10 Ptr [Ebx] ; st(0) = B_Number , st(1) = A_Number * C_Number * -4.0
   Fmul St, St        ; st(0) = st(0) * st(0)
                      ;       = B_Number * B_Number
   Faddp St(1), St ; st(1) = st(1) + st(0)
                   ;       = A_Number * C_Number * -4.0 + B_Number * B_Number
   Fstp squareRootNumber ; squareRootNumber = St(1) + St(0)

   Fld squareRootNumber  ; st(0) = squareRootNumber

   .If isgreater(squareRootNumber, -1.0)
      ; if squareRootNumber greater than -1.0
      Fsqrt                   ; Sqrt st(0)
      Fstp resultOfSquareRoot ; resultOfSquareRoot = sqrt st(0)
      Fld Real10 Ptr [Ebx]    ; st(0) = B_Number
      Fchs                    ; st(0) = -B_Number
      Fstp negativeB          ; negativeB = st(0)
      Fld negativeB          ; st(0) = negativeB
      Fld resultOfSquareRoot ; st(0) = resultOfSquareRoot , st(1) = negativeB
      Faddp St(1), St        ; st(1) = st(1) + st(0)
                             ;       = negativeB + resultOfSquareRoot
      Fstp numerator1        ; numerator1  = st(0)
      Fld Real10 Ptr [Eax]   ; st(0) = A_Number
      Fld (Number2)          ; st(0) = 2.0 , st(1) = A_Number
      Fmulp St(1), St        ; st(1) = st(1) * st(0)
                             ;       = A_Number * 2.0
      Fstp denominator       ; denominator = st(0)
      Fld (numerator1)       ; st(0) = numerator1
      Fld (denominator)      ; st(0) = denominator , st(1) numerator1
      Fdivp St(1), St        ; st(1) = st(1) / st(0)
                             ;       = numerator1 / denominator
      Fstp signedRoot1       ; signedRoot1 = st(1) = numerator1 / denominator

      Ffree St(0)
      Fld negativeB           ; st(0) = negativeB
      Fld resultOfSquareRoot  ; st(0) = resultOfSquareRoot , st(1) = negativeB
      Fchs                    ; st(0) = -resultOfSquareRoot
      Faddp St(1), St         ; st(1) = st(1) + st(0)
                              ;       = negativeB + -resultOfSquareRoot
      Fld denominator         ; st(0) = denominator , st(1) = negativeB + -resultOfSquareRoot
      Fdivp St(1), St         ; st(1) = st(1) / st(0)
                              ;       = (negativeB + -resultOfSquareRoot) / denominator
      Fstp signedRoot2        ; signedRoot2 = st(1)

      print chr$(13, 10)  ; a carriage return line feed will be outputted to the
                          ; screen
      print chr$(" Solutions for quadratic equation : ")

      ; The following statement call output format procedure of the quadratic
      ; equation
      Mov A_Number, Eax
      Mov B_Number, Ebx
      Mov C_Number, Ecx

      Invoke printQuadraticFormat, A_Number, B_Number, C_Number

      print chr$(13, 10, 13, 10) ; two carriage return line feeds will be
                                 ; outputted to the screen
      print chr$(" X = ")
      print real10$ (signedRoot1)   ; print signedRoot1 string array
      print chr$(13, 10)
      print chr$("  1 ", 13, 10)
      print chr$(" X = ")
      print real10$ (signedRoot2)  ; print signedRoot2 string array
      print chr$(13, 10)
      print chr$("  2 ", 13, 10)
      print chr$(13, 10)

    .ElseIf islessequal(squareRootNumber, -1.0)
      ; if squareRootNumber less than or equal to -1.0
      print chr$(13, 10)
      print chr$("There are no real solutions for the quadratic equation : ")

      ; The following statement call output format procedure of the quadratic
      ; equation
      Mov A_Number, Eax
      Mov B_Number, Ebx
      Mov C_Number, Ecx

      Invoke printQuadraticFormat, A_Number, B_Number, C_Number
      print chr$(" !", 13, 10, 13, 10) ; ! will be outputted along with two
                                       ; carriage return line feeds to the screen
   .EndIf
  Ret

calculateQuadraticRoots EndP

End start


-------------------------------------------------------------------------------------------
Here are my debugger error messages below:

Module1.asm(215) : error A2008: syntax error : real10
Module1.asm(216) : error A2008: syntax error : real10
Module1.asm(265) : error A2070: invalid instruction operands
Module1.asm(266) : error A2070: invalid instruction operands
Module1.asm(267) : error A2070: invalid instruction operands
Module1.asm(349) : error A2070: invalid instruction operands
Module1.asm(350) : error A2070: invalid instruction operands
Module1.asm(351) : error A2070: invalid instruction operands
Module1.asm(411) : error A2070: invalid instruction operands
Module1.asm(412) : error A2070: invalid instruction operands
Module1.asm(413) : error A2070: invalid instruction operands
Module1.asm(436) : error A2070: invalid instruction operands
Module1.asm(437) : error A2070: invalid instruction operands
Module1.asm(438) : error A2070: invalid instruction operands
Module1.asm(243) : error A2050: real or BCD number not allowed
isnotequal(3): Macro Called From
  Module1.asm(243): Include File
Module1.asm(246) : error A2050: real or BCD number not allowed
isequal(3): Macro Called From
  Module1.asm(246): Include File
Module1.asm(256) : error A2115: invalid coprocessor register
Module1.asm(270) : error A2050: real or BCD number not allowed
isequal(3): Macro Called From
  Module1.asm(270): Include File
Module1.asm(273) : error A2050: real or BCD number not allowed
isequal(3): Macro Called From
  Module1.asm(273): Include File
Module1.asm(276) : error A2050: real or BCD number not allowed
isgreater(3): Macro Called From
  Module1.asm(276): Include File
Module1.asm(276) : error A2050: real or BCD number not allowed
isless(3): Macro Called From
  Module1.asm(276): Include File
Module1.asm(284) : error A2050: real or BCD number not allowed
isless(3): Macro Called From
  Module1.asm(284): Include File
Module1.asm(288) : error A2050: real or BCD number not allowed
isequal(3): Macro Called From
  Module1.asm(288): Include File
Module1.asm(291) : error A2050: real or BCD number not allowed
isequal(3): Macro Called From
  Module1.asm(291): Include File
Module1.asm(294) : error A2050: real or BCD number not allowed
isgreater(3): Macro Called From
  Module1.asm(294): Include File
Module1.asm(303) : error A2050: real or BCD number not allowed
isless(3): Macro Called From
  Module1.asm(303): Include File
Module1.asm(306) : error A2050: real or BCD number not allowed
isequal(3): Macro Called From
  Module1.asm(306): Include File
Module1.asm(310) : error A2050: real or BCD number not allowed
isgreater(3): Macro Called From
  Module1.asm(310): Include File
Module1.asm(370) : error A2050: real or BCD number not allowed
isgreater(3): Macro Called From
  Module1.asm(370): Include File
Module1.asm(428) : error A2050: real or BCD number not allowed
islessequal(3): Macro Called From
  Module1.asm(428): Include File

Errors ocurred.

-----------------------------------------------------------------------------------------------------------------------
I don't understand what these error messages mean.  I just know where the error messages occur at.  Please help me.


Thanks

MichaelW


Module1.asm(215) : error A2008: syntax error : real10
Module1.asm(216) : error A2008: syntax error : real10

; The correct syntax is Proto :Real10, :Real10, :Real10

Module1.asm(265) : error A2070: invalid instruction operands
Module1.asm(266) : error A2070: invalid instruction operands
Module1.asm(267) : error A2070: invalid instruction operands
Module1.asm(349) : error A2070: invalid instruction operands
Module1.asm(350) : error A2070: invalid instruction operands
Module1.asm(351) : error A2070: invalid instruction operands
Module1.asm(411) : error A2070: invalid instruction operands
Module1.asm(412) : error A2070: invalid instruction operands
Module1.asm(413) : error A2070: invalid instruction operands
Module1.asm(436) : error A2070: invalid instruction operands
Module1.asm(437) : error A2070: invalid instruction operands
Module1.asm(438) : error A2070: invalid instruction operands

; An 80-bit real10 will not fit in a 32-bit register.

Module1.asm(243) : error A2050: real or BCD number not allowed
isnotequal(3): Macro Called From
  Module1.asm(243): Include File
Module1.asm(246) : error A2050: real or BCD number not allowed
isequal(3): Macro Called From
  Module1.asm(246): Include File
Module1.asm(270) : error A2050: real or BCD number not allowed
isequal(3): Macro Called From
  Module1.asm(270): Include File
Module1.asm(273) : error A2050: real or BCD number not allowed
isequal(3): Macro Called From
  Module1.asm(273): Include File
Module1.asm(276) : error A2050: real or BCD number not allowed
isgreater(3): Macro Called From
  Module1.asm(276): Include File
Module1.asm(276) : error A2050: real or BCD number not allowed
isless(3): Macro Called From
  Module1.asm(276): Include File
Module1.asm(284) : error A2050: real or BCD number not allowed
isless(3): Macro Called From
  Module1.asm(284): Include File
Module1.asm(288) : error A2050: real or BCD number not allowed
isequal(3): Macro Called From
  Module1.asm(288): Include File
Module1.asm(291) : error A2050: real or BCD number not allowed
isequal(3): Macro Called From
  Module1.asm(291): Include File
Module1.asm(294) : error A2050: real or BCD number not allowed
isgreater(3): Macro Called From
  Module1.asm(294): Include File
Module1.asm(303) : error A2050: real or BCD number not allowed
isless(3): Macro Called From
  Module1.asm(303): Include File
Module1.asm(306) : error A2050: real or BCD number not allowed
isequal(3): Macro Called From
  Module1.asm(306): Include File
Module1.asm(310) : error A2050: real or BCD number not allowed
isgreater(3): Macro Called From
  Module1.asm(310): Include File
Module1.asm(370) : error A2050: real or BCD number not allowed
isgreater(3): Macro Called From
  Module1.asm(370): Include File
Module1.asm(428) : error A2050: real or BCD number not allowed
islessequal(3): Macro Called From
  Module1.asm(428): Include File

; The fld instruction in the macros cannot load immediate values.
; One easy way to deal with this would be to create variables
; that contain the necessary values and pass these to the macros:

zero    REAL10 0.0
one     REAL10 1.0
negone  REAL10 -1.0
...
 
Module1.asm(256) : error A2115: invalid coprocessor register

; The fpu registers must be specified as constants (and there is no st(8)).
; One easy way to deal with this is:

ffree st(0)
ffree st(1)
ffree st(2)
ffree st(3)
ffree st(4)
ffree st(5)
ffree st(6)
ffree st(7)

eschew obfuscation

GregL

QuoteCan you use for example do this?
No.

QuoteCan you do this?
No.


Looks like MichaelW answered the rest of your questions.

Come on etow, you have been given everything you need to write this program. You need to go back and read the tutorials and documentation, you're still missing the basics.


RuiLoureiro

          To be simple, define A_Number, B_Number and C_Number and the solutions
          RootX0 and RootX1 in data segment.
          So printFormat and calculateQuadraticRoots dont have input parameters.
          They assume the values in that global variables.
          calculateQuadraticRoots put the roots in RootX0 and RootX1 for whatever
          you need.
          In this way you use instructions like  *** fld    A_Number ***
          *** fld    B_Number *** and *** fld    C_Number ***.
         
          Your InputR10 should get the user's integer values and converte it
          to Real10 format A_Number, B_Number and C_Number. Or convert it
          to integers NumberA, NumberB and NumberC and then to reals.

          Test A_Number against 0.0 before calling calculateQuadraticRoot
         
          If A_Number is 0, the equation is first degree or ... It is not
          an Error, Division by zero.

          What do you mean with *** A_Number:Ptr Real10 ***. It means the same
          as A_Number:DWORD if it is a pointer. All pointers here are 32 bits
         

.data
;
; All numbers are real numbers
; ----------------------------
A_Number        REAL10   1.0          ; Put here the Number a
B_Number        REAL10  -1.0          ; Put here the Number b
C_Number        REAL10 -12.0          ; Put here the Number c
;..........................
RootX0          REAL10 ?
RootX1          REAL10 ?
;......................................................................
.code


       
RuiLoureiro

etow

hi

I found the FPU Tutorial.  I read it and understand it.

Is there a function or procedure to read floating point numbers already in masm32 version 9 library?

Please reply.

Thanks

etow

Greg's application to me is very complex and confusing to me.