This assembler language is close to x86 assembler. This chapter describes the syntax.
The processor have 9 registers (float value), and 3 flags (boolean):
eip : Instruction Pointer, this is a pointer in the code segment on next instruction to be executed. This register is protected, you can't access it.
eax : Accumulator register. Use this as a general register.
ebx : Base register. Use this as a general register.
ecx : Counter register. Generaly use for counting, looping, etc ...
edx : Data register. Generaly use for keeping data.
esi : Start pointer. Generaly use for keeping an offset in memory.
edi : Destination pointer. Generaly use for keeping a offset in memory.
ebp : Base pointer. Use for pointing the base of the stack.
esp : Stack pointer. Use for pointing the top of the stack.
flags lower (l) : Set when the last comparison result was lower.
flags equals (e) : Set when the last comparison result was equality.
flags greater (g) : Set when the last comparison result was greater.
To declare variables, use the keyword dd
dd myVar, value1 (rep1), ... ,valueN (repN) : declare a variable myVar, initialised by rep1 value1, follow by rep2 value2, etc ....
- dd myVar, 15.0 : init myVar with 15.0
- dd myVar, 15.0(5) : init a tab of 5 elements myVar with values [15.0, 15.0, 15.0, 15.0, 15.0]
- dd myVar, 15.0(2), 10(2) : init a tab of 4 elements myVar with values [15.0, 15.0, 10.0, 10.0]
Includes other files
You can split your code into several files. Simply include them with :
You can access values of variables or registers by different ways :
- single access : just use a register or variable in a instruction to use its value.
For example : mov eax, myVar copy the value of myVar into the register eax.
- variable indexed access : Access to a value of a array variable, indexed by a constant and/or another variable.
For example : mov eax, myVar copy the value of of 13th elements of myVar into the register eax.
For example : mov eax, myVar[ebx] does the same if ebx contains 12.
For example : mov eax, myVar[ebx+10] does the same if ebx contains 2.
- direct offset access : Access to a value at specified offset in data segment.
For example : mov eax, [esi] copy the value pointed by esi register in eax.
These instructions do data manipulation :
mov rwArg0, roArg1 : copy the value of roArg1 into rwArg0
lea rwArg0, roArg1 : copy the offset of roArg1 into rwArg0
push roArg0 : copy the value of roArg1 on the top of the stack
pop rwArg0 : copy the top of the stack into rwArg0
For doing loops, functions and tests, you must declare label with the syntax :
After you can use the label myLabel in several instructions.
jmp myLabel : go to the next instruction pointed by myLabel
The :main label is a mandatory label. It's the first instruction executed when your bot starts.
Conditionnal tests are done by comparing something, and jumping to a label if the result is a particular result.
cmp eax, ebx : cmp compares two values, and set flags E, L, G. If the values are equals, E is set to true. If the first value is lower than the second, the L flags is set. And if the result is greater, the flags G is set.
After a comparison is done, you can jump to a label using this instructions :
je myLabel : jump only if flags E is set.
jne myLabel : jump only if flags E is not set.
jge myLabel : jump only if flags E or G are set.
etc ... see the complete variants list in opcodes list
A function is a label you call with a particular instruction call :
call myLabel : go to myLabel, and push on the top of the stack the line of the instruction next to the call. This will allow us to return where we were.
ret : using ret in a function, will pop the value on the top of the stack (instruction pointer), and go to this instruction.
For example :
mov eax, 12
add eax, 8
This example will start at the label main, then call myFunc, execute mov eax, 12, return to add eax, 8 and execute it.
A lot of instructions does data computations. Go to opcodes list to have a complete list.
For example : add eax, ebx : add the value of eax and ebx and store the result in eax.
Bots interact with their environnement with this instructions :
drive roArg0 : Update the wanted direction (degree)
speed roArg0 : Update the wanted speed (m/s)
fire roArg0, roArg1 : Fire a missile in roArg0 direction (degree), at range roArg1 (m)
scan rwArg0, roArg1, roArg2 : Scan in roArg1 direction (degree), with roArg2 precision (degree), and store the result (first bot distance found) in rwArg0 (m)
Radio channels must be opened to send a message. The message is effectively sent when the channel is closed.
open roArg0, roArg1 : Open the chan roArg0 for sending radio data, for bot roArg1. If roArg1 = 1 then all bots will receive the message. Reopening a chan previously opened which wasn't close will result in reseting all written values
write roArg0, roArg1 :write roArg0, roArg1
close roArg0 : Close the chan roArg0 and send all data written since the chan was opened.
read roArg0, rwArg1 : Try to read a value on the chan roArg0. If a value is read, write it to rwArg1 else rwArg1 is not changed