diff options
| author | hachem <im@hachem.wtf> | 2026-08-31 19:58:56 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-08-31 19:58:56 +0200 |
| commit | 5b06b0e4b8effaacd23308d6a6b26c525e7d3af4 (patch) | |
| tree | 351155777028e604845d3dfec27d3caf3b22257f /examples/records.hdass | |
| parent | cbdb9073480c3e4d8a088b306c23406cf42e25c0 (diff) | |
feat: add enums and structs
Diffstat (limited to 'examples/records.hdass')
| -rw-r--r-- | examples/records.hdass | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/examples/records.hdass b/examples/records.hdass new file mode 100644 index 0000000..9800839 --- /dev/null +++ b/examples/records.hdass @@ -0,0 +1,42 @@ +[entry: main] + +// An enum of status codes and a struct describing a memory layout. Stores two +// fields into a stack instance, reads them back, and exits with their sum. +enum Status +{ + Ok, + Warn, + Fail +} + +struct Pair +{ + a: qword + b: qword +} + +const SYS_EXIT = 60 + +proc main +{ + stack pair[16] // Pair.size + + rsi = pair + rbx = 40 + ^rsi = rbx // pair.a (offset 0) + + rsi = pair + rsi += Pair.b + rcx = Status.Fail // 2 + ^rsi = rcx // pair.b (offset 8) + + rsi = pair + rdi = ^rsi // load a = 40 + rsi = pair + rsi += Pair.b + rax = ^rsi // load b = 2 + rdi += rax // 42 + + rax = SYS_EXIT + syscall +} |
