Quick start manual

Inline assembly code
13-15
Expressions
Expression types
Every built-in assembler expression has a type—or, 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
MOV AL,QuitFlag
MOV BX,OutBufPtr
end;
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:
MOV DL,BYTE PTR OutBufPtr
MOV DL,Byte(OutBufPtr)
MOV DL,OutBufPtr.Byte
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:
procedure Example(var Buffer);
asm
MOV AL, [Buffer]
MOV CX, [Buffer]
MOV EDX, [Buffer]
The built-in assembler permits these instructions, because the expression [Buffer] has
no type—it 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,
INC BYTE PTR [ECX]
IMUL WORD PTR [EDX]