Chapter 10 Writing Assembler Control Statements

Usage example

A source file that uses #if and #ifn is shown below.

DEVICE

equ

1

_TEXT

section

CODE, PUBLIC, 1

#if

DEVICE-1

 

#else

mov

0x01, D0

mov

0x02, D0

#endif

 

 

#ifn

DEVICE-1

 

#else

mov

0x03, D0

mov

0x04, D0

#endif

 

 

The assembled list file is shown below. The program first sets DEVICE to 1. Therefore the expression DEVICE-1 will be 0, so the #if directive causes line number 7 to be assembled and the #ifn directive causes line number 10 to be assembled.

 

 

 

 

 

if.lst

Page 1

 

***

PanaX Series MN1030 Cross Assembler

***

Loc

Object

 

Line

Source

 

 

 

 

=00000001

1

DEVICE

equ

1

 

 

 

 

2

 

 

 

 

 

 

 

3

_TEXT

section

CODE, PUBLIC, 1

 

 

 

4

#if

DEVICE-1

 

 

 

 

 

5X

 

mov

0x01, D0

 

 

 

6

#else

 

 

 

00000000

8002

 

7

 

mov

0x02, D0

 

 

 

8

#endif

 

 

 

 

 

 

9

#ifn

DEVICE-1

 

 

00000002

8503

 

10

 

mov

0x03, D1

 

 

 

11

#else

 

 

 

 

 

 

12X

 

mov

0x04, D1

 

 

 

13

#endif

 

 

 

194 Conditional Assembly

Page 206
Image 206
Panasonic MN1030 #else Mov 0x01, D0 0x02, D0 #endif #ifn, #else Mov 0x03, D0 0x04, D0 #endif, Mov 0x01, D0 #else