11.12 Transferring parameters to stacked functions via registers
-----------------------------------------------------------------
Transferring parameters via registers most often produces smaller and
faster code. But the contents of the registers can easily be destroyed. If
any of the parameters in a function is used once to initialize some
register at the beginning of the function, then this value can be
transferred to the function immediately via the register, omitting the
stage of push and pop of the contents to the stack.
For example:
int proc (int param1, param2, param3)
{
(E)BX = param3;
(E)BX.TEG_STRUCT.var = proc2 (param1,papra2);
proc3 (param1,param2);
}
In the following example param3 is used only to initialized (E)BX,
therefore it can immediately be transferred via the register:
int proc (int param1, param2, (E)BX)
{
(E)BX.TEG_STRUCT.var = proc2 (param1,papra2);
proc3 (param1,param2);
}
As you can see, the function has been somewhat simplified.
In theory, the order of stack and register parameters is not important.
But note that the contents of registers can easily be destroyed and
therefore it is best to initialize register parameters only after all stack
parameters have been pushed to the stack. For 'pascal' type functions the
register parameters are best located after the stack parameters. For
'cdecl' and 'stdcall' type functions, it is best to first locate the
register parameters.