06.02.2013 Views

C166/ST10 Cross-Assembler, Linker/Locator, Utilities ... - Tasking

C166/ST10 Cross-Assembler, Linker/Locator, Utilities ... - Tasking

C166/ST10 Cross-Assembler, Linker/Locator, Utilities ... - Tasking

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2−72<br />

MACRO PREPROCESSOR<br />

Chapter 2<br />

2.7.8 ALGORITHM FOR EVALUATING MACRO CALLS<br />

The algorithm of the macro preprocessor used for evaluating the source<br />

file can be broken down into 6 steps:<br />

1. Scan the input until the ’@’ character is found.<br />

2. Isolate the macro−name.<br />

3. If macro has parameters, expand each parameter from left to right (initiate<br />

step one for actual parameter) before expanding the next parameter.<br />

4. Substitute actual parameters for formal parameters in macro−body.<br />

5. If the literal character is not used, initiate step one on macro−body.<br />

6. Insert the result into output stream.<br />

The terms ’input stream’ and ’output stream’ are used because the return<br />

value of one macro may be a parameter to another. On the first iteration,<br />

the input stream is the source line. On the final iteration, the output stream<br />

is passed to the assembler.<br />

Example:<br />

The examples below illustrate the macro preprocessor’s evaluation<br />

algorithm:<br />

@SET( TOM, 3 )<br />

@*DEFINE STEVE ()<br />

@SET( TOM, @TOM −1 ) @TOM<br />

@ENDD<br />

@DEFINE ADAM( A, B )<br />

DB @A, @B, @A, @B, @A, @B<br />

@ENDD<br />

The call ADAM is presented here in the normal mode with TOM as the<br />

first actual parameter and STEVE as the second actual parameter. The first<br />

parameter is completely expanded before the second parameter is<br />

expanded. After the call to ADAM has been completely expanded, TOM<br />

will have the value 02h.<br />

Before Macro Expansion After Macro Expansion<br />

@ADAM( @TOM, @STEVE ) −> DB 03h, 02h, 03h, 02h, 03h, 02h

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!