I'm trying to get into asm using masm32 but the simple sample code from the tutorial doesn't work
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
.data
BUFFER_LENGTH EQU 1024
szMessageBoxFormat BYTE "The resul is %d", 0
szMessageBoxText BYTE 0 dup(BUFFER_LENGTH)
.code
start:
main proc
push 3
call display_number_in_message_box
ret
main endp
display_number_in_message_box proc
;Create a string representation of the number
mov eax, [esp + 4]
invoke wsprintf, ADDR szMessageBoxText, szMessageBoxFormat, eax
;Display that string in a message box
invoke MessageBoxA, NULL, ADDR szMessageBoxText, NULL, MB_OK
ret 4
display_number_in_message_box endp
end start
I am using C:\masm32\bin\ml.exe /c /coff /Cp ex0.asm
and C:\masm32\bin\link.exe /SUBSYSTEM:WINDOWS /LIBPATH:C:\masm32\lib ex0.obj
to create an exe, but when running it nothing happens, any ideas?
You forgot the ADDR
before szMessageBoxFormat
when you invoke wsprintf
, so you end up passing an invalid address (probably 20656854h
, i.e. "The "
interpreted as a DWORD
).