Displaying floating point numbers in MASM32 visual projects

Started by etow, March 13, 2008, 11:00:23 PM

Previous topic - Next topic

hutch--

Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

etow

Hi Hutch,

Here is the complete Win32 Console program for solving quadratic equation in the link below with code and executable program.

Thanks



[attachment deleted by admin]

etow

I have trouble with either input or output or both for Visual Win32 Executable programs
in MASM32 when using floating point or real numbers.

Below are some of my input and output procedures of my visual win32 executable program
with floating point or real numbers for my Quadratic Solutions program in MASM32

Code:

.Data?
szNumberA Byte 20 Dup (?)
szNumberB Byte 20 Dup (?)
szNumberC Byte 20 Dup (?)

.Data
NumberA Real10 ?   ; the coefficient of X^2 in the quadratic equation
NumberB Real10 ?   ; the coefficient of X in the quadratic equation
NumberC Real10 ?   ; the constant in the quadratic equation

    ;--------------------------------------------
    ; butchered version of Greg's macro
    ;--------------------------------------------
    a2r10x MACRO pStr:req
        LOCAL r8, r10
        .data
           align 16
           ;; r10 REAL10 0.0
           r8  REAL8  0.0
        IFNDEF r8fmt
        .data
            r8fmt BYTE "%lf",0
        ENDIF
        .code
        invoke crt_sscanf, pStr, ADDR r8fmt, ADDR r8
        finit
        fld r8
        ;; fstp r10
        ;; EXITM <OFFSET r10>
    ENDM
    ;--------------------------------------------


;---------------------------------------------------------------------
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;<<  ReadNumbersOfQuadraticEquation will read in string of floating point  <<
;<<  numbers of the quadratic equation.                                    <<
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

ReadNumbersOfQuadraticEquation Proc Private hWnd:HWND

  Local szNumber1[60]:Byte
  Local szNumber2[60]:Byte
  Local szNumber3[60]:Byte

   ;Get the handle to Results Static control in Eax
   Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_RESULTS

        Push Edi
   ;Save it in Edi
   Mov Edi, Eax

   ;Clear the Results control
   Invoke SetWindowText, Edi, NULL

   ;Clear szbuffer and number buffers
   Mov szBuffer[0], 0
   Mov szNumber1[0], 0
   Mov szNumber2[0], 0
   Mov szNumber3[0], 0

       Invoke GetWindowText, Edi, Addr szBuffer, 255
       Invoke SetWindowText, Edi, Addr szBuffer

       ;Get the handle to Solve button in Eax
       Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_GETA

       Push Edx
       ;Save it in Edx
       Mov Edx, Eax

       ;Get the text in the Edit control
       Invoke GetWindowText, Edx, Addr szNumber1, 24
       ;Convert it to a number returned in Eax
       ;    Invoke Value, Addr szNumber1

       a2r10x Addr szNumber1

       Fstp NumberA

       ;Invoke FpuAtoFL, Addr szNumber1, Addr NumberA, DEST_MEM

       ;Get the handle to Solve button in Eax
       Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_GETB

       Push Esi
       ;Save it in Esi
       Mov Esi, Eax

       ;Get the text in the Edit control
       Invoke GetWindowText, Esi, Addr szNumber2, 24
       ;Convert it to a number returned in Eax
       ;    Invoke Value, Addr szNumber2

       a2r10x Addr szNumber2

       Fstp NumberB

       ;Invoke FpuAtoFL, Addr szNumber2, Addr NumberB, DEST_MEM

       ;Get the handle to Solve button in Eax
       Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_GETC

       Push Ebx
       ;Save it in Ebx
       Mov Ebx, Eax

       ;Get the text in the Edit control
       Invoke GetWindowText, Ebx, Addr szNumber3, 24
       ;Convert it to a number returned in Eax
       ;    Invoke Value, Addr szNumber3

       a2r10x Addr szNumber3

       Fstp NumberC

       ;Invoke FpuAtoFL, Addr szNumber3, Addr NumberC, DEST_MEM

       Pop Ebx
       Pop Esi
       Pop Edx
       Pop Edi

       ret       
ReadNumbersOfQuadraticEquation EndP


;----------------------------------------------------------------------
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;<<  printQuadraticFormat procedure will output the quadratic equation with  <<
;<<  the three numbers that the user entered.                                <<
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

printQuadraticFormat Proc Private hWnd:HWND

      ;Get the address of last character of szBuffer
      Invoke lstrlen, Addr szBuffer
      Add Eax, Offset szBuffer

      Invoke lstrcat, Addr szBuffer, TextAddr(" ")
     ;Adds a carriage return/line feed to szBuffer
      Invoke lstrcat, Addr szBuffer, Addr szCRLF

      Invoke lstrcat, Addr szBuffer, TextAddr(" The quadratic equation : ")

      ;Adds a carriage return/line feed to szBuffer
      Invoke lstrcat, Addr szBuffer, Addr szCRLF
      Invoke lstrcat, Addr szBuffer, TextAddr(" -------------------------------------")

      ;Adds a carriage return/line feed to szBuffer
      Invoke lstrcat, Addr szBuffer, Addr szCRLF
      Invoke lstrcat, Addr szBuffer, TextAddr(" ")

