News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Converting string to it's integer representation?

Started by clashie, August 24, 2007, 01:55:44 AM

Previous topic - Next topic

clashie

So, basically I want to make use of functions such as atoi, itoa, etc. How can I go about doing this? They are a part of stdlib, right? Is it possible to make use of this in MASM, or is there another way?

MichaelW

Both, it's possible to use the CRT functions in MASM, and there are other ways.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      astring db "12345678",0
      format  db "%d%c", 0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    invoke crt_atoi, ADDR astring
    invoke crt_printf, ADDR format, eax, 10

    ; atodw is part of the MASM32 library, and ustr$ is a macro

    invoke atodw, ADDR astring
    print ustr$(eax), 13, 10

    inkey "Press any key to exit..."
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

eschew obfuscation

GregL

#2
Michael beat me to it. Attached is a quick translation of some examples in C from MSDN. A couple notes.
1. The C Run-Time functions are prefixed with 'crt_' to avoid conflicts with MASM keywords and MASM32 functions.
2. If you use INVOKE (and PROTO) MASM will balance the stack for you with C calling-convention functions.



[attachment deleted by admin]