diff --git a/vm.md b/vm.md index 9f28924..4463349 100644 --- a/vm.md +++ b/vm.md @@ -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. * Addresses point to single bytes. +* Signed numbers use two's complement. | Type | Size (bits) | | - | - | @@ -43,23 +44,29 @@ CPU flags are addressed by bit index, going from right to left. ## 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 * **Params**: REG1, REG2 * `REG1 = REG1 + REG2` + * Unsigned addition * Mul * **Params**: REG1, REG2 * `REG1 = REG1 * REG2` + * Unsigned multiplication * Div * **Params**: REG1, REG2 * `REG1 = REG1 / REG2` + * Unsigned division * Mod * **Params**: REG1, REG2 * `REG1 = REG1 % REG2` (exact semantics TBD) -* Neg +* INeg * **Params**: REG1 * `REG1 = REG1 * -1` + * Signed negative * And * **Params**: REG1, REG2 * `REG1 = REG1 & REG2` @@ -76,6 +83,11 @@ Arithmetic instructions store their result in the first register specified. * **Params**: REG1, REG2 * `REG1 = REG1 >> REG2` +### TODO + +* Add signed instructions (iadd, imul, etc) +* Overflow flag? + ## Control flow * CmpEq