aboutsummaryrefslogtreecommitdiff
path: root/docs/language.md
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-08-31 16:24:28 +0200
committerhachem <im@hachem.wtf>2026-08-31 16:24:28 +0200
commitf8a2d02c75df62f74e5907696d5a99a024d59018 (patch)
tree7f374fb0e408ea2dab15dc628b7bb6b0cee0d9e8 /docs/language.md
parentcaf904c9a8a30a44fb3fca6df93e97c5cabdb0c0 (diff)
feat: codegen for * and / in expressions and /= on any register
Diffstat (limited to 'docs/language.md')
-rw-r--r--docs/language.md8
1 files changed, 5 insertions, 3 deletions
diff --git a/docs/language.md b/docs/language.md
index a2b4ffa..bfb41f3 100644
--- a/docs/language.md
+++ b/docs/language.md
@@ -78,8 +78,9 @@ Written by their architecture names — `rax`–`rdi`, `rbp`, `rsp`, `r8`–`r15
```hdass
rax = SYS_WRITE // mov
-rcx -= 1 // += -= *= /= -> add sub imul idiv (/= targets rax)
-rdx = buffer + 31 // address math with + and -
+rcx -= 1 // += -= *= /= -> add sub imul idiv
+rax = rbx * rcx // + - * / in a value; / and /= use rax:rdx (see Gotchas)
+rdx = buffer + 31 // address math
loop: // label
goto loop
if rcx != 0 // == != < <= > >= ; runs the next statement only
@@ -113,7 +114,7 @@ A leading size keyword sets the width explicitly. It down-converts a full regist
## Expressions
-Assignment values and `if` operands: registers, integers, chars (`'0'`), constants, data names, member access (`data.len`), and `+`/`-`. Multiply and divide come from the `*=` and `/=` compound assignments, not from `*`/`/` inside a value.
+Assignment values and `if` operands: registers, integers, chars (`'0'`), constants, data names, member access (`data.len`), and `+` `-` `*` `/`. Operators are left-associative and each right-hand operand must be a single term, so `a * b + c` works but `a + b * c` (a nested right operand) doesn't yet.
## Extensions
@@ -160,4 +161,5 @@ The [README](../README.md) has a Docker setup with these tools.
- **Clobbering is yours.** `syscall` trashes `rcx`/`r11`; a callee trashes what it touches. Nothing is saved for you — `examples/fibonacci.hdass` keeps its counter in `r15` for this reason.
- **Widths must match.** `rax = r1.8` becomes `mov rax, al`, which won't assemble.
+- **Division uses `rax:rdx`.** `/` and `/=` go through `idiv`, so they clobber `rax` and `rdx` regardless of the target, and the divisor can't be `rax`, `rdx`, or an immediate — put it in another register first.
- **The entry procedure has no `ret`** — end it with an exit syscall. \ No newline at end of file