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

88

Chapter 3. Writing Assembly Programs

 

 

Operators

The Ax51 assembler provides several classes of operators that allow you to compare and combine operands and expressions. These operators are described in the sections that follow.

Arithmetic Operators

Arithmetic operators perform arithmetic functions like addition, subtraction, multiplication, and division. These operators require one or two operands depending on the operation. The result is always a 16-bit value. Overflow and

3 underflow conditions are not detected. Division by zero is detected and causes an assembler error.

Operator

Syntax

 

 

Description

+

+ expression

 

Unary plus sign

expression

 

Unary minus sign

+

expression

+

expression

Addition

expression

expression

Subtraction

*

expression

*

expression

Multiplication

/

expression

/

expression

Integer division

MOD

expression

MOD expression

Remainder

( and )

(expression)

 

Specify order of execution

Binary Operators

Binary operators are used to complement, shift, and perform bit–wise operations on the binary value of their operands.

Operator

Syntax

 

 

Description

NOT

NOT expression

 

Bit–wise complement

SHR

expression

SHR

count

Shift right

SHL

expression

SHL

count

Shift left

AND

expression

AND expression

Bit–wise AND

OR

expression

OR expression

Bit–wise OR

XOR

expression

XOR expression

Bit–wise exclusive OR

Shaded directives and options are available only in AX51 and A251.

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

89

 

 

Relational Operators

The relational operators compare two operands. The result of the comparison is a TRUE or FALSE. A FALSE result has a value of 0000h. A TRUE result has a non–zero value.

The following table lists the relational operators and provides a brief description of each.

 

Operator

Syntax

 

 

 

 

Result

 

 

 

 

 

GTE

expression1

GTE

expression2

True if

expression1

is greater than or equal to

 

 

 

3

 

 

 

 

 

 

 

expression2

 

 

 

 

LTE

expression1

LTE

expression2

True if

expression1

is less than or equal to

 

 

 

 

 

 

 

 

expression2

 

 

 

 

NE

expression1

NE

expression2

True if

expression1

is not equal to expression2

 

 

 

EQ

expression1

EQ

expression2

True if

expression1

is equal to

expression2

 

 

 

LT

expression1

LT

expression2

True if

expression1

is less than

expression2

 

 

 

GT

expression1

GT

expression2

True if

expression1

is greater than expression2

 

 

 

>=

expression1

>=

expression2

True if

expression1

is greater than or equal to

 

 

 

 

 

 

 

 

 

expression2

 

 

 

 

 

<=

expression1

<=

expression2

True if

expression1

is less than or equal to

 

 

 

 

 

 

 

 

 

expression2

 

 

 

 

 

<>

expression1

<>

expression2

True if

expression1

is not equal to expression2

 

 

 

=

expression1

=

expression2

True if

expression1

is equal to

expression2

 

 

 

<

expression1

<

expression2

True if

expression1

is less than

expression2

 

 

 

>

expression1

>

expression2

True if

expression1

is greater than expression2

 

 

Shaded directives and options are available only in AX51 and A251.

90

Chapter 3. Writing Assembly Programs

 

 

Class Operators

The class operator assigns a memory class to an expression. This is how you associate an expression with a class. The Ax51 assembler generates an error message if you use an expression with a class on an instruction which does not support this class, for example, when you use an XDATA expression as a direct address.

The following table lists the class operators and provides a brief description of each.

3

 

Operator

Syntax

Description

 

 

BIT

BIT expression

Assigns the class BIT to the expression.

 

 

CODE

CODE expression

Assigns the class CODE to the expression.

 

 

 

CONST

CONST expression

Assigns the class CONST to the expression.

 

 

 

 

 

DATA

DATA expression

Assigns the class DATA to the expression.

 

 

 

EBIT

EBIT expression

Assigns the class EBIT to the expression.

 

 

 

ECODE

ECODE expression

Assigns the class ECODE to the expression.

 

 

 

ECONST

ECONST expression

Assigns the class ECONST to the expression.

 

 

 

EDATA

EDATA expression

