aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-08-30 00:39:55 +0200
committerhachem <im@hachem.wtf>2026-08-30 00:39:55 +0200
commitcd04e59647a9440e6b362b3a46b36f46bf2b2576 (patch)
tree14a5182dfc421ed0339e2986241c6328fa0f6389 /examples
parentb419298e454ad3d035ac8ab7c60dc58420f8af07 (diff)
setup: prepare docker and build system
Diffstat (limited to 'examples')
-rw-r--r--examples/fibonacci.hdasm60
-rw-r--r--examples/hello_world.hdass19
2 files changed, 79 insertions, 0 deletions
diff --git a/examples/fibonacci.hdasm b/examples/fibonacci.hdasm
new file mode 100644
index 0000000..b044d84
--- /dev/null
+++ b/examples/fibonacci.hdasm
@@ -0,0 +1,60 @@
+const SYS_WRITE = 1
+const SYS_EXIT = 60
+
+const STDOUT = 1
+
+data newline = "\n"
+
+proc print_number(value: rdi)
+{
+ stack buffer[32]
+
+ rax = value
+ rbx = 10
+ rsi = buffer+31
+
+convert:
+ rdx = 0
+ rax /= rbx
+ rdx += '0'
+
+ ^rsi = rdx
+ rsi -= 1
+
+ if rax != 0
+ goto convert
+ rsi += 1
+
+ rax = SYS_WRITE
+ rdi = STDOUT
+ rdx = buffer+32-rsi
+ syscall
+
+ rax = SYS_WRITE
+ rdi = STDOUT
+ rsi = newline
+ rdx = newline.len
+ syscall
+}
+
+proc main
+{
+ r12 = 0
+ r13 = 1
+ rcx = 10
+
+loop:
+ print_number(r12)
+
+ rax = r12
+ r12 = r13
+ r13 += rax
+
+ rcx -= 1
+ if rcx != 0
+ goto loop
+
+ rax = SYS_EXIT
+ rdi = 0
+ syscall
+}
diff --git a/examples/hello_world.hdass b/examples/hello_world.hdass
new file mode 100644
index 0000000..59dac80
--- /dev/null
+++ b/examples/hello_world.hdass
@@ -0,0 +1,19 @@
+const SYS_WRITE = 1
+const SYS_EXIT = 60
+
+const STDOUT = 1
+
+data message = "Hello, World!\n"
+
+proc main
+{
+ rax = SYS_WRITE
+ rdi = STDOUT
+ rsi = message
+ rdx = message.len
+ syscall
+
+ rax = SYS_EXIT
+ rdi = 0
+ syscall
+}