From 9283b46a08a1c58c321b6c7ebad1353725c3bc47 Mon Sep 17 00:00:00 2001 From: hachem Date: Fri, 4 Sep 2026 20:00:52 +0200 Subject: 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. --- docs/language.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'docs') 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 ` 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: -- cgit v1.3