From 6c96adddffda04d6955dbe5870d4e41b893c4afa Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Sun, 26 Jan 2020 10:59:25 -0500 Subject: [PATCH] Add a few notes about numbers and arithmetic, rename Neg -> INeg Signed-off-by: Alek Ratzloff --- vm.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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