The built-in assembler divides expressions into three classes: registers, memory references, and immediate values.
内嵌的汇编器把表达式分为3种类型:寄存器,内存引用和立即数.
An expression that consists solely of a register name is a register expression. Examples of register expressions are AX, CL, DI, and ES. Used
as operands, register expressions direct the assembler to generate instructions that operate on the CPU registers.
只包含一个寄存器名的表达式是寄存器表达式.寄存器表达式比如AX, CL, DI 和 ES.用做操作数,寄存器表达式直接使汇编器产生在CPU寄存器上操作的指令。
Expressions that denote memory locations are memory references. Delphi's labels, variables, typed constants, procedures, and functions belong to this category.
表示内存位置的表达式是内存引用。Delphi的标签,变量,类型常量,过程和函数属于这种类别。
Expressions that aren't registers and aren't associated with memory locations are immediate values. This group includes Delphi's untyped constants and type identifiers.
既不是寄存器也不跟内存位置有关的是立即数表达式。这一组包含Delphi的无类型常量和类型标志符。
Immediate values and memory references cause different code to be generated when used as operands. For example,
立即数和内存引用在用做操作数的时候导致不同的代码产生。比如。
const
Start = 10;
var
Count: Integer;
...
asm
MOV EAX,Start { MOV EAX,xxxx }
MOV EBX,Count { MOV EBX,[xxxx] }
MOV ECX,[Start] { MOV ECX,[xxxx] }
MOV EDX,OFFSET Count { MOV EDX,xxxx }
end;
Because Start is an immediate value, the first MOV is assembled into a move immediate instruction. The second MOV, however, is translated into
因为Start是一个立即数,第一个Mov被编译成一个移动立即数的指令。第二个Mov,然而翻译成一个移动内存的指令,Count作为一个内存引用。第三个Mov,括号把Start转换成一个内存引用(在这种情况下,在数据段中偏移为10的一个字的内容),第四个Mov,OFFSET操作符把Count转换为一个立即数(在数据段中的Count个偏移)。
a move memory instruction, as Count is a memory reference. In the third MOV, the brackets convert Start into a memory reference (in this case, the word at offset 10 in the data segment). In the fourth MOV, the OFFSET operator converts Count into an immediate value (the offset of Count in the data segment).
The brackets and OFFSET operator complement each other. The following asm statement produces identical machine code to the first two lines of the previous asm statement.
括号和OFFSET可以互相转换。在asm前的头2行汇编语句将产生同样的机器码。
asm
MOV EAX,OFFSET [Start]
MOV EBX,[OFFSET Count]
end;
Memory references and immediate values are further classified as either relocatable or absolute. Relocation is the process by which the linker assigns absolute addresses to symbols. A relocatable expression denotes a value that requires relocation at link time, while an absolute
立即数和内存引用是进步的分类作为重定位和绝对地址。
expression denotes a value that requires no such relocation. Typically, expressions that refer to labels, variables, procedures, or functions are relocatable, since the final address of these symbols is unknown at compile time. Expressions that operate solely on constants are absolute.
The built-in assembler allows you to carry out any operation on an absolute value, but it restricts operations on relocatable values to addition and subtraction of constants.
表示一个数值的表达式要求没有如此的重定位
典型地,引用标签,变量,过程和函数的表达式是可重定位的,因为这些标志符最终的地址在编译时是未知的
表达式操作常量是唯一的绝对
内嵌汇编允许你对一个绝对值进行任何操作,但是限制可重定位的值的加或者减常量的操作。