aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/language.md18
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: