Passing parameters

PowerBASIC 32-bit compilers pass all parameters to procedures by pushing them in sequence from right to left.  This is always the case when a procedure uses the default calling conventions of SDECL (and its synonym STDCALL), or the C calling conventions of CDECL.  However, if the optional BDECL calling conventions are specified, parameters are pushed from left to right, and the called code is responsible for cleaning up the stack frame before returning.  PowerBASIC Subs ands Functions that use the BDECL convention automatically clean up the stack before returning execution to the calling code.

By default, PowerBASIC passes parameters by reference: a 32-bit pointer to the data.  You can also pass most parameters by value, by declaring with the optional BYVAL keyword.  When a parameter is passed by value, the actual value of the parameter is pushed on the stack.

Fixed-length strings, nul-terminated strings, and User-Defined Types/Unions may also be passed as BYVAL or OPTIONAL parameters, now.  Try to avoid passing large items BYVAL, as itís terribly inefficient, and there is a maximum size limit of 64 Kb for a given parameter list.  Arrays cannot be passed BYVAL.

PowerBASIC automatically sets up a local "stack frame" at the beginning of each procedure in your program.  As per standard conventions, the EBP register is used to address the parameters.  The lowest parameter can be found at EBP+8, and subsequent parameters will be found in adjacent locations on the stack.

In assembler routines, it is easier and safer to access parameters by name rather than calculating their locations on the stack.  However, it is important to remember the difference in accessing parameters passed by value and parameters passed by reference.


See Also

The Inline Assembler

Parameters passed by reference or by copy

Parameters passed by value

Passing arrays

Passing dynamic strings

Accessing PowerBASIC variables by name