• Keine Ergebnisse gefunden

RASM-86 Code-macro Facilities

Im Dokument FlexOS 286 (Seite 127-132)

FSUB80P byte ptr my_var: sub and pop temp real

SECTION 5 RASM-86 Code-macro Facilities

5.1 Introduction

RASM-86 allows you to define your own instructions using the Code-macro directive. RASM-86 code-macros differ from traditional

assembly~language macros in the following ways:

• Traditional assembly-language macros contain assembly-language instructions, but a RASM-86 macro contains only code-macro directives.

• Traditional assembly-language macros are usually defined in the Symbol Table, while RASM-86 code-macros are defined in the assembler's internal Symbol Table.

• A traditional macro simplifies the repeated use of the same block of instructions throughout a program, but a code-macro sends a bit stream to the output file, and in effect, adds a new instruction to the assembler.

5.2 Invoking Code-macros

RASM-86 treats a code-macro as an instruction, so you can invoke code-macros by using them as instructions in your program. The following example shows how to invoke MYCODE, an instruction defined by a code-macro.

MYCODE PARM 1,PARM2

Note that MYCODE accepts two operands as formal parameters. When you define MYCODE, RASM-86 classifies these two operands according to type, size, and so forth.

t> . .:s inVOKing ~oae-macros ~rogrammers Ulllilles uUlOe 5.3 Defining Code-macros

A code-macro definition takes the general form:

CodeMacro name [formal parameter list]

[ list of code-macro directives ] EndM

where name is any string of characters you select to represent the code-macro. The optional formal parameter and code-macro directive lists are described in the following sections. Example code-macro definitions are provided in Section 5.3.3

5.3.1 Formal Parameter List

When you define a code macro, you can specify one or more optional formal parameter lists. The parameters specified in the formal parameter list are used as placeholders to indicate where and how the operands are to be used. The formal parameter list is created using the following syntax:

formal_name : specifier_letter [ modifier_letter] [ range]

formal name

You can specify any formal name to represent the formal parameters in your list. RASM-86 replaces the formal_names with the names or values supplied as operands when you invoke the code-macro.

specifier _letter

Every formal parameter must have a specifier letter to indicate what type of operand is needed to match the formal parameter. Table 5-1 defines the eight possible specifier letters.

Programmer's Utilities Guide 5.3 Defining Code-macros' Table 5-1. Code-macro Operand Specifiers

Letter Operand Type

A

C D E

M

R S X

modifier letter

Accumulator register, AX or AL.

Code, a label expression only.

Data, a number used as· an immediate value.

Effective address, either an M (memory address) or an R (register).

Memory address. This can be either" a variable or a bracketed register expression.

General register only.

Segment register only.

Direct memory reference.

The optional modifier_letter in a code-macro definition is a further requirement on the operand. The meaning of the modifier letter depends on the type of the operand. For variables, the modifier requires the operand be a certain type:

• b for byte

• w for word

• d for double-word

• sb for signed byte

For numbers, the modifiers require the number be a certain size: b for -256 to 255 and w for other numbers. Table 5-2 summarizes

code-~.~ uetlnmg L;Ode-macros I-'rogrammers UIIllIles uUlOe Table 5-2. Code-macro Operand Modifiers

Variables Numbers

Modifier b w d sb

range

Type byte word dword signed byte

Modifier Size

b -256 to 255 w anything else

The optional range in a code-macro definition is specified within parentheses by either one expression or two expressions separated by a comma. The following are valid formats:

(numberb) (register)

(numberb,numberb) (numberb,register) (register,numberb) (regi ster,reg ister)

Numberb is an a-bit number, not 'an address.

5.3.2 Code-macro Directives

Code-macro directives define the bit pattern and make further requirements on how the operand is to be treated. Directives are reserved words, and those that appear to duplicate assembly language instructions have different meanings within a code-macro definition.

Programmer's Utilities Guide 5.3 Defining Code-macros The following are legal code-macro directives:

SEGFIX NOSEGFIX MOORM RELB RELW DB OW DO OBIT IF ELSE ENOIF

These directives are unique to code-macros. The code-macro directives DB, OW, and DO that appear to duplicate the RASM-86 directives of the same names have different meanings in code-macro context. These directives are discussed in greater detail in Section.

CodeMacro, EndM, and the code-macro directives are all reserved words. The formal definition syntax for a code-macro is defined in Backus-Naur-like .!orm in Appendix E.

SEGFIX

SEGFIX instructs RASM-86 to determine whether a segment-override prefix byte is needed to access a given memory location. If so, it is output as the first byte of the instruction. If not, RASM-86 takes no action. SEGFIX has the following form:

SEGFIX formal name

The formal name is the name of a formal parameter representing the memory ad-dress. Because it represents a memory address, the formal parameter must have one of the specifiers E, M, or X.

5.3 Defining Code-macros Programmer's Utilities Guide NOSEGFIX

Use NOSEGFIX for operands in instructions that must use the ES register for that operand. This applies only to the destination operand of these instructions: CMPS, MOVS, SCAS, STOS. NOSEGFIX has the following

form:-NOSEGFIX segreg, form name

The segreg is one of the segment registers ES, CS, SS, or OS, and form_name is the name of the memory-address formal parameter that must have a specifier E, M, or X. No code is generated from this directive, but an error check is performed. The following is an example of NOSEGFIX in a code-macro directive:

CodeMacro MOVS si ptr:Ew,di ptr:Ew

NOSEGFIX ES,di ptr

Im Dokument FlexOS 286 (Seite 127-132)