How to convert a string to a signed number?
If you considered in line with the field EDIT
PUSH OFFSET string
PUSH 255
PUSH WM_GETTEXT
PUSH HWNDEDT2
CALL SendMessageA@16
e.g. using the CRT function sscanf (https://msdn.microsoft.com/en-us/library/zkx076cy.aspx):
; x is SDWORD
; frmt db "%d",0
invoke crt_sscanf, ADDR string, ADDR frmt, ADDR x
In the MASM32 library there is also the function atol:
invoke atol,ADDR string
mov x,eax
...and a macro:
mov x, sval(ADDR string)
Pure assembler :biggrin:
include \masm32\MasmBasic\MasmBasic.inc ; download (http://masm32.com/board/index.php?topic=94.0)
Init
Inkey Str$("The decimal representation of your input is %i", Val(Prompt$("Type a decimal, hex or binary number, then close this window:", "0x123")))
Exit
EndOfCode
In kernel32.inc not described functions atol, strtoint. What to do?
I Use MASM32.
Use the recommended include file. The functions you refer to are in MSVCRT.
The include file is "masm32rt.inc".
QuoteIn kernel32.inc not described functions atol, strtoint.
atol is defined in \masm32\include\masm32.inc
About StrToInt :
https://msdn.microsoft.com/en-us/library/windows/desktop/bb773446%28v=vs.85%29.aspx
Quote from: ikudesnik on October 04, 2015, 01:33:43 AM
If you considered in line with the field EDIT
PUSH OFFSET string
PUSH 255
PUSH WM_GETTEXT
PUSH HWNDEDT2
CALL SendMessageA@16
we generally use INVOKE to do that for us....
INVOKE SendMessage,HWNDEDT2,WM_GETTEXT,255,offset string
if you start your program with this single line,
it will add most of the inc's and lib's you will need
INCLUDE \Masm32\Include\Masm32rt.inc
i often add these lines after that one, to enable newer instructions
.686p
.MMX
.XMM
Quote from: ikudesnik on October 04, 2015, 01:33:43 AM
If you considered in line with the field EDIT
PUSH OFFSET string
PUSH 255
PUSH WM_GETTEXT
PUSH HWNDEDT2
CALL SendMessageA@16
I see that nobody here honours my fantastic Val (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1202) macro :(
So, here is a plain WinAPI solution: GetDlgItemInt.
Quote from: jj2007I see that nobody here honours my fantastic Val macro :(
- somebody once advised "cast not your pearls before swine" :biggrin: