Printing a single char in Assembly with printf

See more x86 assembly information at:
http://devel.archefire.org/forum/viewforum.php?hl=en&f=27
http://devel.archefire.org/forum/viewforum.php?hl=en&f=27
http://devel.archefire.org/forum/viewforum.php?hl=en&f=27
http://devel.archefire.org/forum/viewforum.php?hl=en&f=27

push eax ;Param 1. Must contain the value of the char in AL, the rest of EAX is ignored
push dword str_percent_c ;Param 0. Must point to a string containing "%c"
call printf
add eax,8 ;Cleanup the stack from the 2 32-bit parameters

For example in a Windows program:

mov wideax,0xABCD21
; printf("%c",wideax);
;;
push wideax ;Param 1
push wideword str_percent_c ;Param 0
call wideword[printf@MSVCRT.DLL] ;CALL, CRTDLL.DLL or MSVCRT.DLL, MSVCRT60.DLL
add widesp,wideword_sz*2 ;Stack clean

The string would be like this in the PE EXE file data section:

str_percent_c equ $+ImageBase-data_RVA_Localize
db "%c",0

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories