aboutsummaryrefslogtreecommitdiff
path: root/examples/spec_example.asm
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-11-25 18:20:15 +0000
committerDimitri Sokolyuk <demon@dim13.org>2015-11-25 18:20:15 +0000
commit76369877147e77c24e6b56f4a166922959c2f149 (patch)
tree4baf650be4971f0577c4a363629099aeddb5a462 /examples/spec_example.asm
parent4592509f18e44d6302fe3fd7ad69974beb00b749 (diff)
Add examples
Diffstat (limited to 'examples/spec_example.asm')
-rw-r--r--examples/spec_example.asm30
1 files changed, 30 insertions, 0 deletions
diff --git a/examples/spec_example.asm b/examples/spec_example.asm
new file mode 100644
index 0000000..f5f86de
--- /dev/null
+++ b/examples/spec_example.asm
@@ -0,0 +1,30 @@
+; example from Notch's spec for DCPU-16
+
+; Try some basic stuff
+ SET A, 0x30 ; 7c01 0030
+ SET [0x1000], 0x20 ; 7de1 1000 0020
+ SUB A, [0x1000] ; 7803 1000
+ IFN A, 0x10 ; c00d
+ SET PC, crash ; 7dc1 001a [*]
+
+; Do a loopy thing
+ SET I, 10 ; a861
+ SET A, 0x2000 ; 7c01 2000
+:loop SET [0x2000+I], [A] ; 2161 2000
+ SUB I, 1 ; 8463
+ IFN I, 0 ; 806d
+ SET PC, loop ; 7dc1 000d [*]
+
+; Call a subroutine
+ SET X, 0x4 ; 9031
+ JSR testsub ; 7c10 0018 [*]
+ SET PC, crash ; 7dc1 001a [*]
+
+:testsub SHL X, 4 ; 9037
+ SET PC, POP ; 61c1
+
+; Hang forever. X should now be 0x40 if everything went right.
+:crash SET PC, crash ; 7dc1 001a [*]
+
+; [*]: Note that these can be one word shorter and one cycle faster by using the short form (0x00-0x1f) of literals,
+; but my assembler doesn't support short form labels yet.