GCC 3.2/x86 Question

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

 



Hi All,
I have two relatively simple questions. First I am using some inline assembly
that captures the current value of %esp and then calls a funtion which takes %esp
as it only arg then spits out the difference between the two. Now, this should give
me the amount of stack 'usage' for the function including stack variables and args,
right. Well, the number seem a little funny, and not know that much about assembly
I can't really surmise whether gcc is really just allocating more than enough stack or
I screwed up. So the question is does the code below give the actual stack usage?


void
somefunc(int esp)
{
   int esp1;

asm ("movl %%esp, %0;" :"=m"(esp1));

   printf("%d\n", esp - esp1);
}

int
main(void)
{
   int esp;

asm ("movl %%esp, %0;" :"=m"(esp));

   somefunc(esp);
}

Second question. From looking at some of the docs and testing a small chunk of code (see below), I can't seem to get the value of EIP or IP
(Instruction Pointer) from inline assembly. Does anyone know how to do this?

asm ("movl %%eip, %0;" :"=m"(eip));


Thanks in advance, Jens Thomsen

--
Jens Thomsen
Deep Magic Consulting




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux