aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-08-31 00:19:10 +0200
committerhachem <im@hachem.wtf>2026-08-31 00:19:10 +0200
commit3e20038bbf7206e2270655418d7884ccfe91a4e4 (patch)
treedfc7bf806a00c1dbec6c889351c108702a0e9d40 /examples
parent8eac30c13cfa4f47a8a0aa0772b96f0813fe33a5 (diff)
add directives and directive based entry points
Diffstat (limited to 'examples')
-rw-r--r--examples/arithmetic.hdass2
-rw-r--r--examples/branch.hdass2
-rw-r--r--examples/call.hdass2
-rw-r--r--examples/exit_code.hdass2
-rw-r--r--examples/fibonacci.hdasm8
-rw-r--r--examples/greet.hdass2
-rw-r--r--examples/hello_world.hdass2
-rw-r--r--examples/loop_sum.hdass2
8 files changed, 19 insertions, 3 deletions
diff --git a/examples/arithmetic.hdass b/examples/arithmetic.hdass
index 359653e..1534146 100644
--- a/examples/arithmetic.hdass
+++ b/examples/arithmetic.hdass
@@ -1,3 +1,5 @@
+[entry: main]
+
// Computes (5 + 3) * 2 - 1 = 15 and returns it as the exit status.
const SYS_EXIT = 60
diff --git a/examples/branch.hdass b/examples/branch.hdass
index 1218773..15f8d1b 100644
--- a/examples/branch.hdass
+++ b/examples/branch.hdass
@@ -1,3 +1,5 @@
+[entry: main]
+
// Returns the larger of two values (max(3, 8) = 8) as the exit status.
const SYS_EXIT = 60
diff --git a/examples/call.hdass b/examples/call.hdass
index 239a26b..bf0c515 100644
--- a/examples/call.hdass
+++ b/examples/call.hdass
@@ -1,3 +1,5 @@
+[entry: main]
+
// Passes an argument through a proc parameter, which exits with that value.
const SYS_EXIT = 60
diff --git a/examples/exit_code.hdass b/examples/exit_code.hdass
index 7c44df9..cabe634 100644
--- a/examples/exit_code.hdass
+++ b/examples/exit_code.hdass
@@ -1,3 +1,5 @@
+[entry: main]
+
// Exits with status 42 and no output.
const SYS_EXIT = 60
diff --git a/examples/fibonacci.hdasm b/examples/fibonacci.hdasm
index 58f71fe..95a59c8 100644
--- a/examples/fibonacci.hdasm
+++ b/examples/fibonacci.hdasm
@@ -1,3 +1,5 @@
+[entry: main]
+
const SYS_WRITE = 1
const SYS_EXIT = 60
@@ -41,7 +43,7 @@ proc main
{
r12 = 0
r13 = 1
- rcx = 10
+ r15 = 10 // syscall clobbers rcx/r11, so keep the counter in r15
loop:
print_number(r12)
@@ -50,8 +52,8 @@ loop:
r12 = r13
r13 += rax
- rcx -= 1
- if rcx != 0
+ r15 -= 1
+ if r15 != 0
goto loop
rax = SYS_EXIT
diff --git a/examples/greet.hdass b/examples/greet.hdass
index a253b5e..da9f790 100644
--- a/examples/greet.hdass
+++ b/examples/greet.hdass
@@ -1,3 +1,5 @@
+[entry: main]
+
// Writes a fixed string to stdout, then exits cleanly.
const SYS_WRITE = 1
const SYS_EXIT = 60
diff --git a/examples/hello_world.hdass b/examples/hello_world.hdass
index 59dac80..da6b2b5 100644
--- a/examples/hello_world.hdass
+++ b/examples/hello_world.hdass
@@ -1,3 +1,5 @@
+[entry: main]
+
const SYS_WRITE = 1
const SYS_EXIT = 60
diff --git a/examples/loop_sum.hdass b/examples/loop_sum.hdass
index bb8d115..5976914 100644
--- a/examples/loop_sum.hdass
+++ b/examples/loop_sum.hdass
@@ -1,3 +1,5 @@
+[entry: main]
+
// Sums 5 + 4 + 3 + 2 + 1 = 15 with a countdown loop, returns it as the status.
const SYS_EXIT = 60