šHca.geocities.com/JLABELLE@rogers.com/nsasm/docs/x381.htmlca.geocities.com/JLABELLE_rogers.com/nsasm/docs/x381.htmldelayedxHnÕJ˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙ČĄ¬¸ XOKtext/htmlPS´' X˙˙˙˙b‰.HTue, 07 Dec 2004 00:52:50 GMTRMozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)en, *HnÕJ Xoperand expression evaluation

operand expression evaluation

The expression evaluator in the assembler evaluates an expression in the operand field of a source program. The expressions are composed of combinations of terms and operators.

terms

Terms in an expression are:

Each term is described by four attributes: value, relocation type, memory type and size. The relocation type is either absolute or relocatable. An absolute term is one in which the value is completely known during assembly. A relocatable term is defined as a label within a relocatable section (see .sect), a symbol equated to another relocatable expression, or a symbol declared with the .extrn directive. The value of a relocatable term is the offset of the label from the start of the section or the external value. Both of these values must be determined by the linker.

The memory type of a term indicates whether the term represents a BASE, RAM, EERAM, REG, SEG, SEGB or ROM address. This is also specified by use of the .sect or .extrn directives. In addition, the memory type of a term may be null in the case of an absolute term. The size attribute of a term is null, byte or word. A term has the byte attribute if it is the label on a .db, .dsb, or .fb directive, or it is specified as byte on a .extrn or .set directive or = (assignment). A term has the word attribute if it is the label on a .dw, .dsw, or .fw directive, or it is specified as word on the .extrn or .set directive or = (assignment).

An expression has the same attributes as a term. These attributes are taken from the terms that comprise the expression, and only certain combinations of terms are valid in an expression. The relocation type of an expression is derived from its terms as follows (aterm is absolute, rterm is relocatable, op represents any operator, cop represents any conditional operator, e.g., >=):

		rterm = rterm  +  aterm
		rterm = rterm  -  aterm
		rterm = aterm  +  rterm
		aterm = aterm  op aterm
		aterm = rterm  -  rterm
		aterm = rterm cop rterm
	

In the last two cases, the terms must be relocatable within the same section. Any other expression is considered to have a complex relocation type and must be resolved by the linker.

The memory or size type of an expression is derived from its terms in a manner similar to the relocation type. If type is an expression with memory or size type and number is an absolute (non-label) value, then the following rules apply:

		type =  type  + number
		type =  type  - number
		type = number +  type
	

Any other combinations of memory or size types are considered null. Also, a complex expression is considered to have a null size type. The size type of a term can be ignored using the & (untype) operator. For example, the expression "&byte_variable" would have a null type even if byte_variable was declared as "byte_variable = 123:BYTE".

Here is notation for the various types of terms:

termdescriptionexamples
decimal constant A decimal constant term is a decimal number that optionally begins with "D'" or "d'." Leading zero is not permitted for decimal, except for simple case of constant 0. 3, 234, -10, D'3.
hexadecimal constant A hexadecimal constant term is a hexadecimal number that starts with "X'" or "x'" or "H'" or "h'" or "0X" or "0x" or 0. An optional "H" or "h" is permitted at the end. X'23A, H'23A, 0x23A, 023A, 023AH.
octal constant An octal constant term is an octal number that starts with "O'" or "o'" or "Q'" or "q'." O'27, Q'27.
binary constant A binary constant term is a binary number that starts with "B'" or "b'." B'011, B'0111011.
string constant A string constant term is a one or two character string enclosed in single quotation marks. 'Z', '$', '23', '', '''', ''''''.
label A label term is described in the Section called label field under the label field description.  
symbol A symbol term consists of a single symbol. The symbol has been given a value by either an assignment statement or by the .set directive  
location counter The location counter term is a single dot (.). The dot represents the location counter and, if it appears within an expression, it is replaced by the current value of the location counter. JP .

The null string '' is evaluated as 0. Within a string, single quotation marks are indicated by two quotation marks. The string '''' is the single quotation mark string, and '''''' is the double quotation mark string.

String constants are represented internally by the appropriate 8-bit ASCII code (the most significant bit is zero).

	''   is replaced by 0
	'A'  is replaced by 041
	'AB' is replaced by 04142
	

The following escape codes may be used in a string constant to represent the value shown:

	\a 0x7 bell
	\b 0x8 backspace
	\f 0xC formfeed
	\n 0xA linefeed
	\r 0xD carriage return
	\t 0x9 horizontal tab
	\v 0xB vertical tab
	\0 0 null
	' 0x27 quote
	\" 0x22 double quote
	\\ 0x5C reverse slash
	

Any lowercase character may also be specified as uppercase (e.g., \b and \B are the same).

Numbers are represented internally in the assembler in 16-bit two's complement notation. The range for numbers in this representation is -32768 (X'8000) to +32767 (X'7FFF) for signed numbers and 0 to 65535 for unsigned numbers.

operators

Operators in an expression are:

The arithmetic operators are the usual +, -, *, /, MOD, SHL, SHR, ROL, and ROR. The logical operators are NOT, AND, OR and XOR. The available relational operators are EQ, NE, GT, LT, GE and LE. The ampersand (&) is the untype operator. The upper- and lower-byte extraction operators are HIGH and LOW. Table 2-1 lists the operators, function and whether the operator is unary or binary. Some operators have optional syntax for compatibility with older assemblers. Table 2-2 lists the precedence order for the evaluation of the operators; a higher precedence operator is evaluated before a lower precedence operator.

operatoraliasfunctiontype
+ additionunary or binary
- subtractionunary or binary
* multiplicationbinary
/ divisionbinary
MOD modulobinary
SHL shift leftbinary
SHR shift rightbinary
ROL rotate leftbinary
ROR rotate leftbinary
NOT%logical notunary
AND&logical andbinary
OR!logical orbinary
XOR logical xorbinary
LT<less thanbinary
EQ=equal tobinary
GT>greater thanbinary
LE<=less than or equal tobinary
GE>=greater than or equalbinary
NE<>not equal tobinary
& untypeunary
LOWLlower 8 bitsunary
HIGHHhigh 8 bitsunary
B_SECT beginning of sectionunary
E_SECT end of sectionunary

operatorprecedence value
)0 (lowest)
OR,!1
XOR1
AND, &2
NOT,%3
LT,<4
GT,>4
EQ,-4
NE,<>4
LE,<=4
GE,>=4
+5
-5
/6
MOD6
SHL6
SHR6
ROL6
ROR6
LOW,L7
HIGH,H7
(9
unary -9
unary +9

Parentheses are permitted in expressions. Parentheses in expressions override the normal order of evaluation; the expression(s) within the parentheses are evaluated before the outer expressions.

expressions

An expression may consist of a single term, as shown in the following:

	5
	X'3C
	'Q'
	SUB
	.
	HIGH(X'3CF)
	LOW(SUB)
	

Alternatively, an expression may consist of two or more terms combined using the operators shown in Table 2-1.

	36 + SUB
	X'3F0-10
	X'7F AND 'Q'
	3*5 OR XYZ
	(NOT SUB)/2
	

Note: All expression evaluations treat the terms as unsigned numbers; for example, -1 is treated as value X'FFFF.

The magnitude of the expression must be compatible with the memory storage available for the expression. For example, if the expression is to be stored in an 8-bit memory word, then the value of the expression must not exceed X'FF.