Here's an example
Code:
push ebp //Push the base pointer
mov ebp, esp //Set the base pointer to the current stack pointer
add esp, -4 //Subtract 4 from the stack. Equivalent of PUSH DWORD 0. This will hold the local variable. [EBP-4] and [ESP] now points to the local variable
lea ecx, [eax*4+1024] //ecx := eax*4+1024
mov [ebp-4], ecx //store ecx in the local variable
mov eax, [ebp-4] //store the local variable in result
mov esp, ebp //restore the old stack pointer
pop ebp //pop the old base pointer
ret
This is ofcourse a pretty naive and unoptimized code sample, but it goes to show how to write assembler
The equivalent pascal code:
[pascal]
function GetIndex(i: integer): integer;
var x: integer;
begin
x := i*4+1024;
result := x;
end;
[/pascal]
Bookmarks