Robot Programming Model and Assembly Language:

The robot consists of 6 8 bit registers (memory locations), a flag register, and 256 instruction locations. Each instruction has room for 4 bytes: an opcode byte and three operand bytes. The instruction locations can not be modified by the Roboprogram. But if someone thinks it would be neat to try...

The registers are:
PC program counter, points into the instruction locations at the next instruction to execute. The program counter rolls over without indication if the pc passes 255, back to 0. So a run away program might be hard to spot. There are 4 general purpose registers: Ra, Rb, Rc, Rd. Each eight bit registers can be acted upon by the instructions.. These registers also constitute all the memory the program has to work with.

A flag register with two flags: 0 and one ( I haven't put code in the parser for better labels yet.)
A '0' is obstacle, meaning the robot bumped into something while moving. The second flag ('1' in flag assy code) is a counter-intuitive. If set, it means no enemy was spotted after a look instruction. This counter intuitiveness is a result of the way the jump on flag instruction was implemented and makes for tighter look first then shoot code.

The first robot always starts with all registers set to 0. Any robots produced by the 'CLONE' instruction are created with a PC of 0 and Rb, Rc, Rd equal to 0. Ra is set equal to the parent robot's Ra. This allows for the creation of  'queens and workers' like ants or bees have.

The amount of robowar time processing each instruction takes is variable, just not through the xml config file yet. In this version Everything takes one tick for a robot, except cloning, which takes 200 ticks.

The available robot instructions:
It is case sensitive, and there is not a lot of error checking or helpful messages

(Rx or Ry can be substitued with Ra,Rb,Rc,Rd. 'C' means a constant, 0-255)

Instead of typing a numeric constant for C in the JMP instructions, a LABEL statement name can be used. This is bad in the relative jump instructions. The label is translated into a line number and that number would be used for the relative offset.

Note to self, I do not know what happens if an undefined LABEL is referenced in place of one of these constant operands


Mnemonic
Op1
Op2
Op3
Comment
NOP
-
-
-
do nothing, a place holder, used in some evolution gene crossover schemes
MOVER_R
Rx
Ry
-
move from register to register, copy Rx into Ry
MOVEC_R C
Rx
-
move a constant C into Rx
ADDC
C
Rx
-
add a constant into Rx, rollovers possible and not flagged
ADDR
Rx
Ry
-
add Rx and Ry results in Ry, rollovers possible and not flagged
RANDRx
Rx
-
-
randomize Rx (note RANDRx is one word, do not substitute a true register name)
MOVERobot
Rx


robot will move on map in direction held in Rx, might result in obstacle flag being set
LOOK
Rx
-
-
will look in direction in Rx. If no enemy in that direction NoEnemy flag ('1') will be set
CLONE
-
-
-
Robot will produce copy in an adjacent square if an open one exists and total number of robots below game max
FIRE
Rx
-
-
Robot will shoot in direction held in Rx
JMP
C
-
-
loads the constant C into PC register (C can be a Label )
JMPRel
C
-
-
adds C to PC register (-127 to +127 ) It would be difficult to use a LABEL in this case
JSR
C
-
-
loads constant into PC, saving old PC in one deep stack for use with RTN
JMPFlag
flag indicator, a 0 or a 1
C
-
if flag 'f' is set (0 is obstacle, 1 is 'NoEnemy') load constant C (or label) into PC
JMPFlagR
flag indicator, a 0 or a 1
C
-
C is a relative value added to PC if flag f is set - (0 is obstacle, 1 is 'NoEnemy'). Another place a label statement is not a good substitute for C
JMPReg
Rx
C1
C2
if Rx equals constant C1, PC will be loaded with C2
JMPRegR
Rx
C1
C2
Rx C1 C2  if Rx equals constant C1 PC will be incremented with C2
RTN
-
-
-
fetch PC value from 1 deep stack
RTNFlag flag indicator, a 0 or a 1
-
-
fetch PC value from 1 deep stack if flag f set (0 is obstacle, 1 is 'NoEnemy').
RTNReg
Rx
C
-
fetch PC value from 1 deep stack if Rx equals constant
XPORT
-
-
-
Robot will attempt to Xport itself to the network- Special debug mode only instruction
TERMINATE
-
-
-
Robot self destructs
LABEL
name
-
-
mark a line in the program listing for the assembler to reference, does not wind up in robot instruction memory. The assembler will assign a constant with the line number of the matching LABEL name anywhere it finds an operand with a string matching a defined LABEL in it.































Example Robot File:



CLONE
LABEL START
    JMPReg Ra 1 WORKER1 //if Ra has a 1 in it this will be a WORKER1 so JMP there
    JMPReg Ra 2 WORKER2 //if Ra has a 2 in it this will be a WORKER2 so JMP there
    MOVEC_R 1 Ra               //Since we didn't JMP to any WORKER loop, be a queen and reproduce, first make 2 worker1 offspring
    CLONE
    CLONE
    MOVEC_R 2 Ra               //put a 2 in Ra so the next offspring will be worker2
    CLONE
    CLONE
    MOVEC_R 0 Ra               //make a few more queens
    CLONE
    CLONE
    JMP START                       //do it all again. It might be good for the queens to move and spread out some
LABEL WORKER1
    MOVEC_R 4 Ra               //move south (dir 4, up to 127 steps, will stop when obstructed)
    MOVEC_R 127 Rb
    JSR MOVEFUNC
    JSR FIREFUNC
    MOVEC_R 2 Ra              //move east (dir 2, up to 127 steps, will stop when obstructed)
    MOVEC_R 127 Rb
    JSR MOVEFUNC
    JSR FIREFUNC
    MOVEC_R 0 Ra             //move North hope to find opening
    MOVEC_R 12 Rb
    JSR MOVEFUNC
    JSR FIREFUNC
    MOVEC_R 2 Ra             //move east
    MOVEC_R 127 Rb
    JSR FIREFUNC
    JMP WORKER1            //go back to start of func
LABEL WORKER2
    MOVEC_R 0 Ra            //move North
    MOVEC_R 127 Rb
    JSR MOVEFUNC
    JSR FIREFUNC
    MOVEC_R 2 Ra            //move east
    MOVEC_R 127 Rb
    JSR MOVEFUNC
    JSR FIREFUNC
    MOVEC_R 4 Ra             //move South hope to find opening
    MOVEC_R 20 Rb
    JSR MOVEFUNC
    JSR FIREFUNC
    MOVEC_R 2 Ra             //move east
    MOVEC_R 127 Rb
    JSR MOVEFUNC
    JSR FIREFUNC
    JMP WORKER2           //go back to start of func
LABEL FIREFUNC         //Looks all 8 directions for something to shoot
    MOVEC_R 0 Rd
    LOOK Rd
    JMPFlagR 1 2        //skip the fire instr if NO Enemy flag set
    FIRE Rd
    ADDC 1 Rd
    RTNReg Rd 8
    JMPRel -5
LABEL MOVEFUNC   //Move dir Ra for Rb or till blocked
    MOVERobot Ra      
    RTNFlag 0
    ADDC -1 Rb
    JMPRegR Rb 0 2
    JMP MOVEFUNC
    RTN