What is the bot CPU, and why is there an assembly league?
The machine
- Words are 32 bits. There are eight general registers,
r0tor7, plus a stack pointersp. - Program ROM holds your code, separate from data. In the assembly league it's 1,024 words (more with a ROM-M or ROM-L), and code size is part of the challenge.
- Data RAM holds variables and the stack: 256 words in assembly.
- The clock gives 256 cycles each tick in assembly, and there are 20 ticks a second.
- Numbers for the devices are Q16.16 fixed point, and the CPU has instructions for them (
MULQ,DIVQ), along with angle literals like#90deg.
Each part on your machine is a device on a numbered channel. A program reads them and commands them each tick: POLL brings fresh readings in, IN and OUT read and write a device's registers, SEND sends your commands, and WAIT gives up the rest of the tick.
A tiny assembly bot
This drives forward at full throttle, forever:
.include "chs-l.inc"
.equ CHS, 0 ; the chassis is on channel 0
.code
loop: POLL r0 ; fresh readings in
CLRIO
MOV r1, #1.0q ; full throttle
OUT #CHS, #CHS_THROTTLE, r1
OUT #CHS, #CHS_CTRL, #CHS_APPLY_THROTTLE
SEND ; commands out
WAIT ; give up the rest of this tick
JMP loop
.include "std.s"
A command only takes effect when its bit is set in the device's CTRL register, so you write the value first, then CTRL.
Why write assembly?
- Total control. No compiler overhead: you decide exactly what each cycle does.
- It's a puzzle. Fitting a smart bot into 256 cycles a tick is the hard-core challenge.
- It's the truth underneath. In any other language, open Generated assembly under the editor to see what your program became. It's a good way to learn what your code really costs.
The other leagues get twice the cycles and four times the memory, which offsets what compiled code costs. So assembly isn't an advantage on its own. It's a different way to play.
When the CPU faults
Only a few mistakes fault the CPU, such as reading or writing outside RAM, overflowing the stack, or jumping outside the program. Then it reboots. It stalls for 1 second (20 ticks) and starts again from the top. Its parts keep doing what they were last told, and the match goes on.
The full instruction list, with every cycle cost, is in Reference under the editor (Instructions) when the Assembly league is picked.