Syntax - gtrxAC/gxarch GitHub Wiki
A gxarch program consists of statements. Statements can be:
- instructions
- compile time instructions, used for managing variables
- labels
- blocks
- includes
Labels
A label creates a new address variable whose value is the current position in the code. They are used for creating points in the code which can be then jumped to or called as a function. Another use is creating array variables such as the default font widths.
; This creates a variable called 'main' which is a memory address referring to this point in the ROM.
main:
; Do something...
; This jumps back to the memory address of 'main' which creates an infinite loop.
jmp main
Blocks
Blocks are used to create a new scope for variables. Blocks are braces { ... }
that have statements inside of them - blocks are also statements so blocks can contain other blocks. Variables defined inside a block cannot be accessed outside of it.
; Create a register called 'a' and increment it by one.
reg a %0
add [a] 1 a
{
; 'b' is another register which is set to b - 10.
reg b %1
sub [a] 10 b
}
; Error! 'b' cannot be used outside of its scope (block).
mul [b] 2 b
Includes
Includes are used to copy contents of other files into the current file. They are useful for importing libraries and organizing different parts of a larger project (functions that accomplish a specific task can be grouped into one file and included in the main file).
An include looks like this: include "std/print.gxs"
. The file path is relative to the working directory where the assembler was executed.