From cd04e59647a9440e6b362b3a46b36f46bf2b2576 Mon Sep 17 00:00:00 2001 From: hachem Date: Sun, 30 Aug 2026 00:39:55 +0200 Subject: setup: prepare docker and build system --- examples/fibonacci.hdasm | 60 ++++++++++++++++++++++++++++++++++++++++++++++ examples/hello_world.hdass | 19 +++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 examples/fibonacci.hdasm create mode 100644 examples/hello_world.hdass (limited to 'examples') 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 +} -- cgit v1.3