Hi
How do you convert a string input from a edit text box for a visual windows Easy Code project into a real or floating point number and using the FpuAtoFL function?
Thanks
Egan,
In the PrimeFactor program I made for you there is the answer to your question. Get the text for the Edit control (by calling the GetWindowText API call or the GetText Easy Code method) and then convert it to a numerical value (by calling the Value Easy Code method).
Ramon
Thanks
Ramon
Hi Ramon,
I have trouble with my parts of my code:
Here is my code:
;Get the handle to Solve button in Eax
Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_GETA
;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
Mov NumberA, Eax
The error is "error A2070: invalid instruction operands"
What is the correct operands?
Hi Ramon,
I am using FPU functions to calculate real numbers.
Hi Ramon,
I am using Real10 variables to store my real or floating point numbers
I have trouble with the following code below:
It gives me Access Violation Read at "Invoke String, szNumber1, Eax, ecDecimal"
Please help.
Thanks
printQuadraticFormat Proc Private hWnd:HWND
Local szNumber1[100]:CHAR
Local szNumber2[100]:CHAR
Local szNumber3[100]:CHAR
Local szRootX0[100]:CHAR
Local szRootX1[100]:CHAR
;Get the handle to Results Static control in Eax
Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_RESULTS
;Save it in Edi
Mov Edi, Eax
;Clear the Results control
Invoke SetWindowText, Edi, NULL
;Clear szbuffer
Mov szBuffer[0], 0
Invoke GetWindowText, Edi, Addr szBuffer, 255
Invoke SetWindowText, Edi, Addr szBuffer
;Get the address of last character of szBuffer
Invoke lstrlen, Addr szBuffer
Add Eax, Offset szBuffer
;Adds a carriage return/line feed to szBuffer
Invoke lstrcat, Addr szBuffer, Addr szCRLF
; print chr$(13, 10)
Invoke lstrcat, Addr szBuffer, TextAddr("The quadratic equation : ")
; print chr$(" Solutions for quadratic equation : ", 13, 10)
Invoke lstrcat, Addr szBuffer, TextAddr("---------------------------")
; print chr$("--------------------------------------", 13, 10)
Invoke lstrcat, Addr szBuffer, TextAddr(" ")
; print chr$(" ")
Invoke FpuFLtoA, Addr NumberA, 4, Addr szNumber1, SRC1_REAL
; print ext$ (NumberA, 0, 4) ; 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 Esi value to a decimal
;string and adds it to szBuffer
Invoke String, szNumber1, Eax, ecDecimal
Invoke lstrcat, Addr szBuffer, TextAddr(" X^2 ")
; print chr$(" 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(" + ")
; print chr$(" + ")
Invoke FpuFLtoA, Addr NumberB, 4, Addr szNumber2, SRC1_REAL
; print ext$ (NumberB, 0, 4) ; 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 Esi value to a decimal
;string and adds it to szBuffer
Invoke String, szNumber2, Eax, ecDecimal
Invoke lstrcat, Addr szBuffer, TextAddr(" X ")
; print chr$(" X ")
Jmp NextC ; just jump
;
NumberBIs0:
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(" + ")
; print chr$(" + ")
Invoke FpuFLtoA, Addr NumberC, 4, Addr szNumber3, SRC1_REAL
; print ext$ (NumberC, 0, 4) ; display the constant of
; quadratic equation
;Get the address of last character of szBuffer
Invoke lstrlen, Addr szBuffer
Add Eax, Offset szBuffer
;Convert the Esi value to a decimal
;string and adds it to szBuffer
Invoke String, szNumber3, Eax, ecDecimal
; to 4 decimal places
Jmp EndPrint ; just jump
NumberCIs0:
EndPrint:
Invoke lstrcat, Addr szBuffer, TextAddr(" = 0 ")
Invoke lstrcat, Addr szBuffer, Addr szCRLF
Invoke lstrcat, Addr szBuffer, Addr szCRLF
; print chr$ (" = 0 ", 13, 10)
; print chr$(13, 10, 13, 10) ; two carriage return line feeds will be
; outputted to the screen
Invoke lstrcat, Addr szBuffer, TextAddr(" X = ")
; print chr$(" X = ")
Invoke FpuFLtoA, Addr _RootX0, 15, Addr szRootX0, SRC1_REAL
; print real10$ (_RootX0) ; print the real number of one real root
; in the quadratic formula
;Get the address of last character of szBuffer
Invoke lstrlen, Addr szBuffer
Add Eax, Offset szBuffer
;Convert the Esi value to a decimal
;string and adds it to szBuffer
Invoke String, szRootX0, Eax, ecDecimal
Invoke lstrcat, Addr szBuffer, Addr szCRLF
; print chr$(13, 10)
Invoke lstrcat, Addr szBuffer, TextAddr(" 1 ")
; print chr$(" 1 ", 13, 10, 13, 10)
Invoke lstrcat, Addr szBuffer, TextAddr(" X = ")
; print chr$(" X = ")
Invoke FpuFLtoA, Addr _RootX1, 15, Addr szRootX1, SRC1_REAL
; print real10$ (_RootX1) ; print the real number of another real root
; in the quadratic formula
;Get the address of last character of szBuffer
Invoke lstrlen, Addr szBuffer
Add Eax, Offset szBuffer
;Convert the Esi value to a decimal
;string and adds it to szBuffer
Invoke String, szRootX1, Eax, ecDecimal
Invoke lstrcat, Addr szBuffer, Addr szCRLF
; print chr$(13, 10)
Invoke lstrcat, Addr szBuffer, TextAddr(" 2 ")
; print chr$(" 2 ", 13, 10)
; print chr$(13, 10)
Ret
printQuadraticFormat EndP
Egan,
Invoke String, szNumber1, Eax, ecDecimal
The problem is in the szNumber1 variable. You have to pass the effective addres, using the Addr directive, like this:
Invoke String, Addr szNumber1, Eax, ecDecimal.
Hi
Can you check the following code?
I get Access Violation Read
Exception Address: 40BF55H
--------------------------------------------------------------------------------------------------------------
SolveQuadraticEquation Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM
Local szNumber1[100]:CHAR
Local szNumber2[100]:CHAR
Local szNumber3[100]:CHAR
;Get the handle to Solve button in Eax
Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_GETA
;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
Invoke FpuAtoFL, Eax, Addr NumberA, DEST_FPU
;Get the handle to Solve button in Eax
Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_GETB
;Save it in Edx
Mov Ebx, Eax
;Get the text in the Edit control
Invoke GetWindowText, Ebx, Addr szNumber2, 24
;Convert it to a number returned in Eax
Invoke Value, Addr szNumber2
Invoke FpuAtoFL, Eax, Addr NumberB, DEST_FPU
;Get the handle to Solve button in Eax
Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_GETC
;Save it in Edx
Mov Ecx, Eax
;Get the text in the Edit control
Invoke GetWindowText, Ecx, Addr szNumber3, 24
;Convert it to a number returned in Eax
Invoke Value, Addr szNumber3
Invoke FpuAtoFL, Eax, Addr NumberC, DEST_FPU
Invoke FpuComp, Addr NumberA, Offset Number0, SRC1_REAL Or SRC2_REAL
Or Eax, Eax ; activate zero flag
Jz ErrorInComp ; jump if zero
; ------------------------------------
; If bit 0 of EAX=1 => NumberA=Number0
; ------------------------------------
Shr Al, 1 ; mov bit 0 to Carry Flag , NumberA = 0
Jc Linear ; jump on Carry Flag
;
Invoke calculateXRoots, Addr NumberA, Addr NumberB, Addr NumberC
Invoke printQuadraticFormat, HWnd
print chr$(13, 10)
Jmp Finish
ErrorInComp:
; print chr$(13, 10)
; print chr$(" Error comparing Number A against zero! ", 13, 10, 13, 10)
Invoke MessageBox, hWnd, TextAddr("Error comparing Number A against zero!"), TextAddr("Quadratic Solutions"), MB_ICONEXCLAMATION Or MB_OK
Jmp Finish
Linear:
Invoke FpuComp, Addr NumberB, Offset Number0, SRC1_REAL Or SRC2_REAL
Or Eax, Eax ; activates zero flag
Jz ZeroErrors ; jump if zero
; ------------------------------------
; If bit 0 of EAX=1 => NumberB=Number0
; ------------------------------------
Shr Al, 1 ; mov bit 0 to Carry Flag , NumberB = 0
Jc ZeroErrors
Invoke calculateLinearRoot, Addr NumberB, Addr NumberC
Invoke printLinearFormat, HWnd
Jmp Finish
ZeroErrors:
; print chr$(13, 10)
; print chr$(" Error, Numbers for A and B are zero! ", 13, 10, 13, 10)
Invoke MessageBox, hWnd, TextAddr("Error, Numbers for A and B are zero!"), TextAddr("Quadratic Solutions"), MB_ICONEXCLAMATION Or MB_OK
Finish:
Ret
SolveQuadraticEquation EndP
hi
I want to make sure if my procedures are correct below in my following code below:
;The MASM32 Runtime Library include file.
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Include \masm32\include\masm32rt.inc
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Include \masm32\fpulib\fpu.inc
IncludeLib \masm32\fpulib\fpu.lib
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Include MyMacros.inc
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
.Const
IDC_EDIT Equ 3000
IDC_BUTTON Equ 3001
IDC_EXIT Equ 3002
IDM_GETTEXT Equ 32000
IDM_CLEAR Equ 32001
IDM_EXIT Equ 32002
.Data?
szBuffer Byte 512 Dup(?)
.Data
szCRLF Byte 13, 10, 0
Number0 Real10 0.0 ; used to determine if there are real roots in the
; quadratic formula
Number2 Real10 2.0 ; number to use to get the denominator in the quadratic
; formula
Number4 Real10 4.0 ; number to get part of the square root number
Minus1 Real10 - 1.0 ; used for negation
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
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
;------------------------------------
_RootX0 Real10 ? ; first real root solution to the quadratic formula
_RootX1 Real10 ? ; second real root solution to the quadratic formula
_LinearRootX Real10 ? ; real linear root solution to the linear equation
; ##############################################################################################
.Code
QuadraticSolutionsProcedure Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM
.If uMsg == WM_CREATE
Return TRUE
.ElseIf uMsg == WM_COMMAND
LoWord wParam ;Get the low word of wParam
.If Ax == IDC_QUADRATICSOLUTIONS_SOLVEBUTTON
HiWord wParam ;Get the high word of wParam
.If Ax == BN_CLICKED
;Solve button has been clicked
Invoke SolveQuadraticEquation, hWnd, uMsg, wParam, lParam
Return TRUE
.EndIf
.ElseIf Ax == IDC_QUADRATICSOLUTIONS_CLEARBUTTON
HiWord wParam ;Get the high word of wParam
.If Ax == BN_CLICKED
;Clear button has been clicked
;Get the handle for the Edit control
Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_GETA
;Set Edit control to no text
Invoke SetWindowText, Eax, NULL
;Get the handle for the Edit control
Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_GETB
;Set Edit control to no text
Invoke SetWindowText, Eax, NULL
;Get the handle for the Edit control
Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_GETC
;Set Edit control to no text
Invoke SetWindowText, Eax, NULL
;Get the handle for the Results static control
Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_RESULTS
;Set the Results static control to no text
Invoke SetWindowText, Eax, NULL
Return TRUE
.EndIf
.ElseIf Ax == IDC_QUADRATICSOLUTIONS_EXITBUTTON
HiWord wParam ;Get the high word of wParam
.If Ax == BN_CLICKED
;Exit button has been clicked
Invoke SendMessage, hWnd, WM_CLOSE, 0, 0
Return TRUE
.EndIf
.EndIf
.ElseIf uMsg == WM_CLOSE
Invoke IsModal, hWnd
.If Eax
Invoke EndModal, hWnd, IDCANCEL
Return TRUE
.EndIf
.EndIf
Return FALSE
QuadraticSolutionsProcedure EndP
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;<< SolveQuadraticEquation procedure will solve a quadratic equation by getting <<
;<< two solutions using the quadratic forumla. <<
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
SolveQuadraticEquation Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM
Local szNumber1[100]:CHAR
Local szNumber2[100]:CHAR
Local szNumber3[100]:CHAR
;Get the handle to Solve button in Eax
Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_GETA
;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
Invoke FpuAtoFL, Eax, Addr NumberA, DEST_FPU
;Get the handle to Solve button in Eax
Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_GETB
;Save it in Edx
Mov Ebx, Eax
;Get the text in the Edit control
Invoke GetWindowText, Ebx, Addr szNumber2, 24
;Convert it to a number returned in Eax
Invoke Value, Addr szNumber2
Invoke FpuAtoFL, Eax, Addr NumberB, DEST_FPU
;Get the handle to Solve button in Eax
Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_GETC
;Save it in Edx
Mov Ecx, Eax
;Get the text in the Edit control
Invoke GetWindowText, Ecx, Addr szNumber3, 24
;Convert it to a number returned in Eax
Invoke Value, Addr szNumber3
Invoke FpuAtoFL, Eax, Addr NumberC, DEST_FPU
Invoke FpuComp, Addr NumberA, Offset Number0, SRC1_REAL Or SRC2_REAL
Or Eax, Eax ; activate zero flag
Jz ErrorInComp ; jump if zero
; ------------------------------------
; If bit 0 of EAX=1 => NumberA=Number0
; ------------------------------------
Shr Al, 1 ; mov bit 0 to Carry Flag , NumberA = 0
Jc Linear ; jump on Carry Flag
;
Invoke calculateXRoots, Addr NumberA, Addr NumberB, Addr NumberC
Jc _ExitProc ; jump on Carry Flag
Cmp Eax, 2 ; compare Eax with 2 , complex roots results
Je @F ; jump if equal to 2 forward to @@
Invoke printTheXRoots, hWnd
; print chr$(13, 10)
Jmp Finish
@@:
;print chr$(13, 10)
Invoke lstrcat, Addr szBuffer, TextAddr("There are no real solutions for the quadratic equation : ")
; print chr$(" Solutions for quadratic equation : ", 13, 10)
Invoke lstrcat, Addr szBuffer, TextAddr("---------------------------------------------------------")
;print chr$(" There are no real solutions for the quadratic equation: ", 13, 10)
;print chr$("----------------------------------------------------------", 13, 10)
Invoke printQuadraticFormat, hWnd
Invoke lstrcat, Addr szBuffer, TextAddr("This equation has complex roots!")
; print chr$(13, 10, " This equation has complex roots! ")
; print chr$(13, 10, 13, 10) ; two carriage return line feeds to the screen
Jmp Finish ; exit here
ErrorInComp:
; print chr$(13, 10)
; print chr$(" Error comparing Number A against zero! ", 13, 10, 13, 10)
Invoke MessageBox, hWnd, TextAddr("Error comparing Number A against zero!"), TextAddr("Quadratic Solutions"), MB_ICONEXCLAMATION Or MB_OK
Jmp Finish
Linear:
Invoke FpuComp, Addr NumberB, Offset Number0, SRC1_REAL Or SRC2_REAL
Or Eax, Eax ; activates zero flag
Jz ZeroErrors ; jump if zero
; ------------------------------------
; If bit 0 of EAX=1 => NumberB=Number0
; ------------------------------------
Shr Al, 1 ; mov bit 0 to Carry Flag , NumberB = 0
Jc ZeroErrors
Invoke calculateLinearRoot, Addr NumberB, Addr NumberC
Invoke printLinearFormat, hWnd
Jmp Finish
ZeroErrors:
; print chr$(13, 10)
; print chr$(" Error, Numbers for A and B are zero! ", 13, 10, 13, 10)
Invoke MessageBox, hWnd, TextAddr("Error, Numbers for A and B are zero!"), TextAddr("Quadratic Solutions"), MB_ICONEXCLAMATION Or MB_OK
Jmp Finish
_ExitProc:
; print chr$(13, 10)
Invoke MessageBox, hWnd, TextAddr("An Error occurred while calculating the roots!"), TextAddr("Quadratic Solutions"), MB_ICONEXCLAMATION Or MB_OK
;print chr$(" An Error occured while calculating the roots", 13, 10)
Finish:
Ret
SolveQuadraticEquation EndP
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;<< printQuadraticFormat procedure will output the quadratic equation with <<
;<< the three numbers that the user entered. <<
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
printQuadraticFormat Proc Private hWnd:HWND
Local szNumber1[100]:CHAR
Local szNumber2[100]:CHAR
Local szNumber3[100]:CHAR
Local szRootX0[100]:CHAR
Local szRootX1[100]:CHAR
;Get the handle to Results Static control in Eax
Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_RESULTS
;Save it in Edi
Mov Edi, Eax
;Clear the Results control
Invoke SetWindowText, Edi, NULL
;Clear szbuffer
Mov szBuffer[0], 0
Invoke GetWindowText, Edi, Addr szBuffer, 255
Invoke SetWindowText, Edi, Addr szBuffer
;Get the address of last character of szBuffer
Invoke lstrlen, Addr szBuffer
Add Eax, Offset szBuffer
;Adds a carriage return/line feed to szBuffer
Invoke lstrcat, Addr szBuffer, Addr szCRLF
; print chr$(13, 10)
Invoke lstrcat, Addr szBuffer, TextAddr("The quadratic equation : ")
; print chr$(" Solutions for quadratic equation : ", 13, 10)
Invoke lstrcat, Addr szBuffer, TextAddr("---------------------------")
; print chr$("--------------------------------------", 13, 10)
Invoke lstrcat, Addr szBuffer, TextAddr(" ")
; print chr$(" ")
Invoke FpuFLtoA, Addr NumberA, 4, Addr szNumber1, SRC1_REAL
; print ext$ (NumberA, 0, 4) ; 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 Esi value to a decimal
;string and adds it to szBuffer
Invoke String, Addr szNumber1, Eax, ecDecimal
Invoke lstrcat, Addr szBuffer, TextAddr(" X^2 ")
; print chr$(" 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(" + ")
; print chr$(" + ")
Invoke FpuFLtoA, Addr NumberB, 4, Addr szNumber2, SRC1_REAL
; print ext$ (NumberB, 0, 4) ; 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 Esi value to a decimal
;string and adds it to szBuffer
Invoke String, Addr szNumber2, Eax, ecDecimal
Invoke lstrcat, Addr szBuffer, TextAddr(" X ")
; print chr$(" X ")
Jmp NextC ; just jump
;
NumberBIs0:
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(" + ")
; print chr$(" + ")
Invoke FpuFLtoA, Addr NumberC, 4, Addr szNumber3, SRC1_REAL
; print ext$ (NumberC, 0, 4) ; display the constant of
; quadratic equation
;Get the address of last character of szBuffer
Invoke lstrlen, Addr szBuffer
Add Eax, Offset szBuffer
;Convert the Esi value to a decimal
;string and adds it to szBuffer
Invoke String, Addr szNumber3, Eax, ecDecimal
; to 4 decimal places
Jmp EndPrint ; just jump
NumberCIs0:
EndPrint:
Invoke lstrcat, Addr szBuffer, TextAddr(" = 0 ")
Invoke lstrcat, Addr szBuffer, Addr szCRLF
Invoke lstrcat, Addr szBuffer, Addr szCRLF
; print chr$ (" = 0 ", 13, 10)
; print chr$(13, 10, 13, 10) ; two carriage return line feeds will be
; outputted to the screen
printQuadraticFormat EndP
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;<< printTheXRoots outputs the real roots of the quadratic equation. <<
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
printTheXRoots Proc Private, hWnd:HWND
Local szRootX0[100]:CHAR
Local szRootX1[100]:CHAR
; print chr$(13, 10)
Invoke lstrcat, Addr szBuffer, TextAddr(" Solutions for quadratic equation :")
Invoke lstrcat, Addr szBuffer, TextAddr(" ----------------------------------")
; print chr$(" Solutions for quadratic equation : ", 13, 10)
; print chr$("--------------------------------------", 13, 10)
Invoke printQuadraticFormat, hWnd
Invoke lstrcat, Addr szBuffer, TextAddr(" X = ")
; print chr$(" X = ")
Invoke FpuFLtoA, Addr _RootX0, 15, Addr szRootX0, SRC1_REAL
; print real10$ (_RootX0) ; print the real number of one real root
; in the quadratic formula
;Get the address of last character of szBuffer
Invoke lstrlen, Addr szBuffer
Add Eax, Offset szBuffer
;Convert the Esi value to a decimal
;string and adds it to szBuffer
Invoke String, Addr szRootX0, Eax, ecDecimal
Invoke lstrcat, Addr szBuffer, Addr szCRLF
; print chr$(13, 10)
Invoke lstrcat, Addr szBuffer, TextAddr(" 1 ")
; print chr$(" 1 ", 13, 10, 13, 10)
Invoke lstrcat, Addr szBuffer, TextAddr(" X = ")
; print chr$(" X = ")
Invoke FpuFLtoA, Addr _RootX1, 15, Addr szRootX1, SRC1_REAL
; print real10$ (_RootX1) ; print the real number of another real root
; in the quadratic formula
;Get the address of last character of szBuffer
Invoke lstrlen, Addr szBuffer
Add Eax, Offset szBuffer
;Convert the Esi value to a decimal
;string and adds it to szBuffer
Invoke String, Addr szRootX1, Eax, ecDecimal
Invoke lstrcat, Addr szBuffer, Addr szCRLF
; print chr$(13, 10)
Invoke lstrcat, Addr szBuffer, TextAddr(" 2 ")
; print chr$(" 2 ", 13, 10)
; print chr$(13, 10)
Invoke lstrcat, Addr szBuffer, Addr szCRLF
Invoke lstrcat, Addr szBuffer, Addr szCRLF
Ret
printTheXRoots EndP
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;<< printLinearFormat will output the format of the linear equation <<
;<< with the two user numbers. <<
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
printLinearFormat Proc Private hWnd:HWND
Local szNumber1[100]:CHAR
Local szNumber2[100]:CHAR
Local szLinearRootX[100]:CHAR
;Get the handle to Results Static control in Eax
Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_RESULTS
;Save it in Edi
Mov Edi, Eax
;Clear the Results control
Invoke SetWindowText, Edi, NULL
;Clear szbuffer
Mov szBuffer[0], 0
Invoke GetWindowText, Edi, Addr szBuffer, 255
Invoke SetWindowText, Edi, Addr szBuffer
;Get the address of last character of szBuffer
Invoke lstrlen, Addr szBuffer
Add Eax, Offset szBuffer
;Adds a carriage return/line feed to szBuffer
Invoke lstrcat, Addr szBuffer, Addr szCRLF
; print chr$(13, 10)
Invoke lstrcat, Addr szBuffer, TextAddr("Linear Equation : Bx + C")
; print chr$("Linear Equation : Bx + C ", 13, 10)
Invoke lstrcat, Addr szBuffer, Addr szCRLF
; print chr$(13, 10)
Invoke lstrcat, Addr szBuffer, TextAddr("The linear equation : ")
; print chr$(" Solution for linear Equation : ", 13, 10)
Invoke lstrcat, Addr szBuffer, TextAddr("---------------------------")
; print chr$("-------------------------------", 13, 10)
Invoke lstrcat, Addr szBuffer, TextAddr(" ")
; print chr$(" ")
Invoke FpuFLtoA, Addr NumberB, 15, Addr szNumber1, SRC1_REAL
;Get the address of last character of szBuffer
Invoke lstrlen, Addr szBuffer
Add Eax, Offset szBuffer
;Convert the Esi value to a decimal
;string and adds it to szBuffer
Invoke String, Addr szNumber1, Eax, ecDecimal
; print ext$ (NumberB, 0, 4) ; display the X coefficient of linear equation
; to 4 decimal places
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(" X + ")
; print chr$(" X + ")
Invoke FpuFLtoA, Addr NumberC, 15, Addr szNumber2, SRC1_REAL
;Get the address of last character of szBuffer
Invoke lstrlen, Addr szBuffer
Add Eax, Offset szBuffer
;Convert the Esi value to a decimal
;string and adds it to szBuffer
Invoke String, Addr szNumber2, Eax, ecDecimal
; print ext$ (NumberC, 0, 4) ; display the constant of linear equation to
; to 4 decimal places
Jmp Next ; just jump
NumberCIs0:
Invoke lstrcat, Addr szBuffer, TextAddr(" X ")
; print chr$(" X ")
Next:
Invoke lstrcat, Addr szBuffer, TextAddr(" = 0 ")
Invoke lstrcat, Addr szBuffer, Addr szCRLF
Invoke lstrcat, Addr szBuffer, Addr szCRLF
; print chr$(" = 0 ", 13, 10, 13, 10)
Invoke lstrcat, Addr szBuffer, TextAddr(" X = ")
; print chr$(" X = ")
Invoke FpuFLtoA, Addr _LinearRootX, 15, Addr szLinearRootX, SRC1_REAL
;Get the address of last character of szBuffer
Invoke lstrlen, Addr szBuffer
Add Eax, Offset szBuffer
;Convert the Esi value to a decimal
;string and adds it to szBuffer
Invoke String, Addr szLinearRootX, Eax, ecDecimal
Invoke lstrcat, Addr szBuffer, Addr szCRLF
; print real10$ (_LinearRootX)
Invoke lstrcat, Addr szBuffer, Addr szCRLF
; print chr$(13, 10, 13, 10)
;print chr$(13, 10)
Ret
printLinearFormat EndP
Egan,
I do not have much time to be fixing your bugs. You have to be able to find them and fix them if you want to program in assembly.
Anyway, if you attach the whole project, I'll try to find all bugs.
Ramon
Hi Ramon,
Well I am trying my best to find the bugs myself and fixing them. It is just when Easy Code says
Exception address then I do not know where to find the bugs without mentioning the line numbers.
Here is my full program in attachment.
Thanks
[attachment deleted by admin]
Egan,
Please why don't you read the parameters for FpuAtoFL before trying to use it? Here is the error (shown in red color):
;Get the handle to Solve button in Eax
Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_GETA
;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
Invoke FpuAtoFL, Eax, Addr NumberA, DEST_FPU
The first parameter for the FpuAtoFL function must be the address to a buffer, not a numerical value. Try to replace the first parameter (Eax) with a buffer containing a real number.
Ramon
Hi
I corrected the error but I do not get any output from my program.
I have included the edited program in my attachment.
[attachment deleted by admin]
Does any one have the time to look at my code in the email attachment?
Egan,
1 - In the printQuadraticFormat procedure there is no return sentence (Ret), so the program does not return and continues execution in the next procedure. That makes the program to crash.
2 - The String method requires the numerical value to be converted as the first parameter, not the address to a buffer as it is being passed (several times) inside the printQuadraticFormat procedure.
BTW: When attaching a project, please include the Res folder too.
I corrected the ret and value for String.
I still can not get the output to work.
[attachment deleted by admin]
Hi found the problem for output.
The error is that I forgot to use the following two lines of instructions which are:
;Get the handle to Results Static control in Eax
Invoke GetWindowItem, hWnd, IDC_QUADRATICSOLUTIONS_RESULTS
Invoke SetWindowText, Eax, Addr szBuffer
My modified program with the wrong number results is in the attachment.
[attachment deleted by admin]
I can not figure out why it does not output real numbers correctly.
Please help me. My program is in the attachment above.
Thanks
Hi
I tried making the quadratic program work but I can't seem to get it.
I have enclosed my project in attachment.
I need help.
Thanks
[attachment deleted by admin]
Hi Ramon,
How do you output a real or floating point number from a Visual project in Easy Code?
Thanks
Hi,
I've never worked with real or floating point numbers, but I think there is some good source code in MASM32. The FPULib maybe?
Ramon
Hi
I need help with my program.
Here is my complete program with code and executable in zip file below.
[attachment deleted by admin]
Hi
Here is my modified code in below link. I still can not get the floating point results to display correctly.
[attachment deleted by admin]
Hi!
If someone continued the work over this program? I such needs to the school and I have with this big problem..
Please help me..
P.S I Apologize for my English....