Mikroelektronika MIKROE-724 データシート

ページ / 726
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
173
Memory Type Qualifiers
In addition to the standard storage qualifiers(
const, volatile
) the compiler introduces storage qualifiers of 
near 
and
 far.
Near Memory Qualifier
 
1. 
Data Memory Objects 
 
    The qualifier 
near
 is used to denote that a variable is allocated in near data space (the first 8 kB of Data  
 
    memory). Such variables can sometimes be accessed more efficiently than variables not allocated (or not  
 
    known to be allocated) in near data space. 
 
    If variables are allocated in the near data section, the compiler is often able to generate better (more  
 
    compact) code than if the variables are not allocated in the near data section.
 
2. 
Program Memory Objects 
 
    The qualifier 
near
 is used to denote that a constant is allocated in the default program memory page  
 
    (32kB segment of program memory). Default program memory page is the one with most free space and  
 
    is set by the compiler by analyzing program memory pages. 
 
    This qualifier is set as default by the compiler, if no other qualifier is used.
Far Memory Qualifier
 
Data Memory Objects 
 
 The qualifier 
far
 is used to denote that a variable will not be in near data space (i.e. the variable can be  
 
 located  anywhere in data memory). This qualifier is set as default by the compiler, if no other qualifier is  
 
 used.
 
2. 
Program Memory Objects 
 
 The qualifier 
far
 is used to denote that a constant can be allocated anywhere in the program memory, in  
 
 the page pointed to by PSVPAG register.
Location of object based on memory qualifiers:
Qualifier/Memory
Data Memory
Program Memory 
near
First 8 kB of RAM
In default page
far
Anywhere in RAM
In page pointed to PSVPAG register
Example: 
dim i as char  ‘ far memory qualifier is set, variable i can allocated somewhere in data memory
dim j as char near ‘ near memory qualifier is set, variable j will be allocated in the 
first 8kB of data memory
const k as longint = 10000  ‘ near memory qualifier is set, constant k will be allocated 
in the default memory page
Related topics: dsPIC Memory Organization, dsPIC Memory Type Specifiers