Assigns the class EDATA to the expression.

 

 

 

IDATA

IDATA expression

Assigns the class IDATA to the expression.

 

 

 

 

 

 

 

 

 

HCONST

HCONST expression

Assigns the class HCONST to the expression.

 

 

 

HDATA

HDATA expression

Assigns the class HDATA to the expression.

 

 

 

XDATA

XDATA expression

Assigns the class XDATA to the expression.

 

Type Operators

The type operator assigns a data type to an expression. The A251 assembler generates an error if you attempt to use an instruction with the incorrect data type. For example, this happens when you use a WORD expression as an argument in a byte-wide instruction of the 251.

Operator

Syntax

Description

BYTE

BYTE expression

Assigns the type BYTE to the expression.

WORD

WORD expression

Assigns the class WORD to the expression.

DWORD

DWORD expression

Assigns the class DWORD to the expression.

NEAR

NEAR expression

Assigns the class NEAR to the expression.

FAR

FAR expression

Assigns the class FAR to the expression.

Shaded directives and options are available only in AX51 and A251.

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

91

 

 

Miscellaneous Operators

Ax51 provides operators that do not fall into the previously listed categories. These operators are listed and described in the following table.

Operator

Syntax

 

Description

 

 

 

LOW

LOW

expression

Low–order byte of expression

 

 

 

HIGH

HIGH

expression

High–order byte of expression

 

 

 

BYTE0

BYTE0

expression

Byte 0 of expression. See table below. (identical

 

 

 

 

 

 

 

with LOW).

 

 

 

BYTE1

BYTE1

expression

Byte 1 of expression. See table below. (identical

 

 

 

 

 

 

 

 

with HIGH).

 

 

3

BYTE2

BYTE2

expression

Byte 2 of expression. See table below.

 

BYTE3

BYTE3

expression

Byte 3 of expression. See table below.

 

WORD0

WORD0 expression

Word 0 of expression. See table below.

 

 

WORD2

WORD2 expression

Word2 of expression. See table below.

 

 

MBYTE

MBYTE

expression

AX51 only: memory type information for C51

 

 

 

 

 

 

 

run-time libraries. Returns the memory type that

 

 

 

 

 

 

 

is used in the C51 run-time library to access

 

 

 

 

 

 

 

variables defined with the far memory type.

 

 

The following table shows how the byte and word operators impact a 32-bit

 

value.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

MSB

 

 

 

 

 

 

LSB

 

 

BYTE3

 

 

 

BYTE2

BYTE1

 

BYTE0

 

 

 

WORD2

 

WORD0

 

 

 

 

 

 

 

 

HIGH

 

LOW

 

 

The following table shows how the byte and word operators impact a 32-bit value.

Shaded directives and options are available only in AX51 and A251.

92

Chapter 3. Writing Assembly Programs

 

 

Operator Precedence

All operators are evaluated in a certain, well–defined order. This order of evaluation is referred to as operator precedence. Operator precedence is required in order to determine which operators are evaluated first in an expression. The following table lists the operators in the order of evaluation. Operators at level 1 are evaluated first. If there is more than one operator on a given level, the leftmost operator is evaluated first followed by each subsequent operator on that level.

 

 

Level

Operators

 

3

 

 

1

( )

 

 

2

NOT, HIGH, LOW, BYTE0, BYTE1, BYTE2, BYTE3, WORD0, WORD2

 

 

3

BIT, CODE, CONST, DATA, EBIT, EDATA, ECONST, ECODE, HCONST,

 

 

 

 

HDATA, IDATA, XDATA

 

 

 

 

 

 

 

4

BYTE, WORD, DWORD, NEAR, FAR

 

 

 

5

+ (unary), – (unary)

 

 

 

6

*, /, MOD

 

 

 

7

+, –

 

 

 

8

SHR, SHL

 

 

 

9

AND, OR, XOR

 

 

 

10

>=, <=, =, <>, <, >, GTE, LTE, EQ, NE, LT, GT

 

Shaded directives and options are available only in AX51 and A251.

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