diff options
| author | hachem <im@hachem.wtf> | 2026-09-04 20:00:52 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-09-04 20:00:52 +0200 |
| commit | 9283b46a08a1c58c321b6c7ebad1353725c3bc47 (patch) | |
| tree | 5fba917f42bdbaf86f27abc01577b3c1b232e409 /docs | |
| parent | 56ba8b2a373dd1386950592bda9c68ff9f25c203 (diff) | |
feat: add if/else blocks
if now guards a { } block or bare statement with an optional else (and
now else-if chaining). The branch body becomes a statement list; a bare
guarded statement is a list of length one.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/language.md | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/docs/language.md b/docs/language.md index d77ca72..4de054f 100644 --- a/docs/language.md +++ b/docs/language.md @@ -118,13 +118,29 @@ rax = rbx * rcx // + - * / % in a value; / % and their = forms use rax:rdx rdx = buffer + 31 // address math loop: // label goto loop -if rcx != 0 // == != < <= > >= ; runs the next statement only +if rcx != 0 // == != < <= > >= ; guards the next statement or a { block } goto loop syscall print_number(r12) // call; args go into the callee's parameter registers stack buf[Point.size] // stack buffer (size is any constant); buf is its base address ``` +## Branching (`if` / `else`) + +`if <expr> <cmp> <expr>` guards either the single next statement or a `{ }` block, and an optional `else` takes its own statement or block. `else if` chains because the `else` body is itself a statement. Comparisons are `==` `!=` `<` `<=` `>` `>=`; a float compare needs an `xmm` register on the left (see [Floating point](#floating-point)). + +```hdass +if rax > rbx +{ + rdi = 1 + goto done +} +else if rax == rbx + rdi = 0 +else + rdi = 2 +``` + ## Dereference (`^`) `^reg` is the memory at the address in `reg` — NASM's `[reg]`. On the left of `=` it stores there. The store width comes from the value operand, so a sized sub-register picks the size: |
