Variables

The following listing shows variable examples.

Listing: Examples of Variables
#pragma CREATE_ASM_LISTING ON 
struct A {

  char a;

  int i:2;

};

struct A VarA;

#pragma DATA_SEG __SHORT_SEG ShortSeg

int VarInt;

Declare variables with XREF. In addition, for structures, EQU directives define every field. For bitfields, define the bit offset and bit size.

Define variables in the __SHORT_SEG segment with XREF.B, which informs the assembler about the direct access. EQU.B directives define the structure fields in __SHORT_SEG segments.

Listing: Examples of Variables
                        XREF VarA
VarA_a                  EQU VarA + $0

VarA_i                  EQU VarA + $1

VarA_i_BIT_WIDTH        EQU $2

VarA_i_BIT_OFFSET       EQU $0

                        XREF.B VarInt

The Compiler does not write the variable size explicitly. To generate the variable size, use a typedef with the variable type.

The offsets, bit widths, and bit offsets given here are examples. Different compilers may generate different values. In C, the Compiler determines the structure alignment and the bitfield allocation and specifies the correct values.