Hi...

> unsigned long get_esp()
> {
>     __asm__("movl %esp, %eax");
> }
>
> int main()
> {
>     printf("ESP: 0x%x\n", get_esp());
>     int a;
>     printf("ESP: 0x%x\n", get_esp());
>     return 0;
> }
>
> result)
> ESP: 0xbf9fb048
> ESP: 0xbf9fb048

the thing is, what you "code" isn't always what you get when gcc
finish its job. Even if it seems that "a" is allocated after 1st
printf, in reality "a" is very likely allocated first and then those
two printf()s are called.

you could get different result if if you use brk() or sbrk(). See for yourself.

Hint: use objdump <binary>, for better view compile using gcc -g.Or,
use gcc -S so gcc stops after doing assembling.

regards,

Mulyadi.

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to [EMAIL PROTECTED]
Please read the FAQ at http://kernelnewbies.org/FAQ

Reply via email to