News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

How to convert a string to a signed number?

Started by ikudesnik, October 04, 2015, 01:32:07 AM

Previous topic - Next topic

ikudesnik


ikudesnik

If you considered in line with the field EDIT

PUSH OFFSET string
PUSH 255
PUSH WM_GETTEXT
PUSH HWNDEDT2
CALL SendMessageA@16

qWord

e.g. using the CRT function sscanf:
; 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)
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

Pure assembler :biggrin:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  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

ikudesnik

In kernel32.inc not described functions atol, strtoint. What to do?
I Use MASM32.

hutch--

Use the recommended include file. The functions you refer to are in MSVCRT.

The include file is "masm32rt.inc".

Vortex

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

dedndave

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

jj2007

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 macro :(

So, here is a plain WinAPI solution: GetDlgItemInt.

rrr314159

Quote from: jj2007I see that nobody here honours my fantastic Val macro :(

- somebody once advised "cast not your pearls before swine" :biggrin:
I am NaN ;)