-
-
Notifications
You must be signed in to change notification settings - Fork 57
Declaring labels and constants
You can declare named constants by using an equals sign =
.
Constants can then be used anywhere expressions are expected, including instruction arguments and other constant declarations.
#ruledef
{
ld {x: i8} => 0x10 @ x
}
some_constant = 0x42
another_constant = 2 * (some_constant + 5)
ld some_constant
ld another_constant
Constants can be referenced out-of-order, and the assembler's deferred resolution mechanism will attempt to resolve all the values.
z = x * y ; `z` can reference labels that are only declared after itself
x = 7
y = 5
From v0.13.0 onwards: You can alternatively declare constants with #const
.
You can also use #const(noemit)
to prevent a constant from being exported with
one of the symbol output formats.
#const x = 7
#const y = 5
#const(noemit) z = x * y
You can declare labels by using a colon :
. All indentation is ignored and is only
used for aesthetic purposes.
Labels are similar to constants, but the assembler assigns values to them automatically, based off on the current address.
Again, labels may be referenced out-of-order, and the assembler's deferred resolution mechanism will attempt to resolve all the addresses.
#ruledef
{
jmp {addr: i16} => 0x20 @ addr
}
start:
jmp middle
middle:
jmp end
end:
jmp start
Constants and labels can be nested by using periods .
in front of their declarations.
This creates local names that can only be referenced inside the same section β sections being delimited by the two enclosing higher-level declarations.
Alternatively, local names can be referenced from outside the section by using their fully-qualified names.
; `abc` section starts at its declaration
abc:
ld .local ; references `abc.local`
ld xyz.local
.local:
jmp xyz
; `abc` section ends here, at the next declaration of the same level
xyz:
ld .local ; references `xyz.local`
ld abc.local
.local:
jmp abc
Multiple nesting levels are supported.
Continuing the section delimitation logic, third-level ..
names are local
to the section between the enclosing second-level .
names.
abc:
.n1:
..n2:
ld ..n2
ld .n1
ld xyz.n1.n2
xyz:
.n1:
..n2:
ld ..n2
ld .n1
ld abc.n1.n2
- Getting started
- Defining mnemonics β #ruledef, #subruledef
- Declaring labels and constants
- Setting the minimum addressable unit β #bits
- Outputting data blocks β #d
- Working with banks β #bankdef, #bank
- Address manipulation directives β #addr, #align, #res
- Splitting your code into multiple files β #include, #once
- Advanced mnemonics, cascading, and deferred resolution β assert()
- Available expression operators and functions β incbin(), incbinstr(), inchexstr()
- Functions β #fn
- Conditional Compilation β #if, #elif, #else