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;

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 EDX, [Buffer]

end;

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,

INC BYTE PTR [ECX]

IMUL WORD PTR [EDX]

The following table summarizes the predefined type symbols that the built-in assembler provides in addition to any currently declared Delphi types.

Predefined type symbols

Symbol

Type

BYTE

1

WORD

2

DWORD

4

QWORD

8

TBYTE

10

Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment