Expressions & special values

Anywhere a number is expected, FantASM accepts an expression — constants, labels, literals and arithmetic are all evaluated at assembly time.

buffer_end = buffer + SIZE
half       = value / 2
flags      = A_BIT | B_BIT

Special values

These read the assembler’s current state and can be used inside any expression:

ValueMeaning
$, asmpcThe current program counter.
codesizeThe current assembly address relative to the start.
bankThe current memory bank number.
pageThe current memory page number.
tstatesAccumulated T-state count since the start of assembly.
here:
    jr $                 ; jump to self
length = $ - message     ; size of the data above

Sizeof

SIZEOF(<label>) returns the size of a structure or an included binary:

sprite:  incbin "sprite.bin"
sprite_len = SIZEOF(sprite)

Rhai in expressions

FantASM embeds the Rhai scripting engine. The rhai() function evaluates a Rhai expression at assembly time and returns its value, for computation that goes beyond plain arithmetic:

value = rhai("40 * 40 + 7")

See Rhai scripting for build logic and custom directives.