Hi
How do you output a real or floating point number from a Visual project in MASM32?
I know you use FpuFLtoA to display it but I am having trouble to make it display correctly in the static label in my Visual project in MASM32.
I need help please.
Thanks
Hi
I need a routine (or procedure) that converts a real or floating point number in the corresponding text string for output in a string buffer.
Thanks
I have, it's author algorithm supporting exponential output and varios presicion, but it's not free, countacts in profile.
Hi
Here is my visual program which I have problems with displaying floating point numbers.
The program is in the zip file below.
[attachment deleted by admin]
Egan,
I downloaded your source file but could not find an asm file in it.
Is this what you are looking for ?
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
comment * -----------------------------------------------------
Build this template with
"CONSOLE ASSEMBLE AND LINK"
----------------------------------------------------- *
.data
item1 REAL10 1000.0000 ; 80 bit FP numbers
.code
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
call main
inkey
exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
main proc
LOCAL fpo :DWORD
mov fpo, real10$(FP10(1234.5678)) ; literal using a macro
print fpo,13,10
mov fpo, real10$(item1) ; address of item in .DATA section
print fpo,13,10
ret
main endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start
This is the output.
1234.567800
1000.000000
Press any key to continue ...
LATER:
RE: Writing string to a static control.
1. Get the handle of the static control, even if you have to use GetDlgItem() and then use SendMessage() with WM_SETTEXT or alternatively use the API SetWindowText() and you can display the string that contains the result in the static control.
Here is a short example of how to convert string to FP and back again then display it in an edit control. The conversion method is a bit crude as I hacked one of Greg's macros but the general idea of how to display results of FP should be easy enough to follow.
If you are familiar with ray Filiatreault's fpu library his conversions in both directions should be useful.
[attachment deleted by admin]
Hi Hutch,
Here is my complete program with incorrect display of real numbers in my quadratic equation program. I have included my source code and executable program.
Please look at it and tell me what is wrong so I can correct it.
Thanks
Sorry Hutch I forgot to attach the zip file,
Here is my complete code with executable in the zip file below:
[attachment deleted by admin]
You are little mistaken with output function, so all is well working :
[attachment deleted by admin]
What do you mean mistaken by output function?
How come I get integer results instead of floating point numbers?
I changed function that you are used String on FpuFLtoA that to output floating point number.
That to get integer result, floating point converting to interger, by sequence of commands FLD - FISTP.
That to discard tail zeros in floating point number string, I myself using special string functions that round remember to given leight and discard the zeros if it is. They are quite difficult and about 500 lines on C, with such prototype : cap_t* strauxrnd (cap_t* str, const short precision, const cap_t pset) (cap_t it's character)
Hi Hutch,
I corrected a preservation of my registers.
Can you tell me why it is not reading the floating point numbers from the edit box?
I have included my code in zip file called QuadraticSolutions5.zip
[attachment deleted by admin]
Hi Hutch,
I modified my code and still my floating point numbers output are not correct.
Please help.
Thanks
[attachment deleted by admin]
Egan,
I downloaded the code and had a look at it but its the same problem, I don't use the environment it is built with and I cannot test it. I don't properly know what you are trying to do so I have little chance of making sense of your code.
What I want you to do is put the basic calculations into something simple like a masm32 console app with the required data inputs so I can see what you are trying to do. The idea is to track down what you are doing bit by bit, not as a block of code that is not doing what you want. Try a masm32 console template and put the three floating point numbers to test with in the data section something like,
fp1 REAL10 1234.5678
fp2 REAL10 9876.5432
fp3 REAL10 1928.3847
The idea is to get the calcxulation working properly first then work out how to display it
Hi Hutch,
Here is my Win32 console program to solve the quadratic equation in the link below.
This gives you the exact idea of what I want to do in my visual program of QuadraticSolutions.
[attachment deleted by admin]
Where is MyMacros.inc ?
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]
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
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.
How do I read the three FP numbers at those addresses and display them?
I have no clue how to do that?
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().