about summary refs log tree commit diff stats
path: root/subx/examples/ex1.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-09-30 20:59:21 -0700
committerKartik Agaram <vc@akkartik.com>2018-09-30 20:59:21 -0700
commitb515f3b70417c502991e3c6443badf32cded6a20 (patch)
tree603d4e51c29a6db6ec37f46fd073f55aff3b01d4 /subx/examples/ex1.subx
parent16db2a2fde06be9641cc90a57029aaadb754edc3 (diff)
downloadmu-b515f3b70417c502991e3c6443badf32cded6a20.tar.gz
4622
When I started SubX I imagined that being able to write machine code directly
was a feature. Now it's just a hole I haven't bothered closing yet.
Diffstat (limited to 'subx/examples/ex1.subx')
-rw-r--r--subx/examples/ex1.subx20
1 files changed, 20 insertions, 0 deletions
diff --git a/subx/examples/ex1.subx b/subx/examples/ex1.subx
new file mode 100644
index 00000000..a355ef6b
--- /dev/null
+++ b/subx/examples/ex1.subx
@@ -0,0 +1,20 @@
+## first program: same as https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html
+# Just return 42.
+#
+# To run:
+#   $ subx translate ex1.2.subx ex1
+#   $ subx run ex1
+# Expected result:
+#   $ echo $?
+#   42
+
+== code
+# instruction                     effective address                                                   operand     displacement    immediate
+# op          subop               mod             rm32          base        index         scale       r32
+# 1-3 bytes   3 bits              2 bits          3 bits        3 bits      3 bits        2 bits      2 bits      0/1/2/4 bytes   0/1/2/4 bytes
+  bb/copy                                                                                                                         2a/imm32          # copy 42 to EBX
+  # exit(EBX)
+  b8/copy                                                                                                                         1/imm32           # copy 1 to EAX
+  cd/syscall  0x80/imm8
+
+# vim:ft=subx