šH ca.geocities.com /JLABELLE@rogers.com/nsasm/docs/x381.html ca.geocities.com/JLABELLE_rogers.com/nsasm/docs/x381.html delayed x HnÕJ ˙˙˙˙ ˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙Č Ą¬¸ X OK text/html PS´' X ˙˙˙˙ b‰.H Tue, 07 Dec 2004 00:52:50 GMT R Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98) en, * HnÕJ X
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 in an expression are:
numbers in decimal, hexadecimal, octal, or binary
string constants
labels and symbols
location counter symbol
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:
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:
term | description | examples |
---|---|---|
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).
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
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 in an expression are:
arithmetic operators
logical operators
relational operators
upper- and lower-byte extraction operators
untype operator
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.
operator | alias | function | type |
---|---|---|---|
+ | addition | unary or binary | |
- | subtraction | unary or binary | |
* | multiplication | binary | |
/ | division | binary | |
MOD | modulo | binary | |
SHL | shift left | binary | |
SHR | shift right | binary | |
ROL | rotate left | binary | |
ROR | rotate left | binary | |
NOT | % | logical not | unary |
AND | & | logical and | binary |
OR | ! | logical or | binary |
XOR | logical xor | binary | |
LT | < | less than | binary |
EQ | = | equal to | binary |
GT | > | greater than | binary |
LE | <= | less than or equal to | binary |
GE | >= | greater than or equal | binary |
NE | <> | not equal to | binary |
& | untype | unary | |
LOW | L | lower 8 bits | unary |
HIGH | H | high 8 bits | unary |
B_SECT | beginning of section | unary | |
E_SECT | end of section | unary |
operator | precedence value |
---|---|
) | 0 (lowest) |
OR,! | 1 |
XOR | 1 |
AND, & | 2 |
NOT,% | 3 |
LT,< | 4 |
GT,> | 4 |
EQ,- | 4 |
NE,<> | 4 |
LE,<= | 4 |
GE,>= | 4 |
+ | 5 |
- | 5 |
/ | 6 |
MOD | 6 |
SHL | 6 |
SHR | 6 |
ROL | 6 |
ROR | 6 |
LOW,L | 7 |
HIGH,H | 7 |
( | 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.
An expression may consist of a single term, as shown in the following:
Alternatively, an expression may consist of two or more terms combined using the operators shown in Table 2-1.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.