The assemblers in Gforth generally use a postfix syntax, i.e., the instruction name follows the operands.
The operands are passed in the usual order (the same that is used in the manual of the architecture). Since they all are Forth words, they have to be separated by spaces; you can also use Forth words to compute the operands.
The instruction names usually end with a ,
. This makes it easier
to visually separate instructions if you put several of them on one
line; it also avoids shadowing other Forth words (e.g., and
).
Registers are usually specified by number; e.g., (decimal) 11
specifies registers R11 and F11 on the Alpha architecture (which one,
depends on the instruction). The usual names are also available, e.g.,
s2
for R11 on Alpha.
Control flow is specified similar to normal Forth code (see Arbitrary control structures), with if,
, ahead,
, then,
,
begin,
, until,
, again,
, cs-roll
,
cs-pick
, else,
, while,
, and repeat,
. The
conditions are specified in a way specific to each assembler.
The rest of this section is of interest mainly for those who want to
define code
words (instead of the more portable abi-code
words).
Note that the register assignments of the Gforth engine can change
between Gforth versions, or even between different compilations of the
same Gforth version (e.g., if you use a different GCC version). If
you are using CODE
instead of ABI-CODE
, and you want to
refer to Gforth’s registers (e.g., the stack pointer or TOS), I
recommend defining your own words for refering to these registers, and
using them later on; then you can adapt to a changed register
assignment.
The most common use of these registers is to end a code
definition with a dispatch to the next word (the next
routine).
A portable way to do this is to jump to ' noop >code-address
(of course, this is less efficient than integrating the next
code and scheduling it well). When using ABI-CODE
, you can
just assemble a normal subroutine return (but make sure you return the
data stack pointer).
Another difference between Gforth versions is that the top of stack is
kept in memory in gforth
and, on most platforms, in a register
in gforth-fast
. For ABI-CODE
definitions, any stack
caching registers are guaranteed to be flushed to the stack, allowing
you to reliably access the top of stack in memory.