From: Joris v. d. S. <vd...@pu...> - 2001-02-14 22:31:28
|
Hi Rod, > int FnDivide( int param1, int param2 ) > { > return( param1 / param2 ); > } > > This example is very simple and may not work on the 8051 but > because the stack is used to pass the parameters and return the > result this function although simple is an example of a re- > entrant function. Sorry, I disagree to this part of your explanation. SDCC will normally use registers to pass the `param1' and `param2' variables and the return value in this case, _not_ the stack! Only because your example function doesn't use local variables, will it be reentrancy-safe. However, this is not a very robust example as people might think that any normal function is reentrant. Only if you use the `reentrant' keyword, the function will be reentrancy-safe. However, depending on the memory model, the compiler still won't use the actual hardware stack, but uses a virtual emulated stack in either the `idata' area (small memory model) or the `xdata' area (large memory model). You are right that most compilers for the larger 16- or 32-bit system will normally use the stack. However, the 8051 has a tiny stack and no efficient addressing mode to obtain information from the stack. This makes it more efficient to store parameters at fixed memory locations at the cost of no longer being reentrancy- safe. Regards, Joris |