The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: clashie on August 24, 2007, 01:55:44 AM

Title: Converting string to it's integer representation?
Post by: clashie on August 24, 2007, 01:55:44 AM
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?
Title: Re: Converting string to it's integer representation?
Post by: MichaelW on August 24, 2007, 03:37:08 AM
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

Title: Re: Converting string to it's integer representation?
Post by: GregL on August 24, 2007, 04:07:12 AM
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]