p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Assembly Language (http://p2p.wrox.com/forumdisplay.php?f=195)
-   -   Questions about the pointer registers (http://p2p.wrox.com/showthread.php?t=56119)

alexj_chn April 1st, 2007 02:43 AM

Questions about the pointer registers
 
I'm a new learner of assembly language. When I learned about the pointer registers of Intel IA-32 processors, I've got the questions below:

[?]1)In Intel IA-32 Platform, the processor usually have EBP as "Stack data pointer" and ESP as "Stack pointer", what's the difference between these two registers?

[?]2)I have read the assembly source below:
...
pushl $buffer
pushl $output
call printf
addl $8, %esp
...
Why add 0x8 to register ESP after call "printf"?

Can anybody do me a fever? Thanks.


steven_wort April 30th, 2007 11:21 PM

#1 EBP is also commonly refered to as the Frame Pointer.

ESP is the only one that gets automatically incremented / decremented by the CPU when you call, ret, or push and pop stuff.

EBP is usually only used by a compiler to keep track of the current frame its working with. EBP or the Frame Pointer then becomes a usefull shortcut for all kinds of things.

#2 adding 8 to esp is a simple way to remove the two values pushed onto the stack before calling printf.

With a compiler in the mix, then you could see several variations of this calling convention based on the calling convention for the function being called. In this case printf isnt doing any stack cleanup, so the caller has to do it after printf returns.

Steve Wort
Co Author "Professional SQL Server 2005 Administration"


All times are GMT -4. The time now is 09:40 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.