Assembly mode
Yabal has a special mode called "assembly mode". In assembly mode, you can write assembly code directly in your program.
To enter assembly mode, use the asm
keyword, followed by a block of code surrounded by curly braces ({
and }
):
asm {
// Assembly code goes here
}
Assembly mode is useful if you want to use an instruction that is not supported by Yabal, or if you want to optimize a piece of code.
Comments
The default comment style in assembly mode is the same as in Yabal (//
for single-line comments and /*
and */
for multi-line comments) but you can also use assembly comments.
Assembly comments start with ,
and end at the end of the line:
asm {
, This is an assembly comment
}
These comments are are included in the generated assembly code, which can be useful for adding notes to the assembly code.
Instructions
To see the list of supported assembly instructions, see the Astro-8 instruction set documentation.
In addition to the instructions listed in the instruction set documentation, Yabal also supports the following instructions:
Instruction | Description |
---|---|
HERE | Insert the argument as a raw value |
JE | Jump to the specified label if register A is equal to register B |
JNE | Jump to the specified label if register A is not equal to register B |
JL | Jump to the specified label if register A is less than register B |
JLE | Jump to the specified label if register A is less than or equal to register B |
JG | Jump to the specified label if register A is greater than register B |
JGE | Jump to the specified label if register A is greater than or equal to register B |
Variable addresses
In assembly mode, you can get the address of a variable by using @
followed by the name of the variable:
int variable = 1
asm {
AIN @variable // Read the value of a into register A
LDIB 1 // Load the value 1 into register B
ADD // Add the value of register B to register A
STA @variable // Store the value of register A into a
}
variable
Labels
Labels are used to mark a location in the assembly code. They are used by jump instructions to jump to a specific location in the code.
Labels are declared by writing the name of the label, followed by a colon (:
):
asm {
label:
}
To jump to a label, use the JMP
instruction:
asm {
label:
JMP label
}
Note: It is only possible to jump to labels that are declared in the same assembly block.
You can also use labels to mark data and use AIN
to load the address.
For example, the following code will create a label called data
and load the address of the label into register A
:
int variable
asm {
JMP program
data:
HERE 5
program:
AIN data
STA @variable
}
variable