diff options
| author | hachem <im@hachem.wtf> | 2026-09-18 19:47:35 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-09-18 19:47:35 +0200 |
| commit | c0f000ea166a24781fcdbf23c080b203cd9b8ed7 (patch) | |
| tree | 827b8b3875c60791d092615ce6f87d3c56de8676 /docs/targets.md | |
| parent | 197b07e69f9ed851f9c94eb40927f3202a239386 (diff) | |
Diffstat (limited to 'docs/targets.md')
| -rw-r--r-- | docs/targets.md | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/docs/targets.md b/docs/targets.md index c54636b..70259ea 100644 --- a/docs/targets.md +++ b/docs/targets.md @@ -1,66 +1,66 @@ -# Targets +# targets hdass separates two things that assemblers usually tangle together: - the **architecture** — which instructions exist and how registers work; - the **assembler syntax** — how those instructions are written to a file. -A target is a pairing of the two, chosen with `-t`: +a target is a pairing of the two, chosen with `-t`: | `-t` | architecture | assembler | notes | | --- | --- | --- | --- | -| `nasm` (default) | x86-64 | NASM | Intel syntax, `nasm -f elf64` | -| `fasm` | x86-64 | fasm | Intel syntax, `fasm` (one step) | -| `arm64` | AArch64 | GNU as | `aarch64-linux-gnu-as` | +| `nasm` (default) | x86-64 | nasm | intel syntax, `nasm -f elf64` | +| `fasm` | x86-64 | fasm | intel syntax, `fasm` (one step) | +| `arm64` | aarch64 | gnu as | `aarch64-linux-gnu-as` | -For x86-64, `nasm` and `fasm` emit the **same instruction bodies** and differ only +for x86-64, `nasm` and `fasm` emit the **same instruction bodies** and differ only in framing (file header, sections, constant and data syntax). `arm64` is a separate instruction selector: different registers, three-operand arithmetic, `ldr`/`str` memory, `cmp`+`b.cond` branches and `svc #0` syscalls. `masm` (x86-64) and a 32-bit `arm` target are planned. -## What each architecture supports +## what each architecture supports -The language is the same; not every construct lowers on every architecture yet. +the language is the same; not every construct lowers on every architecture yet. -| Feature | x86-64 | AArch64 | +| feature | x86-64 | aarch64 | | --- | --- | --- | -| Moves, arithmetic (`+ - * /`), compound assignment | ✅ | ✅ | +| moves, arithmetic (`+ - * /`), compound assignment | ✅ | ✅ | | `if` / `else` / `while`, `goto`, labels | ✅ | ✅ | -| Conditional select (`a if c else b`) | ✅ `cmov` | ✅ `csel` | -| Calls, `syscall` | ✅ | ✅ | -| Memory load/store (`^`), sized and signed | ✅ | partial (`ldr`/`str`) | -| Raw instruction statement | ✅ | ✅ | -| Modulo (`%`), division remainder | ✅ | ❌ not yet | -| Floating point (`xmm`) | ✅ | ❌ not yet | +| conditional select (`a if c else b`) | ✅ `cmov` | ✅ `csel` | +| calls, `syscall` | ✅ | ✅ | +| memory load/store (`^`), sized and signed | ✅ | partial (`ldr`/`str`) | +| raw instruction statement | ✅ | ✅ | +| modulo (`%`), division remainder | ✅ | ❌ not yet | +| floating point (`xmm`) | ✅ | ❌ not yet | | `stack` buffers | ✅ | ❌ not yet | -| Bare-metal directives (`format`, `org`, `boot`, `bits 16`) | ✅ | — (x86/BIOS concept) | +| bare-metal directives (`format`, `org`, `boot`, `bits 16`) | ✅ | — (x86/bios concept) | -Unsupported constructs emit a `; TODO` comment instead of incorrect instructions. +unsupported constructs emit a `; TODO` comment instead of incorrect instructions. -## The portable register model +## the portable register model -Architecture-native register names (`rax` on x86-64, `x0` on AArch64) lock a -program to one architecture. To write for both, enable +architecture-native register names (`rax` on x86-64, `x0` on aarch64) lock a +program to one architecture. to write for both, enable [`logical_registers`](language.md#logical_registers): `r1`–`r14` are the general-purpose registers, mapped per target. | logical | `r1` | `r2` | `r3` | `r4` | `r5` | `r6` | `r7` | `r8` | `r9` | `r10` | … | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | x86-64 | rax | rbx | rcx | rdx | rsi | rdi | r8 | r9 | r10 | r11 | … | -| AArch64 | x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7 | x8 | x9 | … | +| aarch64 | x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7 | x8 | x9 | … | -AArch64 is simply `rN → x(N-1)`. The raw [instruction statement](language.md#raw-instructions) +aarch64 is simply `rN → x(N-1)`. the raw [instruction statement](language.md#raw-instructions) is architecture-locked too: its mnemonics are whatever you write. -## Syscall ABIs differ +## syscall abis differ -Even with logical registers, a *syscall* is not portable: Linux uses different -call numbers, argument registers and trap instructions per architecture. So a -program still carries architecture-specific ABI constants. +even with logical registers, a *syscall* is not portable: linux uses different +call numbers, argument registers and trap instructions per architecture. so a +program still carries architecture-specific abi constants. -| | x86-64 | AArch64 | +| | x86-64 | aarch64 | | --- | --- | --- | | syscall number in | `rax` (logical `r1`) | `x8` (logical `r9`) | | arguments in | `rdi rsi rdx r10 r8 r9` | `x0 x1 x2 x3 x4 x5` | @@ -68,10 +68,10 @@ program still carries architecture-specific ABI constants. | `exit` number | `60` | `93` | | `write` number | `1` | `64` | -C works the same way: portable source, per-platform syscalls. +c works the same way: portable source, per-platform syscalls. -## OS independence +## os independence -The emitted instructions aren't tied to an OS; only the syscall numbers and the -`[entry]`/link convention are. The examples and toolchain here target Linux (ELF, -`ld`, and `qemu-aarch64` for ARM); see [getting started](getting-started.md). +the emitted instructions aren't tied to an os; only the syscall numbers and the +`[entry]`/link convention are. the examples and toolchain here target linux (elf, +`ld`, and `qemu-aarch64` for arm); see [getting started](getting-started.md). |
