Getting Started

In-line assembler code integrates with the rest of a Pascal program. You declare variables as normal and output as normal but write assembler language in a block between the keywords asm and end. We use Intel syntax in the first of each pair of programs and have tested these programs in Lazarus and Delphi 7. The directive {$ASMMODE INTEL} is required in Lazarus but is not accepted by Delphi, so Delphi users should comment out or delete this line. The second program of each pair, in AT&T syntax, has an A appended to its name. The following table summarises important differences between the syntaxes. The EAX register is the accumulator and the mnemonic MOV is a slight abbreviation for 'move'.

  Intel syntax Intel example AT&T syntax AT&T example
Registers No prefix EAX Leading % %EAX
Order of operands Destination followed by source MOV EAX, 5 Source followed by destination MOV $5, %EAX
Literal values No symbol for denary MOV EAX, 5 $ indicates value (not address) MOV $5, %EAX
Hex value Leading $ $A Leading $0x $0xA
Binary value Trailing b 101b Leading $0b $0b101
Labels Leading @, Trailing : @Start: Leading .L, Trailing : .LStart:
Indirect operands Square brackets MOV [EAX], 5 Rounded brackets MOV $5, (EAX)
Indexing symbol + [ECX + ByteArray] None or , ByteArray (%ECX) (%ECX,%EAX)
Operand size May be included MOV AL, byte ptr MyByte Mnemonic may have suffix MOVB MyByte, %AL

Follow these links to demonstration programs to learn more about in-line assembler code.

Programming - a skill for life!

In-line assembler with Intel and AT&T syntax, addressing methods and encryption