__SHORT_SEG Segments

Tools access variables on the direct page (between 0 and 0xFF) using direct addressing. The Compiler allocates some variables on the direct page if they are defined in a __SHORT_SEG segment (refer the following listing).

Listing: Allocate Frequently-Used Variables on the Direct Page
#pragma 
DATA_SEG __SHORT_SEG myShortSegment
unsigned int myVar1, myVar2;

#pragma DATA_SEG DEFAULT 

unsigned int myvar3, myVar4

In the previous example, myVar1 and myVar2 are both accessed using direct addressing mode. Variables myVar3 and myVar4 are accessed using extended addressing mode.

When you define some exported variables in a __SHORT_SEG segment, you must also specify in the external declaration for these variables that they are allocated in a __SHORT_SEG segment. The External definition of the variable defined above looks like:

  #pragma DATA_SEG __SHORT_SEG myShortSegment

  
  extern unsigned int myVar1, myVar2;

  
  #pragma DATA_SEG DEFAULT 

  
  extern unsigned int myvar3, myVar4

  

Place the segment on the direct page using the parameter (PRM) file (refer the following listing).

Listing: Linker Parameter File
LINK test.abs
NAMES test.o startup.o ansi.lib END

SECTIONS

    Z_RAM  = READ_WRITE  0x0080 TO 0x00FF; 

    MY_RAM = READ_WRITE  0x0100 TO 0x01FF;

    MY_ROM = READ_ONLY   0xF000 TO 0xFEFF;

PLACEMENT

    DEFAULT_ROM                    INTO  MY_ROM;

    DEFAULT_RAM                    INTO  MY_RAM;

    _ZEROPAGE, myShortSegment      INTO  Z_RAM;

END

STACKSIZE 0x60

VECTOR 0 _Startup /* set reset vector on _Startup */
Note: The Linker is case-sensitive. The segment name must be identical in the C and PRM files.