Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 Manuale Utente
Codici prodotto
SW006021-1
MPLAB
®
XC8 C Compiler User’s Guide
DS52053B-page 186
2012 Microchip Technology Inc.
Unlike auto variables, parameter variables are allocated memory strictly in the order
in which they appear in the function’s prototype. This means that the parameters will
always be placed in the same memory bank. The auto variables for a function can be
allocated across multiple banks and in any order.
in which they appear in the function’s prototype. This means that the parameters will
always be placed in the same memory bank. The auto variables for a function can be
allocated across multiple banks and in any order.
The parameters for functions that take a variable argument list (defined using an ellipsis
in the prototype and which are called non-prototyped parameters) are placed in the
parameter memory, along with named parameters.
in the prototype and which are called non-prototyped parameters) are placed in the
parameter memory, along with named parameters.
Take, for example, the following ANSI-style function.
void test(char a, int b);
The function test() will receive the parameter b in its function auto-parameter block
and a in the W register. A call to this function:
and a in the W register. A call to this function:
test(xyz, 8);
would generate code similar to:
MOVLW
08h
; move literal 0x8 into...
MOVWF
?_test
; the auto-parameter memory
CLRF
?_test+1
; locations for the 16-bit parameter
MOVF
_xyz,w
; move xyz into the W register
CALL
(_test)
In this example, the parameter b is held in the memory locations ?_test (LSB) and
?_test+1
?_test+1
(MSB).
The exact code used to call a function, or the code used to access a parameters from
within a function, can always be examined in the assembly list file. See
Section 4.8.17 “--ASMLIST: Generate Assembler List Files” for the option that
generates this file. This is useful if you are writing an assembly routine that must call a
function with parameters, or accept arguments when it is called. The above example
does not consider data memory banking or program memory paging, which may
require additional instructions.
within a function, can always be examined in the assembly list file. See
Section 4.8.17 “--ASMLIST: Generate Assembler List Files” for the option that
generates this file. This is useful if you are writing an assembly routine that must call a
function with parameters, or accept arguments when it is called. The above example
does not consider data memory banking or program memory paging, which may
require additional instructions.