• Keine Ergebnisse gefunden

The ASSUME directive

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

A segment register must be loaded with the correct segment value for you to access data in a segment. Often, you must do this yourself. For example, you could use the following code to load the address of the current far data segment into DS:

MOV A:i.,@fardata MOV D8,AX

When a program loads a segment value into a segment register, you use that segment register to access data in the segment. It rapidly becomes tiring (and is also poor programming practice) to specify a specific segment register every time you process data in memory.

- . . Use the ASSUME directive to tell Turbo Assembler to associate a segment register with a segment or group name. This allows Turbo Assembler to be

"smart enough" to use the correct segment registers when data is accessed.

In fact, Turbo Assembler uses the information about the association between the segment registers and group or segment names for another purpose as well: in MASM mode, the value that the CS register is

ASSUMEd to be is used to determine the segment or group a label belongs to. Thus, the CS register must be correctly specified in an ASSUME

directive, or Turbo Assembler will report errors every time you define a label or procedure.

Here's the syntax of the ASSUME directive:

ASSUME segreg : expression [,segreg : expression]

Segment ordering or

ASSUME NOTHING

segreg is one of CS, DS, ES or SS registers. If you specify the 80386 or 80486 processor, you can also use the FS and GS segment registers. expression can be any expression that evaluates to a group or segment name.

Alternatively, it can be the keyword NOTHING. The NOTHING keyword cancels the association between the designated segment register and any segment or group name.

ASSUME NOTHING removes associations between all segment registers and segment or group names.

You can use the ASSUME directive whenever you modify a segment register, or at the start of a procedure to specify the assumptions at that point. In practice, ASSUMEs are usually used at the beginning of a module and occasionally within it. If you use the MODEL statement, Turbo

Assembler automatically sets up the initial ASSUMEs for you.

If you don't specify a segment in an ASSUME directive, its ASSUMEd value is not changed.

For example, the following code shows how you can load the current initialized far data segment into the DS register, access memory in that segment, and restore the DS register to the data segment value.

MOV lJ...,@fardata MOV DS,lJ...

ASSUME DS:@fardata MOV BX,<far_data_variable>

MOV lJ...,@data MOV DS,lJ...

ASSUME DS:@data

The linker arranges and locates all segments defined in a program's modules. Generally, the linker starts with the order in which it encounters the segments in a program's modules. You can alter this order using mechanisms such as segment combination and segment classing.

There are other ways to affect the way the linker arranges segments in the final program. For example, the order in which segments appear in a module's source can be changed. There are also directives that affect segment ordering. Descriptions of these follow.

Changing a modules segment ordering

DOS ordering of segments: the DOSSEG directive

-The order of segments in each module determines the starting point for the linker's location of segments in the program. In MASM 1.0, 2.0, and 3.0, segments were passed to the linker in alphabetical order. Turbo Assembler provides directives (in MASM mode only) that let you reproduce this behavior.

Note that these directives have the same function as the IA and IS command line switches. See Chapter 2 for further details.

The .ALPHA directive

The .ALPHA directive specifies alphabetic segment ordering. This directive tells Turbo Assembler to place segments in the object file in alphabetical order (according to the segment name). Its syntax is

. ALPHA

The .SEQ directive

The .SEQ directive specifies sequential segment ordering, and tells Turbo Assembler to place segments in the object file in the order in which they were encountered in the source file. Since this is the default behavior of the assembler, you should usually use the .SEQ directive only to override a previous .ALPHA or a command line switch. Here's the syntax of .SEQ:

.SEQ

Normally, the linker arranges segments in the sequential order it

encounters them during the generation of the program. When you include a DOSSEG directive in any module in a program, it instructs the linker to use standard DOS segment ordering instead. The linker defines this convention to mean the following arrangement of segments in the final program:

• segments having the class name CODE (typically code segments)

• segments that do not have class name CODE and are not part of DGROUP

• segments that are part of DGROUP in the following order:

1. segments not of class BSS or STACK (typically initialized data) 2. segments of class BSS (typically uninitialized data)

3. segments of class STACK (stack space)

Changing the size of the stack

Table 7.10 Stack size modification directives

The segments within DGROUP are located in the orderin which they were defined in the source modules.

DOSSEG is included in TASM for backward compatibility only. It is recommended that you do not use the DOSSEG directive in new assembly programs. In addition, do not use the DOSSEG directive if you're

interfacing assembly programs with C programs.

A procedure's prolog and epilog code manipulates registers that point into the stack. On the 80386 or 80486 processor, the stack segment can be either 16 bits or 32 bits. Turbo Assembler therefore must know the correct size of the stack before it can generate correct prolog and epilog code for a procedure.

The stack size is automatically selected if you selected a standard model using the MODEL statement.

Turbo Assembler provides directives that can set or override the default stack size for procedure prolog and epilog generation. The following table lists these directives.

Directive SMALLSTACK LARGESTACK

Meaning

Indicates that the stack is 16 bit Indicates that the stack is 32 bit

c

H A p T E R

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