Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 ユーザーズマニュアル

製品コード
SW006021-1
ページ / 518
MPLAB
®
 XC8 C Compiler User’s Guide
DS52053B-page 178
 2012 Microchip Technology Inc.
5.5.6
Variables in Registers
Allocating variables to registers, rather than to a memory location, can make code more 
efficient. With MPLAB XC8, there is no direct control of placement of variables in reg-
isters. The register keyword (which can only be used with auto variables) is silently 
ignored and has no effect on memory allocation of variables.
There are very few registers available for caching of variables on PIC baseline and 
mid-range devices, and as these registers must be frequently used by generated code 
for other purposes, there is little advantage in using them. The cost involved in loading 
variables into registers would far outweigh any advantage of accessing the register. At 
present, code compiled for PIC18 devices also does not utilise registers other than that 
described below.
Some arguments are passed to functions in the W register rather than in a memory 
location; however, these values will typically be stored back to memory by code inside 
the function so that W can be used by code associated with that function. See 
Section 5.8.5 “Function Size Limits” for more information as to which parameter 
variables may use registers.
5.5.7
Dynamic Memory Allocation
Dynamic memory allocation, (heap-based allocation using malloc, etc.) is not sup-
ported on any 8-bit device. This is due to the limited amount of data memory, and that 
this memory is banked. The wasteful nature of dynamic memory allocation does not 
suit itself to the 8-bit PIC device architectures.
5.5.8
Memory Models
MPLAB XC8 C Compiler does not use fixed memory models to alter allocation of vari-
ables to memory. Memory allocation is fully automatic and there are no memory model 
controls.