;      Invoke FpuFLtoA, Addr NumberA, 4, Addr szNumber1, SRC1_REAL
       ; display the X^2 coefficient of quadratic equation to 4 decimal places

      ;Get the address of last character of szBuffer
      Invoke lstrlen, Addr szBuffer
      Add Eax, Offset szBuffer
     ;Convert the NumberA value to a decimal
     ;string and adds it to szBuffer
     Invoke FloatToStr, Addr NumberA, Addr szNumberA

      ;Invoke String, Addr NumberA, Eax, ecDecimal
      Invoke lstrcat, Addr szBuffer, Addr szNumberA
      Invoke lstrcat, Addr szBuffer, TextAddr(" X^2 ")
                     
      Invoke FpuComp, Addr NumberB, Offset Number0, SRC1_REAL Or SRC2_REAL
      Shr Al, 1           ; mov bit 0 to Carry Flag , NumberB = 0
      Jc NumberBIs0       ; jump on Carry Flag

      Invoke lstrcat, Addr szBuffer, TextAddr("  +  ")
;      Invoke FpuFLtoA, Addr NumberB, 4, Addr szNumber2, SRC1_REAL
       ; display the X coefficient of quadratic equation to 4 decimal places

      ;Get the address of last character of szBuffer
      Invoke lstrlen, Addr szBuffer
      Add Eax, Offset szBuffer
     ;Convert the NumberB value to a decimal
     ;string and adds it to szBuffer
      Invoke String, Addr NumberB, Eax, ecDecimal
                                               
      Invoke lstrcat, Addr szBuffer, TextAddr(" X ")
      Jmp NextC   ; just jump
                     ;
NumberBIs0:   ; if NumberB is zero
NextC:
      Invoke FpuComp, Addr NumberC, Offset Number0, SRC1_REAL Or SRC2_REAL
      Shr Al, 1              ; mov bit 0 to Carry Flag , NumberC = 0
      Jc NumberCIs0          ; jump on Carry Flag
      Invoke lstrcat, Addr szBuffer, TextAddr("  +  ")

;      Invoke FpuFLtoA, Addr NumberC, 4, Addr szNumber3, SRC1_REAL
       ; display the constant of quadratic equation to 4 decimal places

      ;Get the address of last character of szBuffer
      Invoke lstrlen, Addr szBuffer
      Add Eax, Offset szBuffer
     
      ;Convert the NumberC value to a decimal
      ;string and adds it to szBuffer
      Invoke String, Addr NumberC, Eax, ecDecimal

      Jmp EndPrint  ; just jump

NumberCIs0:     ; if NUmberC is zero
EndPrint:
      Invoke lstrcat, Addr szBuffer, TextAddr("   =  0 ")
      Invoke lstrcat, Addr szBuffer, Addr szCRLF


      ;Get the handle to Results Static control in Eax
      Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_RESULTS
      Invoke SetWindowText, Eax, Addr szBuffer
      Ret
printQuadraticFormat EndP
----------------------------------------------------------------------

I am sure that my above procedures are incorrect when inputting floating point numbers and outputting
floating point numbers correctly.

-------------------------------------------------
For example the Quadratic Equation:  x^2 + x + 1 , NumberA = 1, NumberB = 1, NumberC = 1
The display from printQuadraticFormat should be the following below:

  The quadratic equation
-------------------------
  1.0000 X^2 + 1.0000 X + 1.0000 = 0

instead of the following:

  The quadratic equation
---------------------------
   4256068 X^2 + 4256078 X + 4256088 = 0


hutch--

Egan,

if this is your required output but you get the second as per your posting,


The quadratic equation
-------------------------
  1.0000 X^2 + 1.0000 X + 1.0000 = 0

instead of the following:

  The quadratic equation
---------------------------
   4256068 X^2 + 4256078 X + 4256088 = 0


The integers you are getting look very much like addresses of WHERE the results are instead of the results. You will notice that they are 10 bytes apart which suggests that tere are 3 REAL10 numbers stored in sequence at those three addresses.

Read the three FP numbers at those addresses and display them instead.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

etow

How do I read the three FP numbers at those addresses and display them?

I have no clue how to do that?


hutch--

Have a look at the functions you have available to convert a REAL10 fp number to a string so it can be displayed. What you basically need is a function that requires the ADDRESS of a REAL10 number as one of its arguments. I think from memory that Ray Filiatreault's FP library can do that for you, then you just display the results in a static control with SetWindowText().
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php