Red Code
From Biowiki
Contents
Redcode
The programming language of Core Wars.
From http://vyznev.net/corewar/guide.html
Memory space
All arithmetic is module CORESIZE. All addressing is relative.
Instruction structure
Opcode | Operand A | Operand B |
Instruction set
- DAT -- data (kills the process)
- MOV -- move (copies data from one address to another)
- ADD -- add (adds one number to another)
- SUB -- subtract (subtracts one number from another)
- MUL -- multiply (multiplies one number with another)
- DIV -- divide (divides one number with another)
- MOD -- modulus (divides one number with another and gives the remainder)
- JMP -- jump (continues execution from another address)
- JMZ -- jump if zero (tests a number and jumps to an address if it's 0)
- JMN -- jump if not zero (tests a number and jumps if it isn't 0)
- DJN -- decrement and jump if not zero (decrements a number by one, and jumps unless the result is 0)
- SPL -- split (starts a second process at another address)
- CMP -- compare (same as SEQ)
- SEQ -- skip if equal (compares two instructions, and skips the next instruction if they are equal)
- SNE -- skip if not equal (compares two instructions, and skips the next instruction if they aren't equal)
- SLT -- skip if lower than (compares two values, and skips the next instruction if the first is lower than the second)
- LDP -- load from p-space (loads a number from private storage space)
- STP -- save to p-space (saves a number to private storage space)
- NOP -- no operation (does nothing)
Example programs
Addressing Modes
- # -- immediate
- $ -- direct (the $ may be omitted)
- * -- A-field indirect
- @ -- B-field indirect
- { -- A-field indirect with predecrement
- < -- B-field indirect with predecrement
- } -- A-field indirect with postincrement
- > -- B-field indirect with postincrement
Instruction modifiers
- MOV.A -- moves the A-field of the source into the A-field of the destination
- MOV.B -- moves the B-field of the source into the B-field of the destination
- MOV.AB -- moves the A-field of the source into the B-field of the destination
- MOV.BA -- moves the B-field of the source into the A-field of the destination
- MOV.F -- moves both fields of the source into the same fields in the destination
- MOV.X -- moves both fields of the source into the opposite fields in the destination
- MOV.I -- moves the whole source instruction into the destination