-
-
Notifications
You must be signed in to change notification settings - Fork 56
Setting the minimum addressable unit β #bits
β οΈ Using#bits
on its own won't work in v0.13.0 onwards. Use it inside a#bankdef
definition. See Working with banks β #bankdef, #bank.
The assembler keeps track of what the current address is, incrementing its value whenever enough bits are output. Labels get assigned the current address when you declare them.
By default, it starts at 0 at the beginning of your file, and increments by 1 every time 8 bits are output β which is usually the minimum addressable unit of modern CPUs.
You can use the #bits
directive at the start of your file to change this
default grouping of bits to any value, even exotic ones.
For example:
#bits 3 ; a 3-bit CPU?!
#ruledef
{
load {imm: i3} => 0b100 @ imm ; outputs 2 groups of 3 bits
load.big {imm: i6} => 0b100 @ imm ; outputs 3 groups of 3 bits
halt => 0b111
}
start: ; value of `start` is 0
load 0
load 1
load 2
mid: ; value of `mid` is 6, since 6 groups of 3 bits were output so far
load.big 3
load.big 7
end: ; value of `end` is 12, since 12 groups of 3 bits were output so far
halt
You'd probably want to set your minimum addressable unit in the most comfortable way that works with jump and data loading instructions.
You can skip or reserve bits using the address manipulation directives. You can also set the starting address by using banks.
If you have multiple separate addressing spaces in your CPU design, such as for code and data, you can use banks to set a different minimum addressable unit for each of them.
- 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