martedì 20 dicembre 2011

Assembly Hello World

.386                    ;this specifies the architecture type
.model flat, stdcall   ;stack size (stdcall = arguments read right->left
option casemap :none

;we must link and include some files
include \masm32\include\
include \masm32\include\
include \masm32\include\

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

;define data segment
msg db "Hello, World!", 0 ; the output string

.code ;code segment

;the code
mov eax, MB_OK ;move in eax register the MB_OK value
push eax;      push it in the stack
lea eax, msg ;lea = load effective address (put it in eax)
push eax;third parameter
push eax;second parameter (they're the same)
;first argument, a NULL (0)
xor eax, eax ; set eax to 0
push eax; push int the stack
; now we have pushed in the stack the arguments
;let's call the funcion
call MessageBox
xor eax, eax
push eax
call ExitProcess ;exit the program

end start