Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Redcode

PietHelzel edited this page Oct 23, 2024 · 13 revisions

Important Links

Guide

Instructions

An instruction looks like the following:

MOV.AB @-2, #3

It is made up of the following parts:

  • Opcode (e.g. MOV): The instruction name.
  • Modifier (e.g. AB): Modifies the instruction by specifying which operands it works on.
  • Source field (e.g. @-2 and destination field (e.g. #3):
    • Each made up of an address mode (like @ or #) followed by a number.
    • The comma separator is necessary!

Address modes

Each instruction can have an address mode for each of its fields. The following is a list of all possible address modes:

  • $ - direct addressing
  • # - immediate
  • * - a-field indirect addressing
  • @ - b-field indirect addressing
  • { - a-field indirect addressing with predecrement
  • < - b-field indirect addressing with predecrement
  • } - a-field indirect addressing with postincrement
  • > - b-field indirect addressing with postincrement

Direct Addressing

Direct addressing directly points to the instruction specified by the number. For example, a MOV $0, $1 copies the 0th instruction (the MOV command itself) one space ahead in memory. The dollar sign is optional, if no address mode is specified, direct addressing is used automatically.

Immediate

A literal number. If decoded as an address, it always points to address 0.

Indirect addressing

Indirect addressing looks into the a- or b-field (whichever is chosen by the specific address mode) of the nth instruction. This value is then used as a direct pointer to the instruction that will actually be used. Here is an example:

-1 | DAT #0, #4 ;  ---.
0  | MOV 0, @-1 ;     |
1  | ...        ;     | +4
2  | ...        ;     |
3  | MOV 0, @-1 ; <---'

When the MOV is executed, it looks at the b-field of instruction -1 (the DAT instruction). The value is 4. It then uses that as a pointer from the DAT instruction (not from the MOV!) to reach the actual destination instruction. In conclusion, the MOV copies itself to instruction 3 (4 ahead of the DAT).

Predecrement and Postincrement

If a predecrement or postincrement addressing mode is used, the intermediate value is either

  • decremented and then used as a pointer in the case of a predecrement.
  • used as a pointer and then incremented in the case of a postincrement.

Clone this wiki locally