diff options
Diffstat (limited to 'docs/language.md')
| -rw-r--r-- | docs/language.md | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/docs/language.md b/docs/language.md index 4de054f..3ccdab8 100644 --- a/docs/language.md +++ b/docs/language.md @@ -50,7 +50,7 @@ Unknown keys, a `bits` value other than 32/64, and unknown extensions are errors ## Constants and data -`const` names a constant integer expression — integer literals, character literals, other constants, and `+` `-` `*` `/`. Integers are decimal, `0x` hex, or `0b` binary (these forms work anywhere an integer does). `data` puts a string in `.data`; the name is its address and `.len` is its length in bytes. +`const` names a constant integer expression — integer literals, character literals, other constants, a leading `-`, and `+` `-` `*` `/`. Integers are decimal, `0x` hex, or `0b` binary (these forms work anywhere an integer does). `data` puts a string in `.data`; the name is its address and `.len` is its length in bytes. ```hdass const STDOUT = 1 @@ -138,7 +138,7 @@ if rax > rbx else if rax == rbx rdi = 0 else - rdi = 2 + rdi = -1 ``` ## Dereference (`^`) @@ -170,10 +170,20 @@ rcx = ^dword rsi // mov ecx, [rsi] (32-bit load zero-extends) rdx = ^rsi + 4 // load, then add 4 ``` +`^signed` before the size sign-extends instead, so a narrower value keeps its sign in the full register. It needs a `byte`, `word`, or `dword` size (a full-width load has nothing to extend): + +```hdass +rax = ^signed byte rsi // movsx rax, byte [rsi] +rbx = ^signed word rsi // movsx rbx, word [rsi] +rcx = ^signed dword rsi // movsxd rcx, dword [rsi] +``` + ## Expressions 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. +A leading `-` negates a term (`rax = -5`, `rbx = rax + -3`, `const OFFSET = -8`). It only applies to values that fold to a constant, so it emits a negative immediate; negating a register (`-rbx`) is not supported. + ## Extensions ### logical_registers |
