Written with Jéremy Gagnot and Thibaut Fontaine
Corewar is a pretty confusing project involving a questionable VM and some pieces of bytecode fighting for their life.
It is divided in two parts.
- The VM allocates some memory in which the processes will fight. This memory is circular.
- Every cycle, each process is executed. Its PC moves to the next byte and tries to execute an instruction there.
- Each instruction takes a set time to execute. (forking a process takes 1000 cycles for example).
- Each process has access to 16 registers.
- Every set number of cycles, the VM kills every process that hasn't executed the
liveinstruction - The last process alive is declared winner.
The code in the asm folder produces a compiler that compiles pseudo assembly code.
There are 16 instructions :
live: makes the process liveld, ldi, lld, lldi: load memory bytes into a process' register.st, sti: writes a process' register onto the memory.add, suband, or, xorfork, lfork: forks the processzjmp: jumps the PC if the process' internal "carry" is 0aff: display a byte to stdout
- register : one byte, r1 to r16
- direct : two or four bytes
- indirect : two bytes
.name "[program name]"
.comment "[program description]"
[label_definition]:
[instruction] [indirect_arg],%[direct_arg],:[label_name]
#comment
One instuction =
- One byte for the opcode
- One byte for the parameter types
- N bytes for the parameters themselves
0x xx xx xx 00
arg1 arg2 arg3
With 01 : register
10 : direct
11 : indirect
