BASIC-80

Language Elements

Table 2-6.BASIC-SO Operators in Order of Precedence (Cont'd.)

Order

Operator

Example

9.Logical NOT, used to invert a given

argument.

NOT-1 =0

 

10.Logical AND, used to test if the nth bit of X

and the nth bit of Yare both on.

1ANDO=O

11.Logical OR, used to test if the nth bit of X or

Y equals 1.

150RO=15

12.Logical exclusive OR, used to test if either

 

the nth bit of X or the nth bit of Y = 1, but not

15XOR7= 8

 

both.

 

13.

Logical implication, used to test if the nth bit

OFOFOH IMP OOFFH=OFFFOH

 

of X is on, then the nth bit of Y is on.

 

 

14.Logical equivalence, used to test if the nth

bit of X equals the nth bit of Y.

OFOFH EQV.OOFFH=OFOOFH

 

Operators and Precedence of Evaluation

Complex expressions may be formed by combining constants and variables with arithmetic, logical, relational, and string operators. BASIC-SO follows an order of precedence to insure orderly and predictable evaluation when analyzing complex ex- pressions. This order of precedence may be overridden by parentheses; any elements within the parentheses are evaluated first. The numeric operators (arithmetic, logical, and relational) are listed in order of precedence in Table 2-6.

Arithmetic Operators

There are seven arithmetic operators in BASIC-SO, each performing a familiar arithmetic operation on two numeric expressions. They are evaluated before the relational or logical operators, and if two operators of equal precedence are found by BASIC-SO, they are evaluated from left to right. Table 2-6 lists the arithmetic operators in order of precedence. Some examples of arithmetic operators are:

A= 8*(C*2.49) K1=(L+M) S RS = (83* Et .S)

Relational Operators

There are six relational operators in BASIC-SO, which test relationships between two expressions and return a -1if the premise is true, a 0 if it is false. You can write in- structions to direct program execution according to either result. The relational operators are evaluated after the arithmetic operators, and if two operators with the same order of precedence are given in an expression, they are evaluated left to right. Table 2-6 lists the relational operators, and some examples are given below:

IF (A*2.2)<>8*81 THEN 220

IF INT(A1) = INT(81) THEN A=B

IF A> B THEN IF 8>(C* VA#)THEN 340

2-11

Page 21
Image 21
Intel 9800758-02 manual Arithmetic Operators, BASIC-SO Operators in Order of Precedence Contd