-
Notifications
You must be signed in to change notification settings - Fork 0
Redcode
- 84 spec
- 94 spec + reference implementation
- Book: The Armchair Universe: an exploration of computer worlds
- 94 spec guide
- Krieg der Kerne: Handbuch für Einsteiger (German)
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.
@-2and destination field (e.g.#3):- Each made up of an address mode (like
@or#) followed by a number. - The comma separator is necessary!
- Each made up of an address mode (like
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 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.
A literal number. If decoded as an address, it always points to address 0.
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).
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.