5 operator precedence, 6 characters and character strings – Texas Instruments MSC1210 User Manual

Page 199

Advertising
background image

Operator Precedence

16-5

8052 Assembly Language

16.5 Operator Precedence

Mathematical operators within an expression are subject to the following order
of precedence. Operators at the same “level” are evaluated left to right.

Table 16−1.Order of Precedence for Mathematical Operators

Order

Operator

1 (Highest)

( )

2

HIGH LOW

3

* / MOD SHL SHR

4

EQ NE LT LE GT GE = <> < <= > >=

5

NOT

6

AND

7 (Lowest)

OR XOR

Note:

If you have any doubts about operator precedence, it is useful to use paren-
theses to force the order of evaluation that you have contemplated. It is often
easier to read mathematical expressions when parentheses have been add-
ed, although the parentheses are not technically necessary.

16.6 Characters and Character Strings

Characters and character strings are enclosed in single quotes and are con-
verted to their numeric equivalent at assemble time. For example, the follow-
ing two instructions are the same:

MOV A,#’C’

MOV A,#43H

The two instructions are the same because the assembler will see the ‘C’ se-
quence, convert the character contained in quotes to its ASCII equivalent
(43

H

), and use that value. Thus, the second instruction is the same as the first.

Strings of characters are sometimes enclosed in single quotes and sometimes
enclosed in double quotes. For example, Pinnacle 52 uses double quotes to
indicate a string of characters and a single quote to indicate a single character.
Thus:

MOV

A,#’C’

;Single character – ok

MOV

A,#”STRING” ;String

ERROR!

Can’t

load

a

string

into

the

;accumulator

Strings are invalid in the above context, although there are other special as-
sembler directives that do allow strings. Be sure to check the manual for your
assembler to determine whether character strings should be placed within
single quotes or double quotes.

Advertising