• Keine Ergebnisse gefunden

Defining generic segments and groups

Im Dokument . TUrbo Assembler" (Seite 107-111)

The SEGMENT directive

Most applications can use segments created using the standard models.

These standard models, however, are limited in their flexibility. Some applications require full control over all aspects of segment generation;

generic segment directives provide this flexibility.

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.

The Ideal mode syntax for the SEGMENT directive is:

SEGMENT name [attributes]

You can use the following syntax for MASM mode:

name SEGMENT [attributes]

name is the name of the segment. You should name segments according to their usages. See Appendix A for examples of segment names.

Note that Turbo

You can open and close a segment of the same name many times in a single module. In this case, Turbo Assembler concatenates together the sections of the segment in the order it finds them. You only need to specify the

attributes for the segment the first time you open the segment.

attributes includes any and all desired segment attribute values, for each of the following:

• segment combination attribute .. segment class attribute

.. segment alignment attribute

II segment size attribute

1'1 segment access attribute

The segment combination attribute tells the linker how to combine segments from different modules that have the same name. The following table lists the legal values of the segment combination attribute. Note that if you don't specify the combine type, Turbo Assembler assumes PRIVATE.

Attribute value

Segment will not be combined with any other segments of the same name outside of this module.

Segment will be concatenated with other segments of the same name outside of this module to form a single contiguous segment.

Same as PUBLIC. Segment will be concatenated with other segments of the same name outside this module to form a single contiguous segment, used as the default stack. The linker initializes values for the initial SS and SP registers so that they point to the end of these segments.

Locates this segment and all other segments with the same name at the same address. All segments of this name overlap shared memory. The length of the resulting common segment is the length of the longest segment from a single module.

Defines a special kind of segment that must be declared inside an enclosing segment. The linker treats it as a common area and attaches it to the enclosing segment. The virtual segment inherits its attributes from the enclosing segment. The assume directive considers a virtual segment to be a part of its parent segment; in all other ways, a virtual segment is a common area that is combined across modules. This permits the sharing of static data that comes into many modules from included files.

Locates the segment at the absolute paragraph address that the expression xxx specifies. The linker doesn't emit any data or code for AT segments. Use AT to allow symbolic access to fixed memory locations, such as the display screen or ROM areas.

Table 7.6: Segment combination attribute (continued)

UNINIT Produces a warning message to let you know that you have inadvertently written initialized data to uninitialized data segments. For example, you can specify the following to produce a warning message: BSS SEGMENT PUBLIC WORD UNINIT I BSS I . To disable this warning message, use the NOWARN UNI directive. You can reenable the message by using the WARN UNI directive.

Segment class The segment class attribute is a quoted string that helps the linker attribute determine the proper ordering of segments when it puts together a

program from modules. The linker groups together all segments with the same class name in memory. A typical use of the class name is to group all the code segments of a program together (usually the class CODE is used for this). Data and uninitialized data are also grouped using the class mechanism.

Segment alignment The segment alignment attribute tells the linker to ensure that a segment attribute begins on a specified boundary. This is important because data can be

loaded faster on the 80x86 processors if it's properly aligned. The following table lists legal values for this attribute.

Table 7.7

No special alignment; start segment on the next available byte.

Start segment on the next word-aligned address.

Start segment on the next doubleword-aligned address.

Start segment on the next paragraph (16-byte aligned) address.

Start segment on the next page (2S6-byte aligned) address.

Start segment on the next memory page (4Kb aligned) address.

Turbo Assembler assumes the PARA alignment if you don't specify the alignment type.

If the currently selected processor is the 80386, segments can be either 16 bit or 32 bit. The segment size attribute tells the linker which of these you want for a specific segment. The following table contains the legal attribute values.

Attribute value USE16 USE32

Meaning

Segment is 16 bit. A 16-bit segment can contain up to 64K of code andbr data.

Segment is 32 bit. A 32-bit segment can contain up to 4 gigabytes of code andbr data.

Segment access attribute

Table 7.9 Segment access attribute

The ENDS directive

The GROUP directive

Turbo Assembler assumes the USE32 value if you selected the 80386 processor in MASM mode. In Ideal mode, Turbo Assembler assumes USE16 by default.

For any segment in protected mode, you can control access so that certain kinds of memory operations are not permitted. (Note that this feature is currently supported only by the Phar Lap linker. You must generate object code compatible with it using the lop switch if you want to be able to use the segment access attribute.) The segment access attribute tells the linker to apply specific access restrictions to a segment.

The following table lists the legal values for this attribute.

Attribute value EXECONLY EXECREAD READONLY READWRITE

Meaning

the segment is executable only the segment is readable and executable the segment is readable only

the 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. Turbo Assembler assumes the READONL Y attribute if you selected the USE32 attribute but did not specify any of these four attributes.

You can use the ENDS directive to close a segment so that no further data is emitted into it. You should use the ENDS directive to close any segments opened with the SEGMENT directive. Segments opened using the simplified segment directives don't require the ENDS directive.

Here's the syntax of the ENDS directive:

ENDS [name]

For MASM mode only, you can use the following syntax:

name ENDS

name specifies the name of the segment to be closed. Turbo Assembler will report an error message if name doesn't agree with the segment currently open. If you don't specify a name, Turbo Assembler assumes the currently-open segment.

You can use the GROUP directive to assign segments to groups. A group lets you specify a single segment value to access data in all segments in the group.

Here's the Ideal mode syntax for the GROUP directive:

GROUP name segment_name [, segment_name ... ]

You can use the following syntax for MASM mode:

name GROUP segment_name [, segment_name ... ]

name is the name of the group. segment_name is the name of a segment yo~ want to assign to that group.

Im Dokument . TUrbo Assembler" (Seite 107-111)