By using this site, you agree to our Privacy Policy and our Terms of Use. Close
alephnull said:
MisterBlonde said:
@alephnull

The function paramaters are accessed via offsets from ebp. There aren't enough registers to store all the parameters for a particular callstack. They are pushed and popped onto the stack. All compilers do is compile c code into assembly instructions that are executed by the CPU. At run time they are non existent (unless you are talking about a JIT compiler). The assembly code will do the pushing and popping.

Eip points to the next instruction to be executed. When a function makes a call it pushes it's return address onto the stack. There is no way during a synchronous call for the calling function to be running until the called function returns. That is what crashman was saying and that is what I was agreeing with. When the called function returns the calling function's return address is popped back into eip.

google function prologue and epilogue for more details.

 

If you don't think the compiler is involved what do you think happens when you add the keyword inline before a function definition? Would you agree with me that the compiler does not put an inline function's parameters on the call stack?

Try doing a backtrace on a piece of code compiled with -O3 in gcc. I think you will find that it inlines quite a bit. Particularly with the CBE and Xenon you have over a hundred registers per core, and if you don't think copious inlining is going on then... well, I dunno.

 

inline functions replace their function call with the actual code for the function, so you are right there, there is no pushing and popping off the stack.  There may be, however, memory read/writes since you may have more params than available registers.

However, inline functions have to be used carefully.  They can increase code size dramatically.  You could eliminate all stack push/pops by making your code all one function, but that is horrible design, and would basically be what inlineing all your functions does.

inline eliminates the benefits of functions by not reusing code.  If you have:

inline int functiona(int a, int b, int c)
{
//Code Here
}

and this function is called 100 different times, the "Code Here" section is compiled in to assembly 100 times.  Ouch.



I am a Gauntlet Adventurer.

I strive to improve my living conditions by hoarding gold, food, and sometimes keys and potions. I love adventure, fighting, and particularly winning - especially when there's a prize at stake. I occasionally get lost inside buildings and can't find the exit. I need food badly. What Video Game Character Are You?

Mega Man 9 Challenges: 74%

Waltz Tango Jitterbug Bust a move Headbanging
Bunny Hop Mr. Trigger Happy Double Trouble Mr. Perfect Invincible
Almost Invincible No Coffee Break Air Shoes Mega Diet Encore
Peacekeeper Conservationist Farewell To Arms Gamer's Day Daily Dose
Whomp Wiley! Truly Addicted! Truly Hardcore! Conqueror Vanquisher
Destroyer World Warrior Trusty Sidearm Pack Rat Valued Customer
Shop A Holic Last Man Standing Survivor Hard Rock Heavy Metal
Speed Metal Fantastic 9 Fully Unloaded Blue Bomber Eco Fighter
Marathon Fight Quick Draw G Quick Draw C Quick Draw S Quick Draw H
Quick Draw J Quick Draw P Quick Draw T Quick Draw M Quick Draw X