Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
74
Добавлен:
14.04.2015
Размер:
2.03 Mб
Скачать

228

Chapter 7. Invocation and Controls

 

 

Controls for Conditional Assembly

The controls for conditional assembly are General controls—they may be specified any number of times in the body of a source file. Conditional assembly may be used to implement different program versions or different memory models with one source file. You may use conditional assembly to maintain one source module that satisfies several applications.

Conditional text blocks are enclosed by IF, ELSEIF, ELSE and ENDIF.

The SET and RESET controls may be used in the invocation line of the assembler to set and reset conditions tested by the IF and ELSEIF controls.

The remaining instructions for conditional assembly are only allowed within the source file and cannot be part of the assembler invocation line.

IF blocks may be nested a maximum of 10 levels deep. If a block is not translated, conditional blocks nested within it are also skipped.

7

Keil Software — A51/AX51/A251 Macro Assembler and Utilities

229

 

 

Conditional Assembly Controls

Conditional assembly controls allow you to write x51 assembly programs with sections that can be included or excluded from the assembly based on the value of a constant expression. Blocks that are conditionally assembled are enclosed by IF, ELSEIF, ELSE, and ENDIF control statements.

The conditional control statements IF, ELSE, ELSEIF, and ENDIF may be specified only in the source program. They are not allowed on the invocation line. Additionally, these controls may be specified both with and without the leading dollar sign ($).

When prefixed with a dollar sign, the conditional control statements may only access symbols defined by the SET and RESET controls.

When specified without a dollar sign, the conditional control statements may access all symbols except those defined by the SET and RESET controls. These control statements may access parameters in a macro definition.

The following table lists the conditional assembly control statements.

Directive

Page

Description

IF

233

Translate block if condition is true

ELSE

235

Translate block if the condition of a previous IF is false.

ELSEIF

234

Translate block if condition is true and a previous IF or ELSEIF is

 

 

false.

ENDIF

236

Marks end of a block.

RESET

232

Set symbols checked by IF or ELSEIF to false.

SET

231

Set symbols checked by IF or ELSEIF to true or to a specified

 

 

value.

7

230

Chapter 7. Invocation and Controls

 

 

Predefined Constants (A251 only)

The A251 macro assembler provides you with predefined constants to use in conditional $IF / $ELSEIF controls for more portable assembler modules. The following table lists and describes each one.

Constant

Description

_ _INTR4_ _

Set to 1 to when A251 assumes 4 byte interrupt frames. If the A251 control

 

INTR2 is used, the _ _INTR4_ _ symbol is not defined.

_ _MODBIN_ _

Set to 1 if the binary mode of 251 CPU is used. If the source mode is

 

specified with the MODSRC control, the _ _MODBIN_ _ symbol is not

 

defined.

_ _MODSRC_ _

Set to 1 if the source mode of 251 CPU is specified with the MODSRC

 

control. If the binary mode of the 251 CPU is used the _ _MODSRC_ _

 

symbol is not defined.

 

 

7

Keil Software — A51/AX51/A251 Macro Assembler and Utilities

231

 

 

SET

Abbreviation:

None.

Arguments:

A list of symbols with optional value assignments separated

 

by commas and enclosed within parentheses. For example:

 

SET (symbol = number , symbol = number … )

Default:

None.

Control Class:

General

µVision2 Control:

Options – Ax51 – Set.

Description:

The SET control assigns numeric values to the specified

 

symbols. Symbols that do not include an explicit value

 

assignment are assigned the value 0FFFFh. Symbols that

 

are specified with an equal sign (‘=’) and a numeric value

 

are assigned the specified value.

 

These symbols can be used in IF and ELSEIF control

 

statements for conditional assembly. They are only used for

 

conditional assembly. These symbols are administered

 

separately and do not interfere with other symbols.

Example:

 

A251 SAMPLE.A51 SET(DEBUG1=1, DEBUG2=0, DEBUG3=1)

 

 

$SET (TESTCODE = 0)

 

$SET (DEBUGCODE, PRINTCODE)

7

232 Chapter 7. Invocation and Controls

RESET

Abbreviation:

None.

Arguments:

A list of symbols separated by commas and enclosed within

 

parentheses. For example:

 

