This is the code i copied from a Stackoverflow.com's Question:
global _main
extern _GetStdHandle@4
extern _WriteFile@20
extern _ExitProcess@4
section .text
_main:
; DWORD bytes;
mov ebp, esp
sub esp, 4
; hStdOut = GetstdHandle( STD_OUTPUT_HANDLE)
push -11
call _GetStdHandle@4
mov ebx, eax
; WriteFile( hstdOut, message, length(message), &bytes, 0);
push 0
lea eax, [ebp-4]
push eax
push (message_end - message)
push message
push ebx
call _WriteFile@20
; ExitProcess(0)
push 0
call _ExitProcess@4
; never here
hlt
message:
db 'Hello, World', 10
message_end:
This Code works correctly, No errors needs to be cleared, But there have some lines which im unable to understand what does they do, Scroll down:
MOV ebp, esp
Okay anyone can tell this copies the contents of esp
to ebp
register, But how can this be possible to copy a uninitialised register's value to a register? Will it load ebp
with a 0
(Zero)?
SUB esp, 4
Here esp
is being subtracted by 4
, So 0-4= -4
, Is'nt it?? But why this Two lines of code? instead if the result is to be the result which i given "-4"
i would have Normaly do MOV esp, -4
MOV ebx, eax
And the eax
, which i think must be filled by _GetstdHandle
function?
and the last one, hlt
?