Ax51 User's Guide

SEGMENT Assembler Statement

Arguments
segname SEGMENT classrelocationalignment〛〛
Description

The SEGMENT statement declares a generic segment along with memory class and segment location options.

Where

segnamespecifies the symbol name to assign to the segment. This symbol is references by subsequent RSEG statements. It may also be used in expressions to represent the base or starting address of the combined segment.
classis the memory classification for the segment. The class specifies the memory space where the segment is located.
relocationdetermines what relocation options are available to the linker for this segment.
alignmentdetermines what address alignment options are available to the linker for this segment.

The name of each segment in a source module must be unique. The linker combines segments that have the same type.

Class

The segment class specifies the memory space for the segment and is used by the linker to access all segments that belong to that class. The following table lists the basic classes.

classDescription
BITThe BIT address space with the valid address range is 20H.0-2FH.7. For example: 21H.5.
CODEThe CODE address space (from 0000h-0FFFFh).
CONST1The CONST address space. This is the same as the CODE space but is used for constants only. This memory is accessed using the MOVC instruction.
DATAThe DATA address space (from 00h-7Fh).
EBIT1The Extended BIT space on 80C251-compatible devices.
ECODE1The entire address space (used for code) on 80C51MX devices.
ECONST1The Extended CONST space (same as EDATA) on 80C251-compatible devices.
EDATA1The Extended DATA space on 80C251-compatible devices.
HCONST1The entire address space (used for constants) on 80C51MX devices.
HDATA1The entire address space (used for data) on 80C51MX devices.
IDATAThe IDATA address space (from 00h-0FFh).
XDATAThe XDATA address space (from 0000h-0FFFFh).
  1. These classes are available in the AX51 Assembler only.

Following are a few examples of segments defined using the basic classes.

seg1    SEGMENT  XDATA
seg2    SEGMENT  HCONST
seg3    SEGMENT  DATA

User-Defined Classes

User-defined classes allow you to access the same address space as basic class names but with greater flexibility and more granular control over program segments. The primary benefit to user-defined segments is the ability to locate only certain segments to specific physical addresses using the linker.

User-defined class names are composed of a basic class name and an extension and are enclosed in single-quotes ('). For example:

seg1    SEGMENT  'XDATA_FLASH'
seg2    SEGMENT  'HCONST_IMAGES'
seg3    SEGMENT  'DATA1'

Note

  • User-defined classes are available in the AX51 Assembler only.

Relocation

The relocation type specifies how the linker may relocate the segment. The following table lists the valid kinds of relocation.

relocationDescription
AT address1 2specifies that the segment is absolute and is located at the specified address.
BITADDRESSABLEspecifies that the segment is located in bit-addressable memory. This relocation type is allowed only for segments in the DATA class whose length does not exceed 16 bytes.
INBLOCKspecifies that the segment must be located in a single 2048-byte block. This relocation type may be specified only for segments in the CODE class. This is typically used for segments with routines that use ACALL and AJMP instructions.
INPAGEspecifies that the segment must be located in a single 256-byte page.
INSEG1specifies that the segment must be located in a single 64K byte segment.
OFFS offset1 2specifies that the segment is absolute and is located at offset bytes from the base address of the segment's memory class. The advantage of the OFFS relocation type over the AT relocation type is that segments defined with an offset may be relocated using the LX51 Linker's CLASSES directive.
OVERLAYABLE 2specifies that the segment may be overlaid with and share the memory of other segments. Segments declared with the OVERLAYABLE relocation type may be overlaid with each other. OVERLAYABLE segments must be declared using the naming conventions of the C51 or CX51 Compiler.
  1. These relocation types are available in the AX51 Assembler only.
  2. These relocation types cannot be used in combination with user-defined classes.

Alignment

The alignment is optional and specifies how the linker allocates the segment. The following table lists the valid alignment types.

alignmentDescription
BIT1specifies bit alignment for the segment. This is the default for all segments with the class BIT.
BYTEspecifies byte alignment for the segment. This is the default for all segments, except for segments with the class BIT.
WORD1specifies word alignment for the segment. This forces the segment to start on an even address.
DWORD1specifies double word alignment for the segment. This forces the segment to start on an address that starts on a 4-byte boundary.
PAGEspecifies 256-byte page alignment for the segment. The segment start must be on a 256-byte page boundary.
BLOCK1specifies 2048-byte block alignment for the segment. This forces the segment to start on a 2048-byte boundary.
SEG1specifies 64 kbyte alignment for the segment. This forces the segment to start on a 64KB boundary.
  1. These alignment types are available in the AX51 Assembler only.
See Also

BSEG, CSEG, DSEG, ISEG, RSEG, XSEG

Example
; a segment named ?ID?IDS and the memory class IDATA.
?ID?IDS SEGMENT  IDATA

; a segment named ?PR?MYSEG at an absolute CODE address.
?PR?MYSEG SEGMENT CODE AT 0x2000

; a segment named ?HD?SEG in the HDATA memory class that
; starts on a 4-byte boundary and is located within one
; 64KB memory block.
?HD?SEG SEGMENT HDATA INSEG DWORD

; a segment named ?XD?ABC in the XDATA memory class. The
; alignment PAGE forces the segment to start on a 256-byte
; page boundary.
?XD?ABS SEGMENT XDATA PAGE

; a segment named ?XD?ABC1 in the XDATA memory class with
; 32-byte alignment.
?XD?ABS SEGMENT XDATA ALIGN(5)