Skip to content

Commit

Permalink
EQU
Browse files Browse the repository at this point in the history
  • Loading branch information
gareththegeek committed Jul 4, 2018
1 parent 56f07a1 commit 13009b4
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/redcode/labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ When this program is parsed, the parser will replace all references to the label
DAT.F #4, #0
ADD.AB $-1, $-1 ; <- here bmb was replaced with -1
MOV.I $-2, @-2 ; <- here bmb was replaced with -2
JMP.B $-2 ; <- here top was replaced with -2
JMP.B $-2, $0 ; <- here top was replaced with -2
```

Notice that on the `add` instruction, the refence to `bmb` was replaced with `-1` since the `dat` instruction is one position above the `add` instruction. However on the `mov` instruction `bmb` was replaced with `-2` since the `dat` instruction is two positions above the `mov` instruction.
Expand Down
2 changes: 2 additions & 0 deletions docs/redcode/metadata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Metadata

14 changes: 7 additions & 7 deletions docs/redcode/org.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

By default, warriors are loaded into core with the first instruction as the starting instruction.

The `org` directive allows a different starting address to be specified. The `org` directive should be written on its own line and followed by an address indicating the start address relative to the first address in the warrior.
The `ORG` directive allows a different starting address to be specified. The `ORG` directive should be written on its own line and followed by an address indicating the start address relative to the first address in the warrior.

By convention, the `org` directive is usually placed at the top of the warrior's code.
By convention, the `ORG` directive is usually placed at the top of the warrior's code.

```
org 1
ORG 1
dat #4, #0
add.ab -1, -1
```

The above example uses the `org` directive to set the first instruction to the `add` instruction rather than the `dat` instruction.
The above example uses the `ORG` directive to set the first instruction to the `add` instruction rather than the `dat` instruction.

The `org` directive was introduced in the [ICWS'94](./#standards) standard. Previous standards used the `end` directive instead, which worked in the same way but was placed at the end of the warrior.
The `ORG` directive was introduced in the [ICWS'94](./#standards) standard. Previous standards used the `END` directive instead, which worked in the same way but was placed at the end of the warrior.

```
dat #4, #0
add.ab -1, -1
end 1
END 1
```

Note the `end` and `org` directives are semantically equivalent and either can be used.
Note the `END` and `ORG` directives are semantically equivalent and either can be used.

## Parser Warnings

Expand Down
71 changes: 70 additions & 1 deletion docs/redcode/preprocessor.md
Original file line number Diff line number Diff line change
@@ -1 +1,70 @@
# Preprocessor
# Preprocessor

A number of preprocessor directives can be used within redcode. These directives affect how the parser turns the source redcode into the load file.

Note these preprocessor directives are used a parse time and are not output directly into the parsed output itself.

## EQU

The `EQU` directive allows `constants` to be defined, which can then be referred to through out your code. This works in a similar way to [labels](labels). The difference is that you explicitly specify the value of these `constants` rather than being implicitly set based on where they are declared within the redcode.

The syntax for the `EQU` directive is as follows

```redcode
name EQU value
```

Constant names follow the same naming rules as labels (see [labels](labels) for details).

The value can be either a number, a label, one of the [special constants](#special-constants) or even a [mathematical expression](#mathematical-expressions) combining a mixture of these values.

### Literal Number Constant

Here is an example of using `EQU` to set a constant within the classic `dwarf`:

```redcode
step EQU 3044
ORG top
bmb: dat #step #step
top: add.ab bmb, bmb
mov bmb, @bmb
jmp top
```

The parsed output will look like this:

```redcode
ORG 1
DAT.F #3044, #3044
ADD.AB $-1, $-1
MOV.I $-2, @-2
JMP.B $-2, $0
```

Notice that all references to `step` have been replaced with the value of `step` i.e. `3044`.

### Label Constant

You can also use a `label` when declaring a `constant` using the `EQU` directive. When you do this, the parser first replaces all references to the constant within code with the `label` that the `constant` is equal to. After this substitution has been made, labels are replaced with their relative addresses in the normal way, see [labels](labels) for details.

```redcode
mybmb EQU bmb
ORG top
bmb: dat #step #step
top: add.ab mybmb, mybmb
mov mybmb, @mybmb
jmp top
```
Notice here that `mybmb` and `bmb` are equivalent.

## Mathematical Expressions



## Special constants



## FOR


1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ pages:
- Labels: redcode/labels.md
- Preprocessor: redcode/preprocessor.md
- Comments: redcode/comments.md
- Metadata: redcode/metadata.md
- Developer Reference: developer/index.md
theme: readthedocs

0 comments on commit 13009b4

Please sign in to comment.