• Aucun résultat trouvé

The special macro operators

Dans le document Turbo AssemblefB> (Page 55-61)

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 list 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.

& Ideal, MASM

Function Substitute operator Syntax & name

Remarks name is the value of the actual parameter in the macro invocation or repeat block. In many situations, parameter substitution is automatic, and you don't have to use this opera tor. You mus t use this opera tor 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.

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

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

it expands to

MSG9 DB 'Enter a value: '

<>

<> Ideal, MASM

Function Literal text string operator Syntax <text>

Remarks 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 semicolon (;) 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.

Example 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 VALS:

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.

Ideal, MASM

Function Quoted character opera tor Syntax ! character

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

Example MAKEMSG MACRO StrDef,NUM

MSG & NUM DB '&StrDef' ENDM

MAKEMSG <Can't enter !> 99>

In this example, the argument would have been prematurely terminated if the I operator had not been used.

% Ideal, MASM

I I

Function Expression evaluate operator Syntax % expression

Remarks 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 evaluated 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 expression 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 DEFSYM MACRO NUM

???&NUM:

Function Syntax Remarks

ENDM DEFSYM %5+4

results in the following code label definition:

???9:

Ideal, MASM

Suppressed comment

;;text

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.

Example SETBYTES MACRO VarName, val

VarName DB 10 DUP (val) ;;this 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, specifying the format 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, %L1ST.

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, however, 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 .LlST and .XLlST, you use %LlST 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.

Dans le document Turbo AssemblefB> (Page 55-61)

Documents relatifs