• Aucun résultat trouvé

You use the special macro operators when calling macros and within macro and repeat-block definitions. You can also use them with the arguments to conditional assembly directives.

Here's a brief summary of the special macro operators:

&

<>

!

%

Substitute operator

"

Literal text string operator Quoted character operator Expression evaluate operator Suppressed comment

The operators let you modify symbol names and individual characters so that you can either remove special meaning from a character or determine when an argument gets evaluated.

&

Function Mode Syntax Remarks

Example

Substitute operator MASM,Ideal

&name

name is the value of the actual parameter in the macro invocation or repeat block. In many situations, param-eter substitution is automatic, and you don't have to use this operator. You must use this operator when you wish substitution to take place inside a quoted character string, or when you want to "paste" together a symbol from one or more parameters and some fixed characters.

In this case, the & prevents the characters from being interpreted as a single name.

MAKEMSG MACRO StrDef,NUM MSG & NUM DB '&StrDef' ENDM

If you call this macro with MAKEMSG 9,<Enter a value: >

it will expand to

MSG9 DB 'Enter a value: '

<>

Function Mode Syntax Remarks

Example

Literal text string operator MASM, Ideal

<text>

text is treated as a single macro or repeat parameter, even if it contains commas, spaces, or tabs that usually separate each parameter. Use this operator when you want to pass an argument that contains any of these separator characters.

You can also use this operator to force Turbo Assembler to treat a character literally, without giving it any special meaning. For example, it you wanted to pass a semi-colon (;) as a parameter to a macro invocation, you would have to enclose it in angle brackets «;» to prevent it from being treated as the start of a comment.

Turbo Assembler removes the outside set of angle brackets each time a parameter is passed during the invocation of a macro. To pass a parameter down through several levels of macro expansion, you must supply one set of angle brackets for each level.

MANYDB MACRO VALS IRP X, <VALS>

ENDM ENDM

When calling this macro, you must enclose multiple values in angle brackets so they get treated as the single parameter V ALS:

MANYDB <4,6,0,8>

The IRP repeat directive still has angle brackets around the parameter name because the set of brackets around the parameter are stripped when the macro is called.

, .

Function Mode Syntax Remarks

Example

%

Function Mode Syntax Remarks

Quoted character opera tor MASM, Ideal

! character

The! operator lets you call macros with arguments that contain special macro operator characters. This is some-what equivalent to enclosing the character in angle brackets. For example,!& is the same as <&>.

MAKEMSG MACRO StrDef,NUM MSG & NUM DB '&StrDef' ENDM

MAKEMSG <Can't enter !> 99>

In this example, the argument would have been pre-maturely terminatedif the! operator had not been used.

Expression evaluate operator MASM,Ideal

% expressi on

expression can be either a numeric expression using any of the operands and operators described in this chapter or it can be a text equate. If it is a numeric expression, the string that is passed as a parameter to the macro invocation is the result of evaluating the expression. If expression is a text equate, the string passed is the text of the text equate. The evalua ted expression will be represented as a numerical string in the current RADIX.

Use this operator when you want to pass the string representing a calculated result, rather than the expres-sion itself, to a macro. Also, a text macro name can be specified after the %, causing a full substitution of the text macro body for the macro argument.

Example

11

Function Mode Syntax Remarks

Example

DEFSYM MACRO NUM

???&NUM:

ENDM DEFSYM %5+4

results in the following code label definition:

???9:

Suppressed comment MASM,Ideal

iitext

Turbo Assembler ignores all text following the double semicolon (;;). Normal comments are stored as part of the macro definition and appear in the listing any time the macro is expanded. Comments that start with a double semicolon (;;) are not stored as part of the macro definition. This saves memory, particularly if you have a lot of macros that contain a lot of comments.

SETBYTES MACRO VarName,val

VarName DB 10 DUP (val) iithis comment doesn't get saved ENDM

c

H A p T E R

3

Directives

A source statement can either be an instruction or a directive. An instruction source line generates object code for the processor operation specified by the instruction mnemonic and its operands. A directive source line tells the assembler to do something unrelated to instruction generation, including defining and allocating data and data structures, defining macros, speci-fying the fonnat of the listing file, controlling conditional assembly, and selecting the processor type and instruction set.

Some directives define a symbol whose name you supply as part of the source line. These include, for example, SEGMENT, LABEL, and GROUP.

Others change the behavior of the assembler but do not result in a symbol being defined, for example, ORG, IF, %LIST.

The directives presented here appear in alphabetical order (excluding punctuation); for example, .CODE appears just before CODESEG.

The reserved keywords %TOC and %NOTOC do not perform any operation in the current version of Turbo Assembler. Future versions will use these keywords, so you should avoid using them as symbols in your programs.

The directives fall into three categories:

1. The MASM-style directives: Turbo Assembler supports all MASM-style directives. When you use Turbo Assembler in Ideal mode, the syntax of some of these directives changes. For these directives, the description notes the syntax for both modes.

2. The new Turbo Assembler directives: These directives provide added functionality beyond that provided by MASM.

3. Turbo Assembler directives that are synonyms for existing MASM directives: These synonyms provide a more organized alternative to some existing MASM directives. For example, rather than .LIST and .XLIST, you use %LIST and %NOLIST. As a rule, all paired directives that enable and disable an option have the form xxxx and NOxxxx. The synonyms also avoid using a period (.}as the first character of the directive name. The MASM directives that start with a period are not available in Turbo Assembler's Ideal mode, so you must use the new synonyms instead.

All Turbo Assembler directives that control the listing file start with the percent (%) character.

In the syntax section of each entry, the following typographical conventions are used:

• Brackets ([]) indicate optional arguments (you do not need to type in the brackets) .

.. Ellipses ( ... ) indicate that the previous item may be repeated as many times as desired .

• Items in italics are placeholders that you replace with actual symbols and expressions in your program.

Documents relatifs