Chapter 10 Writing Assembler Control Statements

Usage example

A source file that uses #ifdef and #ifndef is shown below.

#define

VERSION

 

_TEXT

section

CODE, PUBLIC,1

#ifdef

VERSION

 

#else

mov

0x01, D0

mov

0x02, D0

#endif

 

 

#ifndef

VERSION

 

#else

mov

0x03, D1

mov

0x04, D1

#endif

 

 

The assembled list file is shown below.

 

 

 

 

ifdef.lst

Page 1

 

 

***

PanaX Series MN1030 Cross Assembler

**

Loc

Object

Line

Source

 

 

 

 

 

1

#define

VERSION

 

 

 

 

2

 

 

 

 

 

 

3

_TEXT

section

CODE, PUBLIC, 1

 

 

4

#ifdef

VERSION

 

 

00000000

8001

5

 

mov

0x01, D0

 

 

6

#else

 

 

 

 

 

7x

 

mov

0x02, D0

 

 

8

#endif

 

 

 

 

 

9

#ifndef

VERSION

 

 

 

 

10X

 

mov

0x03, D1

 

 

11

#else

 

 

 

00000002

8504

12

 

mov

0x04, D1

 

 

13

#endif

 

 

 

The identifier VERSION is defined in line number 1. The replacement string is a null character. Since VERSION has been defined, the #ifdef starting from line number 4 will assemble block 1 (line number 5 here), and will not assemble block 2 (shown as line number X).

The #ifndef directive inverts the condition, so block 2 (line number 12) will be assembled.

192 Conditional Assembly

Page 204
Image 204
Panasonic MN1030 #else Mov 0x01, D0 0x02, D0 #endif #ifndef, #else Mov 0x03, D1 0x04, D1 #endif, 10X Mov 0x03, D1 #else