Page namespace (page_namespace) | 0 |
Page title (without namespace) (page_title) | 'SIC-1 Assembly Language' |
Full page title (page_prefixedtitle) | 'SIC-1 Assembly Language' |
Old content model (old_content_model) | '' |
New content model (new_content_model) | 'wikitext' |
Old page wikitext, before the edit (old_wikitext) | '' |
New page wikitext, after the edit (new_wikitext) | ''''SIC-1 Assembly Language''' is the primary (and, currently, only) language used for programming SIC Systems's '''Single-Instruction Computer, Mark 1 (SIC-1)'''. The SIC-1 is a fictional 8-bit computer used in a web-based programming game (of the same name--see [[#External Resources]] for a link) that, as its name implies, only supports a single instruction: '''subleq''' (subtract and branch if less than or equal to zero).
==Language Overview==
{| class="wikitable"
!Command
!Description
|-
| style="text-align:center"| <code>subleq A B [C]</code>
|mem[A] = mem[A] - mem[B]; branch to C if result <= 0
|-
| style="text-align:center"| <code>@label</code>
|Associates a label with the address of the following command
|-
| style="text-align:center"| .data X
|Sets the next byte of memory to a value at compile time
|}
Note that if the third address (C) for '''subleq''' is omitted, the address of the next instruction is used (in other words, the branch would have no noticeable effect).
===Binary representation and offsets===
Each '''subleq A B C''' instruction is stored as 3 consecutive addresses (each one byte): ABC.
When referring to a label, you can include an offset (specified in bytes), e.g. <code>@label+1</code>. See the self-modifying code example for a practical application of this.
===Built-in labels===
The following predefined lables are always available:
* '''@MAX''' (252): Maximum user-modifiable address
* '''@IN''' (253): Reads a value from input (writes are ignored)
* '''@OUT''' (254): Writes a result to output (reads as zero)
* '''@HALT''' (255): Terminates the program when executed
==Examples==
===Negation===
This program negates one input value and outputs the negated value.
subleq @OUT, @IN
===Continuous negation===
This program reads values, negates them, and outputs them in an infinite loop.
@loop:
subleq @OUT, @IN
subleq @zero, @zero, @loop
@zero: .data 0
===Self-modifying/referencing code===
The sample program below reads its own compiled code and outputs it by incrementing the second address of the instruction at @loop (i.e. modifying address @loop+1).
@loop:
subleq @tmp, 0 ; Second address (initially zero) will be incremented
subleq @OUT, @tmp ; Output the value
subleq @loop+1, @n_one ; Here is where the increment is performed
subleq @tmp, @tmp, @loop
@tmp: .data 0
@n_one: .data -1
==External Resources==
* SIC-1 programming game: https://jaredkrinke.itch.io/sic-1' |
Unified diff of changes made by edit (edit_diff) | '@@ -1,0 +1,60 @@
+'''SIC-1 Assembly Language''' is the primary (and, currently, only) language used for programming SIC Systems's '''Single-Instruction Computer, Mark 1 (SIC-1)'''. The SIC-1 is a fictional 8-bit computer used in a web-based programming game (of the same name--see [[#External Resources]] for a link) that, as its name implies, only supports a single instruction: '''subleq''' (subtract and branch if less than or equal to zero).
+
+==Language Overview==
+{| class="wikitable"
+!Command
+!Description
+|-
+| style="text-align:center"| <code>subleq A B [C]</code>
+|mem[A] = mem[A] - mem[B]; branch to C if result <= 0
+|-
+| style="text-align:center"| <code>@label</code>
+|Associates a label with the address of the following command
+|-
+| style="text-align:center"| .data X
+|Sets the next byte of memory to a value at compile time
+|}
+
+Note that if the third address (C) for '''subleq''' is omitted, the address of the next instruction is used (in other words, the branch would have no noticeable effect).
+
+===Binary representation and offsets===
+Each '''subleq A B C''' instruction is stored as 3 consecutive addresses (each one byte): ABC.
+
+When referring to a label, you can include an offset (specified in bytes), e.g. <code>@label+1</code>. See the self-modifying code example for a practical application of this.
+
+===Built-in labels===
+The following predefined lables are always available:
+
+* '''@MAX''' (252): Maximum user-modifiable address
+* '''@IN''' (253): Reads a value from input (writes are ignored)
+* '''@OUT''' (254): Writes a result to output (reads as zero)
+* '''@HALT''' (255): Terminates the program when executed
+
+==Examples==
+===Negation===
+This program negates one input value and outputs the negated value.
+ subleq @OUT, @IN
+
+===Continuous negation===
+This program reads values, negates them, and outputs them in an infinite loop.
+
+ @loop:
+ subleq @OUT, @IN
+ subleq @zero, @zero, @loop
+
+ @zero: .data 0
+
+===Self-modifying/referencing code===
+The sample program below reads its own compiled code and outputs it by incrementing the second address of the instruction at @loop (i.e. modifying address @loop+1).
+
+ @loop:
+ subleq @tmp, 0 ; Second address (initially zero) will be incremented
+ subleq @OUT, @tmp ; Output the value
+ subleq @loop+1, @n_one ; Here is where the increment is performed
+ subleq @tmp, @tmp, @loop
+
+ @tmp: .data 0
+ @n_one: .data -1
+
+==External Resources==
+* SIC-1 programming game: https://jaredkrinke.itch.io/sic-1
' |
Lines added in edit (added_lines) | [
0 => ''''SIC-1 Assembly Language''' is the primary (and, currently, only) language used for programming SIC Systems's '''Single-Instruction Computer, Mark 1 (SIC-1)'''. The SIC-1 is a fictional 8-bit computer used in a web-based programming game (of the same name--see [[#External Resources]] for a link) that, as its name implies, only supports a single instruction: '''subleq''' (subtract and branch if less than or equal to zero).',
1 => '',
2 => '==Language Overview==',
3 => '{| class="wikitable"',
4 => '!Command',
5 => '!Description',
6 => '|-',
7 => '| style="text-align:center"| <code>subleq A B [C]</code>',
8 => '|mem[A] = mem[A] - mem[B]; branch to C if result <= 0',
9 => '|-',
10 => '| style="text-align:center"| <code>@label</code>',
11 => '|Associates a label with the address of the following command',
12 => '|-',
13 => '| style="text-align:center"| .data X',
14 => '|Sets the next byte of memory to a value at compile time',
15 => '|}',
16 => '',
17 => 'Note that if the third address (C) for '''subleq''' is omitted, the address of the next instruction is used (in other words, the branch would have no noticeable effect).',
18 => '',
19 => '===Binary representation and offsets===',
20 => 'Each '''subleq A B C''' instruction is stored as 3 consecutive addresses (each one byte): ABC.',
21 => '',
22 => 'When referring to a label, you can include an offset (specified in bytes), e.g. <code>@label+1</code>. See the self-modifying code example for a practical application of this.',
23 => '',
24 => '===Built-in labels===',
25 => 'The following predefined lables are always available:',
26 => '',
27 => '* '''@MAX''' (252): Maximum user-modifiable address',
28 => '* '''@IN''' (253): Reads a value from input (writes are ignored)',
29 => '* '''@OUT''' (254): Writes a result to output (reads as zero)',
30 => '* '''@HALT''' (255): Terminates the program when executed',
31 => '',
32 => '==Examples==',
33 => '===Negation===',
34 => 'This program negates one input value and outputs the negated value.',
35 => ' subleq @OUT, @IN',
36 => '',
37 => '===Continuous negation===',
38 => 'This program reads values, negates them, and outputs them in an infinite loop.',
39 => '',
40 => ' @loop:',
41 => ' subleq @OUT, @IN',
42 => ' subleq @zero, @zero, @loop',
43 => ' ',
44 => ' @zero: .data 0',
45 => '',
46 => '===Self-modifying/referencing code===',
47 => 'The sample program below reads its own compiled code and outputs it by incrementing the second address of the instruction at @loop (i.e. modifying address @loop+1).',
48 => '',
49 => ' @loop:',
50 => ' subleq @tmp, 0 ; Second address (initially zero) will be incremented',
51 => ' subleq @OUT, @tmp ; Output the value',
52 => ' subleq @loop+1, @n_one ; Here is where the increment is performed',
53 => ' subleq @tmp, @tmp, @loop',
54 => ' ',
55 => ' @tmp: .data 0',
56 => ' @n_one: .data -1',
57 => '',
58 => '==External Resources==',
59 => '* SIC-1 programming game: https://jaredkrinke.itch.io/sic-1'
] |