Language Elements

BASIC-SO

Logical Operators

The logical operators NOT, AND, OR, XOR, IMP, and EQV are operators that compare the nth bit of argument X with the nth bit of argument Y. They are evaluated after the arithmetic and relational operators; therefore, arithmetic expres- sions resolve to a number which is compared with another number. A relational operator test can be used with logical operations. If there are two logical operators of the same precedence in a single expression, they are evaluated left to right. Table 2-6 lists the logical operators in order of precedence'. Some examples of the logical operators, used in complex expressions, are shown below.

IF A>=3.5X OR X > 3 THEN 01=0

IF B=1 OR B=2 OR B=3 THEN 2750 ELSE 280u

IF (A-B) AND (B+3) THEN STOP ELSE IF (A AND B) THEN CLOSE 2

String Operator

The relational operators may be used with strings to compare them according to ASCII order. If strings of unequal length are compared, and the shorter is identical to the first part of the longer, then the longer is greater. There is one operator only used with strings: the concatenation operator (+). This operator defines a string as two or more strings joined together.

A$ = B$+C$

Expressions

Except for the command and stateqlent instructions, all of the language elements previously discussed can be combined to form expressions. Depending on the type of constants, variables, and operators used, expressions can be classed as numeric or string.

Numeric Expressions

In BASIC-80, numeric expressions are created with numeric variables, constants, functions, and operators. Variables are initialized with 0, and may be assigned other values with assignment statements, or with INPUT statements during program execution.

Any function which returns a numeric value can be used in a numeric expression. Strings can only be used if they are converted to a number. Numeric expressions can use arithmetic, logical, or relational operators. Some numeric expressions:

K(I) = B*SOR(X)

IF A>12.1 THEN C = C + 1

IF PEEK (2FFFH) AND OCH THEN PRINT "ON"

String Expressions

String expressions can be specified in BASIC-80 using string constants, string variables, relational operators, and the concatenation operator (+). The concatena- tion operator combines two strings into one. If the resulting string is longer than 255 characters, execution halts and an error message is displayed. Some string expres- sions are:

A$ = "NAME:" + NAME$

IF B1$>R$ THEN 81$ = ""

R$(I)=R$(I) + S$(I) + "DONE"

2-12

Page 22
Image 22
Intel 9800758-02 manual Logical Operators, String Operator, Numeric Expressions, String Expressions