SEGMENT Initiate segment definition Directive
SEGMENT name [attributes] ; Ideal mode
name SEGMENT [attributes] ; MASM mode
Most applications can use segments created using the standard memory
models (defined with the MODEL directive). To get full control over
all aspects of segment generation, the SEGMENT directive is required.
The SEGMENT directive opens a segment. All code or data following it
will be included in the segment, until a corresponding ENDS directive
closes the segment. If you have already defined a segment with the
same name, this segment is treated as a continuation of the previous
one. You need only specify the segment attributes the first time you
open the segment.
Segment attributes are (TASM processes attribute values from left to
right):
- alignment attribute tells the linker to ensure that
a segment begins at a specified
boundary
- combination attribute tells the linker how to combine
segments from different modules
- class attribute helps the linker determine the
order in which segments are to
be ordered in the program file
(e.g. separate code and data)
- size attribute (≥80386) tells linker if segment
is 16 or 32 bit
- access attribute tells linker to apply specific
access restrictions to a segment
(currently only supported by the
Phar Lap linker)
──────────────────────────────────────────────────────────────────────
align specifies the type of memory boundary where the segment must
start: BYTE, WORD, DWORD, PARA (default, 16 bytes), PAGE (256 bytes),
or MEMPAGE (4 KB).
combine specifies how segments from different modules but with the same
name will be combined at link time:
AT expr locates segment at absolute paragraph address expr
(typically used as a template, e.g for the BIOS data
area: SEGMENT bios_data AT 0040h); the linker emits no
code or data for AT segments
COMMON locates this segment and all other segments with the
same name at the same address (overlapping)
MEMORY (same as PUBLIC)
PRIVATE does not combine this segment with any other segments;
this is the default
PUBLIC concatenates all segments with the same name to form
a single contiguous segment
STACK concatenates all segments with the same name to form
a single contiguous segment, then initializes SS to the
beginning of the segment and SP to the length of the
segment
VIRTUAL defines a special kind of segment that will be treated
as a common area and attached to another segment at
link time (permits sharing of static data that comes
into many modules from included files)
UNINIT will cause TASM to warn if any data is written to the
segment (use with uninitialized data segments)
(e.g. SEGMENT udata2 PARA PUBLIC UNINIT "BSS")
class controls the ordering of segments at link time: segments with the
same class name are loaded into memory together, regardless of the order
in which they appear in the source file.
size specifies the default word size for the segment if 80386 code
generation is enabled, and can be either USE16 or USE32.
access
EXECONLY segment is executable only
EXECREAD segment is readable and executable
READONLY segment is readable only
READWRITE segment is readable and writable
The Phar Lap linker assumes that the segment is meant to run in
protected mode if you select any of these attributes, or if you select
the USE32 attribute. TASM assumes the READONLY attribute if you
selected the USE32 attribute but did not specify any of these four
attributes.
──────────────────────────────────────────────────────────────────────
Example showing mixed simplified and generic segmentation:
; File: i.inc
ideal
model nearstack compact, nolanguage
p186
segment bmp_image para public uninit "FAR_BSS"
ends
segment vga_graphics at 0A000h
ends
; File: imain.asm
ideal
include "i.inc"
STACK 200h
DATASEG
fname db "d:\bmp\352x200.bmp",0
UFARDATA bmp_image ; Public segment
buf_size = 0fff0h
bmp_buffer db buf_size dup (?)
UFARDATA pcx_image ; Private segment
pcx_buffer db buf_size dup (?)
CODESEG
procdesc load_n_draw Pascal :dword, :word
StartupCode
call load_n_draw Pascal, ds offset fname, buf_size
ExitCode 0
;...
END @Startup