In addition to the ANSI storage classes SDCC allows the following MCS51 specific storage classes.
This is the default storage class for Small Memory model. Variables declared with this storage class will be allocated in the directly addressable portion of the internal RAM of a 8051, e.g.:
data unsigned char test_data;Writing 0x01 to this variable generates the assembly code:
75*00 01 mov _test_data,#0x01
Variables declared with this storage class will be placed in the external RAM. This is the default storage class for Large Memory model, e.g.:
xdata unsigned char test_xdata;Writing 0x01 to this variable generates the assembly code:
90s00r00 mov dptr,#_test_xdata
74 01 mov a,#0x01
F0 movx @dptr,a
Variables declared with this storage class will be allocated into the indirectly addressable portion of the internal ram of a 8051, e.g.:
idata unsigned char test_idata;Writing 0x01 to this variable generates the assembly code:
78r00 mov r0,#_test_idata
76 01 mov @r0,#0x01
Paged xdata access is currently not as straightforward as using the other addressing modes of a 8051. The following example writes 0x01 to the address pointed to. Please note, pdata access physically accesses xdata memory. The high byte of the address is determined by port P2 (or in case of some 8051 variants by a separate Special Function Register).
pdata unsigned char *test_pdata_ptr;Generates the assembly code:
void main()
{
test_pdata_ptr = (pdata *)0xfe;
*test_pdata_ptr = 1;
}
75*01 FE mov _test_pdata_ptr,#0xFEBe extremely carefull if you use pdata together with the --xstack option.
78 FE mov r0,#0xFE
74 01 mov a,#0x01
F2 movx @r0,a
'Variables' declared with this storage class will be placed in the code memory:
code unsigned char test_code;Read access to this variable generates the assembly code:
90s00r6F mov dptr,#_test_code
E4 clr a
93 movc a,@a+dptr
This is a data-type and a storage class specifier. When a variable is declared as a bit, it is allocated into the bit addressable memory of 8051, e.g.:
bit test_bit;Writing 1 to this variable generates the assembly code:
D2*00 setb _test_bit
Like the bit keyword, sfr / sbit signifies both a data-type and storage class, they are used to describe the special function registers and special bit variables of a 8051, eg:
sfr at 0x80 P0; /* special function register P0 at location 0x80 */
sbit at 0xd7 CY; /* CY (Carry Flag) */
SDCC allows (via language extensions) pointers to explicitly point
to any of the memory spaces of the 8051. In addition
to the explicit pointers, the compiler uses (by default) generic pointers
which can be used to point to any of the memory spaces.
Pointer declaration examples:
/* pointer physically in internal ram pointing to object in external ram */Well you get the idea.
xdata unsigned char * data p;
/* pointer physically in external ram pointing to object in internal ram */
data unsigned char * xdata p;
/* pointer physically in code rom pointing to data in xdata space */
xdata unsigned char * code p;
/* pointer physically in code space pointing to data in code space */
code unsigned char * code p;
/* the following is a generic pointer physically located in xdata space */
char * xdata p;