Books

Inline Assembler

D, being a systems programming language, provides an inline
assembler.
The inline assembler is standardized for D implementations across
the same CPU family, for example, the Intel Pentium inline assembler
for a Win32 D compiler will be syntax compatible with the inline
assembler for Linux running on an Intel Pentium.

Implementations of D on different architectures, however, are
free to innovate upon the memory model, function call/return conventions,
argument passing conventions, etc.

This document describes the x86 implementation of the inline
assembler.

align IntegerExpression

Causes the assembler to emit NOP instructions to align the next
assembler instruction on an IntegerExpression boundary.
IntegerExpression must evaluate at compile time to an integer that is
a power of 2.

Aligning the start of a loop body can sometimes have a dramatic
effect on the execution speed.

even

Causes the assembler to emit NOP instructions to align the next
assembler instruction on an even boundary.

naked

Causes the compiler to not generate the function prolog and epilog
sequences. This means such is the responsibility of inline
assembly programmer, and is normally used when the entire function
is to be written in assembler.

db, ds, di, dl, df, dd, de

These pseudo ops are for inserting raw data directly into
the code.
db is for bytes,
ds is for 16 bit words,
di is for 32 bit words,
dl is for 64 bit words,
df is for 32 bit floats,
dd is for 64 bit doubles,
and de is for 80 bit extended reals.
Each can have multiple operands.
If an operand is a string literal, it is as if there were length
operands, where length is the number of characters in the string.
One character is used per operand.
For example:

The operand syntax more or less follows the Intel CPU documentation
conventions.
In particular, the convention is that for two operand instructions
the source is the right operand and the destination is the left
operand.
The syntax differs from that of Intel's in order to be compatible
with the D language tokenizer and to simplify parsing.

The seg means load the segment number that the symbol is
in. This is not relevant for flat model code.
Instead, do a move from the relevant segment register.