RESET (symbol , symbol … )

Default:

None

Control Class:

General

µVision2 Control:

Options – Ax51 – Reset.

Description:

The RESET control assigns a value of 0000h to the

 

specified symbols. These symbols may then be used in IF

 

and ELSEIF control statements for conditional assembly.

 

These symbols are only used for conditional assembly.

 

They are administered separately and do not interfere with

 

other symbols.

Example:

 

A251 SAMPLE.A51 RESET(DEBUG1, DEBUG2, DEBUG3)

 

 

$RESET (TESTCODE)

 

$RESET (DEBUGCODE, PRINTCODE)

7

Keil Software — A51/AX51/A251 Macro Assembler and Utilities

233

 

 

IF

Abbreviation:

None

 

Arguments:

A numeric expression

Default:

None

 

Control Class:

General

 

µVision2 Control:

This control cannot be specified on the command line.

Description:

The IF control begins an IFELSEENDIF construct that

 

is used for conditional assembly. The specified numeric

 

expression is evaluated and, if it is non–zero (TRUE), the IF

 

block is assembled. If the expression is zero (FALSE), the

 

IF block is not assembled and subsequent blocks of the IF

 

construct are evaluated.

 

IF blocks can be terminated by an ELSE, ELSEIF, or

 

ENDIF control statement.

Example:

.

 

 

 

 

.

 

 

.

 

 

$IF (DEBUG_VAR = 3)

 

.

 

 

.

 

 

.

 

 

Version_3:

MOV DPTR, #TABLE_3

 

.

 

.

 

.

 

$ ENDIF

 

.

 

.

7

.

 

234 Chapter 7. Invocation and Controls

ELSEIF

Abbreviation:

None

Arguments:

A numeric expression.

Default:

None

µVision2 Control: This control cannot be specified on the command line.

Description: The ELSEIF control is used to introduce an alternative program block after an IF or ELSEIF control. The ELSEIF block is only assembled if the specified numeric expression is non–zero (TRUE) and if previous IF and ELSEIF conditions in the IFELSEENDIF construct were FALSE. ELSEIF blocks are terminated by an

ELSEIF, ELSE, or ENDIF control.

Example:

7

.

 

.

 

.

 

$IF SWITCH = 1

; Assemble if switch is 1

.

 

.

 

.

 

$ELSEIF SWITCH = 2

; Assemble if switch is 2

.

 

.

 

.

 

$ELSEIF SWITCH = 3

; Assemble if switch is 3

.

 

.

 

.

 

$ENDIF

 

.

 

.

 

.

 

Keil Software — A51/AX51/A251 Macro Assembler and Utilities

235

 

 

ELSE

Abbreviation:

None.

 

Arguments:

None.

 

Default:

None.

 

Control Class:

General

 

µVision2 Control:

This control cannot be specified on the command line.

Description:

The ELSE control is used to introduce an alternative

 

program block after an IF or ELSEIF control. The ELSE

 

block is only assembled if previous IF and ELSEIF

 

conditions in the IFELSEENDIF construct were all

 

FALSE. ELSE blocks are terminated with an ENDIF

 

control.

 

Example:

.

 

 

 

 

.

 

 

.

 

 

$IF (DEBUG)

; TRUE when DEBUG <> 1

 

.

 

 

.

 

 

.

 

 

$ELSEIF (TEST)

 

 

.

 

.

.

$ELSE

.

.

.

$ENDIF

.

.

.

7

 

236 Chapter 7. Invocation and Controls

ENDIF

Abbreviation:

None

Arguments:

None

Default:

None

Control Class:

General

µVision2 Control:

This control cannot be specified on the command line.

Description:

The ENDIF control terminates an IFELSEENDIF

 

construct. When the Ax51 assembler encounters an ENDIF

 

control statement, it concludes processing the IF block and

 

resumes assembly at the point of the IF block. Since IF

 

blocks may be nested, this may involve continuing in

 

another IF block. The ENDIF control must be preceded by

 

an IF, ELSEIF, or ELSE control block.

Example:

 

.

.

 

 

.

 

$IF TEST

 

.

 

.

 

.

 

$ENDIF

 

.

 

.

 

.

7

Соседние файлы в папке HLP