News:

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

Main Menu

StdOut DW value instead of its ASCII representation ?

Started by AssemblyBeginner, March 10, 2015, 07:12:31 PM

Previous topic - Next topic

AssemblyBeginner

include \masm32\include\masm32rt.inc

.data
      myvar dw 65
.code
     start:
         invoke StdOut, addr myvar
         inkey "Press a key to continue ..."
         invoke ExitProcess, 0
     end start


The above code prints the letter A instead of 65

I believe StdOut  takes a pointer to a string argument .. So how do I print the number instead of its corresponding ascii value ?

Regards.

dedndave

you're right - it want's a null terminated ascii string

what you want to do is convert the binary 65 into the string "65",0
Hutch has a couple routines to do this - dwtoa, i think is one of the names

the easy way is to use one of the macros
if 65 represents a signed value, use "str$"
if it's unsigned, use "ustr$"
in either case, it needs a dword

    movzx   eax,word ptr myvar   ;zero-extend the WORD into a DWORD
    print   str$(eax),13,10


the "print" macro expands into StdOut

rrr314159

There are many ways to do it simplest is change the line to

     myvar db "65", 10, 0
I am NaN ;)

dedndave

you could also define it as a dword
      myvar dd 65

and print directly
    print    str$(myvar),13,10

Vortex

Hi AssemblyBeginner,

Here is another example for you :

include     \masm32\include\masm32rt.inc

.data

format      db 'MyString = %s',13,10
            db 'MyVar    = %d',0
           
MyString    db '65',0
MyVar       dd 65

.code

start:

    invoke  crt_printf,ADDR format,ADDR MyString,MyVar   

    invoke  ExitProcess,0

END start

AssemblyBeginner

#5
Excelelent .. Thank you all  :icon_cool: