Keil Logo

SEGMENT Assembler Statement

Arguments
segname SEGMENT classrelocationalignment〛〛
Description

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

Where

segname specifies 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.
class is the memory classification for the segment. The class specifies the memory space where the segment is located.
relocation determines what relocation options are available to the linker for this segment.
alignment determines 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.

class Description
BIT The BIT address space with the valid address range is 20H.0-2FH.7. For example: 21H.5.
CODE The CODE address space (from 0000h-0FFFFh).
CONST The 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.
DATA The DATA address space (from 00h-7Fh).
EBIT The Extended BIT space on 80C251-compatible devices.
ECODE The entire address space (used for code) on 80C251 devices.
ECONST The Extended CONST space (same as EDATA) on 80C251-compatible devices.
EDATA The Extended DATA space on 80C251-compatible devices.
HCONST The entire address space (used for constants) on 80C251 devices.
HDATA The entire address space (used for data) on 80C251 devices.
IDATA The IDATA address space (from 00h-0FFh).
XDATA The XDATA address space (from 0000h-0FFFFh).

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'

Relocation

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

relocation Description
AT address specifies that the segment is absolute and is located at the specified address.
BITADDRESSABLE specifies 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.
INBLOCK specifies 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.
INPAGE specifies that the segment must be located in a single 256-byte page.
INSEG specifies that the segment must be located in a single 64K byte segment.
OFFS offset specifies 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 L251 Linker's CLASSES directive.
OVERLAYABLE specifies 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 C251 Compiler.

Alignment

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

alignment Description
BIT specifies bit alignment for the segment. This is the default for all segments with the class BIT.
BYTE specifies byte alignment for the segment. This is the default for all segments, except for segments with the class BIT.
WORD specifies word alignment for the segment. This forces the segment to start on an even address.
DWORD specifies double word alignment for the segment. This forces the segment to start on an address that starts on a 4-byte boundary.
PAGE specifies 256-byte page alignment for the segment. The segment start must be on a 256-byte page boundary.
BLOCK specifies 2048-byte block alignment for the segment. This forces the segment to start on a 2048-byte boundary.
SEG specifies 64 kbyte alignment for the segment. This forces the segment to start on a 64KB boundary.
ALIGN (n) Specifies segment alignment as 2n where n can be a value from 1-23.
See Also

ALIGN, 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 0xFF2000

; 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)
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.