The SARM space is the most important part of the AVR Microcontroller. All operations must be completed by this Part. There are three storage modes for variables in the SARM space: Tiny, small, and large, which correspond to the three storage properties of _ tiny, _ near, __far. Once the storage mode is selected, the default attribute of the corresponding data is determined, but you can use the _ tiny, _ near ,__ far keyword to change it.
For local variables in the program, the compiler will automatically process them, and we cannot add any storage attributes, but IAR provides powerful external variable definitions.
The IAR compiler uses part of the working registers internally, leaving the user with only 12 R4-R15 registers for use by the user. To use the Working registers, the locking option must be enabled in the project options.
Example:
Define two variables using the working register R14, R15.
#include<iom8.h>
__regvar __no_init char g @ 15;
__regvar __no_init char P @ 14;
void main(void)
{
g++;
P++;
}
Open the register R14-R15 to be used in the C/C ++ complier> code in the project option.
The compilation result is as follows to see if the register is directly used as the data application.
// 4 void main(void)
main:
CFI Block cfiBlock0 Using cfiCommon0
CFI Function main
// 5 { g++;
REQUIRE ?Register_R14_is_global_regvar
REQUIRE ?Register_R15_is_global_regvar
INC R15
// 6 P++; }
INC R14
RET
Note: variables defined in registers cannot have initial values. It is best not to use more than 9 register variables, otherwise it may cause potential danger because no registers are locked during database creation.
Define the absolute address of a variable. Variables without features are randomly allocated. To assign an address to a variable, you must perform feature modification. Note that the address must not overlap with the on-chip Register address when defining the address.
_ No_init or const object must be added for defining absolute address variables without storage features
_ No_init char t @ 0x65; // defined outside the I/O address
Const char t @ 0x65; // defines the address of the read-only variable
Example:
#include<iom8.h>
__no_init char u @ 0x65 ;
void main(void)
{
u++;
}
Corresponding assembly:
void main(void)
\ main:
{u++;}
\ 00000000 E6E5 LDI R30, 101
\ 00000002 E0F0 LDI R31, 0
\ 00000004 8100 LD R16, Z
\ 00000006 9503 INC R16
\ 00000008 8300 ST Z, R16
\ 0000000A 9508 RET
The absolute address _ IO ,__ ext_io of variables defined by keywords with storage features is in the I/O space.
#include<iom8.h>
__io char u @ 0x65 ;
void main(void)
{
u++;
}
Corresponding assembly:
void main(void)
\ main:
{u++;}
\ 00000000 91000065 LDS R16, 101
\ 00000004 9503 INC R16
\ 00000006 93000065 STS 101, R16
\ 0000000A 9508 RET