Add a few notes about numbers and arithmetic, rename Neg -> INeg

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-01-26 10:59:25 -05:00
parent df950c6f63
commit 6c96adddff

16
vm.md
View File

@@ -6,6 +6,7 @@ This is an outline of the VM that drives this language.
* Numbers may be big endian (BE) or little endian (LE) at the byte level. This guide will use LE. * Numbers may be big endian (BE) or little endian (LE) at the byte level. This guide will use LE.
* Addresses point to single bytes. * Addresses point to single bytes.
* Signed numbers use two's complement.
| Type | Size (bits) | | Type | Size (bits) |
| - | - | | - | - |
@@ -43,23 +44,29 @@ CPU flags are addressed by bit index, going from right to left.
## Arithmetic ## Arithmetic
Arithmetic instructions store their result in the first register specified. Arithmetic instructions store their result in the first register specified. Overflow is handled by
wrapping around to 0.
* Add * Add
* **Params**: REG1, REG2 * **Params**: REG1, REG2
* `REG1 = REG1 + REG2` * `REG1 = REG1 + REG2`
* Unsigned addition
* Mul * Mul
* **Params**: REG1, REG2 * **Params**: REG1, REG2
* `REG1 = REG1 * REG2` * `REG1 = REG1 * REG2`
* Unsigned multiplication
* Div * Div
* **Params**: REG1, REG2 * **Params**: REG1, REG2
* `REG1 = REG1 / REG2` * `REG1 = REG1 / REG2`
* Unsigned division
* Mod * Mod
* **Params**: REG1, REG2 * **Params**: REG1, REG2
* `REG1 = REG1 % REG2` (exact semantics TBD) * `REG1 = REG1 % REG2` (exact semantics TBD)
* Neg * INeg
* **Params**: REG1 * **Params**: REG1
* `REG1 = REG1 * -1` * `REG1 = REG1 * -1`
* Signed negative
* And * And
* **Params**: REG1, REG2 * **Params**: REG1, REG2
* `REG1 = REG1 & REG2` * `REG1 = REG1 & REG2`
@@ -76,6 +83,11 @@ Arithmetic instructions store their result in the first register specified.
* **Params**: REG1, REG2 * **Params**: REG1, REG2
* `REG1 = REG1 >> REG2` * `REG1 = REG1 >> REG2`
### TODO
* Add signed instructions (iadd, imul, etc)
* Overflow flag?
## Control flow ## Control flow
* CmpEq * CmpEq