Expression Types
Every built-in assembler expression has a typeor, more correctly, a size, because the assembler regards the type of an expression simply as the size of its memory location. For example, the type of an Integer variable is four, because it occupies 4 bytes. The built-in assembler performs type checking whenever possible, so in the instructions
|
var | ||||||||||||||||||||||||||||||||||||||||||
|
QuitFlag: |
Boolean; | |||||||||||||||||||||||||||||||||||||||||
|
OutBufPtr: |
: Word; | |||||||||||||||||||||||||||||||||||||||||
|
asm |
AL,QuitFlag BX,OutBufPtr the assembler checks that the size of QuitFlag is one (a byte), and that the size of OutBufPtr is two (a word). The instruction MOV DL,OutBufPtr produces an error because DL is a byte-sized register and OutBufPtr is a word. The type of a memory reference can be changed through a typecast; these are correct ways of writing the previous instruction:
These MOV instructions all refer to the first (least significant) byte of the OutBufPtr variable. In some cases, a memory reference is untyped. One example is an immediate value (Buffer) enclosed in square brackets:
The built-in assembler permits these instructions, because the expression [Buffer] has no typeit just means "the contents of the location indicated by Buffer," and the type can be determined from the first operand (byte for AL, word for CX, and double-word for EDX. In cases where the type can't be determined from another operand, the built-in assembler requires an explicit typecast. For example,
The following table summarizes the predefined type symbols that the built-in assembler provides in addition to any currently declared Delphi types.
| |||||||||||||||||||||||||||||||||||||||||
Post a comment