Справочник Пользователя для Microchip Technology SW006021-1N
C Language Features
2012 Microchip Technology Inc.
DS52053B-page 165
5.5
MEMORY ALLOCATION AND ACCESS
There are two broad groups of RAM-based variables: auto/parameter variables, which
are allocated to some form of stack, and global/static variables, which are positioned
freely throughout the data memory space at static locations. The memory allocation of
these two groups is discussed separately in the following sections.
are allocated to some form of stack, and global/static variables, which are positioned
freely throughout the data memory space at static locations. The memory allocation of
these two groups is discussed separately in the following sections.
5.5.1
Address Spaces
All 8-bit PIC devices have a Harvard architecture, which has a separate data memory
(RAM) and program memory space (often flash). Some devices also implement
EEPROM.
(RAM) and program memory space (often flash). Some devices also implement
EEPROM.
The data memory uses banking to increase the amount of available memory (referred
to in the data sheets as the general purpose register file) without having to increase the
assembly instruction width. One bank is “selected” by setting one or more bits in an
SFR. (Consult your device data sheet for the exact operation of the device you are
using.) Most instructions which access a data address use only the offset into the cur-
rently selected bank to access data. The exception is the PIC18 instruction MOVFF,
which takes a full banked address and operates independently of the selected bank.
Some devices only have one bank but many have more than one.
to in the data sheets as the general purpose register file) without having to increase the
assembly instruction width. One bank is “selected” by setting one or more bits in an
SFR. (Consult your device data sheet for the exact operation of the device you are
using.) Most instructions which access a data address use only the offset into the cur-
rently selected bank to access data. The exception is the PIC18 instruction MOVFF,
which takes a full banked address and operates independently of the selected bank.
Some devices only have one bank but many have more than one.
Both the general purpose RAM and SFRs both share the same data space and may
appear in all available memory banks. PIC18 devices have all SFRs in the one data
bank, but mid-range and baseline devices have SFRs at the lower addresses of each
bank. Due to the location of SFRs in these devices, the general purpose memory
becomes fragmented and this limits the size of most C objects.
appear in all available memory banks. PIC18 devices have all SFRs in the one data
bank, but mid-range and baseline devices have SFRs at the lower addresses of each
bank. Due to the location of SFRs in these devices, the general purpose memory
becomes fragmented and this limits the size of most C objects.
The Enhanced mid-range devices overcome this fragmentation by allowing a linear
addressing mode, which allows the general purpose memory to be accessed as one
contiguous chunk. Thus, when compiling for these devices, the maximum allowable
size of objects typically increases. Objects defined when using PIC18 devices can also
typically use the entire data memory. See Section 5.5.2.3 “Size Limits of Auto
Variables” and Section 5.5.2.1.2 “Non-Auto Variable Size Limits”.
addressing mode, which allows the general purpose memory to be accessed as one
contiguous chunk. Thus, when compiling for these devices, the maximum allowable
size of objects typically increases. Objects defined when using PIC18 devices can also
typically use the entire data memory. See Section 5.5.2.3 “Size Limits of Auto
Variables” and Section 5.5.2.1.2 “Non-Auto Variable Size Limits”.
Many devices have several bytes which can be accessed regardless of which bank is
currently selected. This memory is called common memory. The PIC18 data sheets
refer to the bank in which this memory is stored as the access bank, and hence it is
often referred to as the access bank memory. Since no code is required to select a bank
before accessing these locations, access to objects in this memory is typically faster
and produces smaller code. The compiler always tries to use this memory if possible.
currently selected. This memory is called common memory. The PIC18 data sheets
refer to the bank in which this memory is stored as the access bank, and hence it is
often referred to as the access bank memory. Since no code is required to select a bank
before accessing these locations, access to objects in this memory is typically faster
and produces smaller code. The compiler always tries to use this memory if possible.
The program memory space is primarily for executable code, but data can also be
located here. There are several ways the different device families locate and read data
from this memory, but all objects located here will be read-only.
located here. There are several ways the different device families locate and read data
from this memory, but all objects located here will be read-only.
5.5.2
Variables in Data Space Memory
Most variables are ultimately positioned into the data space memory. The exceptions
are non-auto variables which are qualified as const, which are placed in the program
memory space, or eeprom qualified variables.
are non-auto variables which are qualified as const, which are placed in the program
memory space, or eeprom qualified variables.
Due to the fundamentally different way in which auto variables and non-auto vari-
ables are allocated memory, they are discussed separately. To use the C language ter-
minology, these two groups of variables are those with automatic storage duration and
those with permanent storage duration, respectively.
ables are allocated memory, they are discussed separately. To use the C language ter-
minology, these two groups of variables are those with automatic storage duration and
those with permanent storage duration, respectively.