The
built-in assembler provides a variety of operators. Precedence rules are
different from Object Pascal; for example, in an asm statement, AND has
lower precedence than the addition and subtraction operators. The following
table lists the built-in assembler’s expression operators in decreasing order
of precedence.
|
Operators |
Remarks |
Precedence |
|
& |
|
highest |
|
( ), [ ], ., HIGH, LOW |
|
|
|
+, - |
unary + and - |
|
|
: |
|
|
|
OFFSET, TYPE, PTR, *, /, MOD, SHL, SHR, +, - |
binary + and - |
|
|
NOT, AND, OR, XOR |
|
lowest |
The following table defines the built-in assembler’s expression operators.
Operator
|
Description |
|
& |
Identifier override. The identifier immediately following the ampersand is treated as a user-defined symbol, even if the spelling is the same as a built-in assembler reserved symbol. |
|
(...) |
Subexpression. Expressions within parentheses are evaluated completely prior to
being treated as a single expression element. Another expression can precede
the expression within the parentheses; the result in this case is the sum of
the values of the two expressions, with the type of the first expression. |
|
[...] |
Memory reference. The expression within brackets is evaluated completely prior to
being treated as a single expression element. Another expression can precede
the expression within the brackets; the result in this case is the sum of the
values of the two expressions, with the type of the first expression. The
result is always a memory reference. |
|
. |
Structure member selector. The result is the sum of the expression before the period and the
expression after the period, with the type of the expression after the
period. Symbols belonging to the scope identified by the expression before
the period can be accessed in the expression after the period. |
|
HIGH |
Returns the high-order 8 bits of the
word-sized expression following the operator. The expression must be an
absolute immediate value. |
|
LOW |
Returns the low-order 8 bits of the word-sized expression following the operator. The expression must be an absolute immediate value. |
|
+ |
Unary plus. Returns the expression following the plus with no changes. The expression must be an absolute immediate value. |
|
- |
Unary minus. Returns the negated value of the expression following the minus. The expression must be an absolute immediate value. |
|
+ |
Addition. The expressions can be immediate values or memory references, but only one of the expressions can be a relocatable value. If one of the expressions is a relocatable value, the result is also a relocatable value. If either of the expressions is a memory reference, the result is also a memory reference. |
|
- |
Subtraction. The first expression can have any class, but the second expression must be an absolute immediate value. The result has the same class as the first expression. |
|
: |
Segment override. Instructs the assembler that the expression after the colon belongs to the segment given by the segment register name (CS, DS, SS, FS, GS, or ES) before the colon. The result is a memory reference with the value of the expression after the colon. When a segment override is used in an instruction operand, the instruction is prefixed with an appropriate segment-override prefix instruction to ensure that the indicated segment is selected. |
|
OFFSET |
Returns the offset part (double word) of
the expression following the operator. The result is an immediate value. |
|
TYPE |
Returns the type (size in bytes) of the expression following the operator. The type of an immediate value is 0. |
|
PTR |
Typecast operator. The result is a memory reference with the value of the expression following the operator and the type of the expression in front of the operator. |
|
* |
Multiplication. Both expressions must be absolute immediate values, and the result is an absolute immediate value. |
|
/ |
Integer division. Both expressions must be absolute immediate values, and the result is an absolute immediate value. |
|
MOD |
Remainder after integer division. Both expressions must be absolute immediate values, and the result is an absolute immediate value. |
|
SHL |
Logical shift left. Both expressions must be absolute immediate values, and the result is an absolute immediate value. |
|
SHR |
Logical shift right. Both expressions must be absolute immediate values, and the result is an absolute immediate value. |
|
NOT |
Bitwise negation. The expression must be an absolute immediate value, and the result is an absolute immediate value. |
|
AND |
Bitwise AND. Both expressions must be absolute immediate values, and the result is an absolute immediate value. |
|
OR |
Bitwise OR. Both expressions must be absolute immediate values, and the result is an absolute immediate value. |
|
XOR |
Bitwise exclusive OR. Both expressions must be absolute immediate values, and the result is an absolute immediate value. |
内建汇编程序提供多种运算符。这些运算符的优先级规则与Object Pascal不同;例如,在asm语句中,AND运算符比加法和加法运算符的优先级低。下表列出了内建汇编程序中表达式运算符的优先级:
|
运算符 |
注释 |
优先级 |
|
& |
|
最高 |
|
( ), [ ], ., HIGH, LOW |
|
|
|
+, - |
一元加和一元减 |
|
|
: |
|
|
|
OFFSET, TYPE, PTR, *, /, MOD, SHL, SHR, +, - |
二元加和二元减 |
|
|
NOT, AND, OR, XOR |
|
最低 |
下表列出了内建汇编程序中表达式运算符的定义:
运算符
|
描述 |
|
& |
标识符忽略。紧随该符号之后的标识符被视为用户定义的符号,即使其拼写与内建汇编程序的保留字相同。 |
|
(...) |
子表达式。在圆括号内的表达式优先求值并且被视为一个单独的表达式元素。另一个表达式可以在有圆括号的表达式之前;这时的结果是两个表达式的和,并且和的类型是第一个表达式的类型。 |
|
[...] |
内存引用。在方括号中的表达式优先求值并且被视为一个单独的表达式。另一个表达式可以在有方括号的表达式之前;这时的结果是两个表达式的和,并且和的类型是第一个表达式的类型。结果总是内存引用。 |
|
. |
结构成员选择器。结果是表达式的和(点号之前)和表达式(点号之后),类型是点号之后的类型。此类符号属于点号之前的表达式标识的作用域,并且可以访问点号之后的表达式。 |
|
HIGH |
返回运算符后单字尺寸的表达式的高8位。表达式总是一个绝对的立即值。 |
|
LOW |
返回运算符后单字尺寸的表达式的低8位。表达式总是一个绝对的立即值。 |
|
+ |
一元加。返回跟随在加号之后的表达式,没有任何改变。表达式总是一个绝对的立即值。 |
|
- |
一元减。返回跟随在减号之后的表达式的负值。表达式总是一个绝对的立即值。 |
|
+ |
加。表达式可以是立即值或内存引用,但表达式中仅能有一个可以是可再定位的值。如果表达式中有一个是可再定位的值,那么结果也是一个可再定位的值。如果表达式中有一个是内存引用,那么结果也是一个内存引用。 |
|
- |
减。第一个表达式可以是任何表达式,但第二个必须是一个绝对的立即值。结果的类型与第一个表达式的类型相同。 |
|
: |
段忽略。告诉汇编程序冒号之后的表达式属于冒号之前段寄存器名(CS、DS、SS、FS、GS或ES)给出的段。结果一个内存引用,其值是冒号之后表达式的值。当段忽略用在一个指令操作数中时,指令以一个适当的段忽略前缀指示为前缀,以确保指示的段被选择。 |
|
OFFSET |
返回跟随在运算符之后的表达式的偏移量部分(双字)。结果是一个立即值。 |
|
TYPE |
返回跟随在运算符之后的表达式的类型(以字节计算的尺寸)。立即值的类型是0。 |
|
PTR |
类型转换运算符。结果是一个内存引用(该内存引用含有跟随在运算符之后的表达式的值)和一个类型(该类型是运算符之前的表达式的类型)。 |
|
* |
相乘。两个表达式必须是绝对的立即值,并且结果是一个绝对的立即值。 |
|
/ |
整除。两个表达式必须是绝对的立即值,并且结果是一个绝对的立即值。 |
|
MOD |
取模(整除的余数)。两个表达式必须是绝对的立即值,并且结果是一个绝对的立即值。 |
|
SHL |
逻辑左移。两个表达式必须是绝对的立即值,并且结果是一个绝对的立即值。 |
|
SHR |
逻辑右移。两个表达式必须是绝对的立即值,并且结果是一个绝对的立即值。 |
|
NOT |
按位(比特位)取反。两个表达式必须是绝对的立即值,并且结果是一个绝对的立即值。 |
|
AND |
按位(比特位)与。两个表达式必须是绝对的立即值,并且结果是一个绝对的立即值。 |
|
OR |
按位(比特位)或。两个表达式必须是绝对的立即值,并且结果是一个绝对的立即值。 |
|
XOR |
按位(比特位)异或。两个表达式必须是绝对的立即值,并且结果是一个绝对的立即值。 |