Re: simple stack point question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux