flat assembler
Message board for the users of flat assembler.
Index
> Main > Stack Frames |
Author |
|
r22 13 May 2005, 00:17
int main(long parameter1){
long aNumber; aNumber = parameter1; return aNumber } --- Code: main: push ebp ;save ebp mov ebp, esp ;mov ptr to stack into ebp, EBP = ESP sub esp, 4 ;subtract 4 from stack ptr reserves 4 bytes (1 long local variable aNumber) mov ecx, [EBP+8] ; move parameter1's value into eax mov [EBP - 4], ecx ; move parameter's value into aNumber mov EAX, ECX ; set the return value add esp, 4 ; unreserve the 4 bytes for the local variable aNumber mov esp, ebp ;set stack back equal to its original value pop ebp ;take the saved EBP value off the stack retn 4 ; ; the return VALUE (aNumber) is always stored in EAX, this return statement is to fix the stack because 1 4byte parameter was passed with the function the stack -parameter1 [EBP+8] ( retn 4 puts stack ptr back here ) -returnaddress -saved ebp [the stack ptr] ebp = ESP = stack frame ptr -local long variable aNumber [EBP - 4] [stack ptr ESP after sub esp,4] |
|||
13 May 2005, 00:17 |
|
shaolin007 13 May 2005, 13:01
Thank you for your help. I now understand how it works. Funny how I had problems understanding this through a book but when you explain it, it becomes crystal clear. Thanks again!
|
|||
13 May 2005, 13:01 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.