diff --git a/vm.md b/vm.md index 309894d..5cdbfd5 100644 --- a/vm.md +++ b/vm.md @@ -61,37 +61,101 @@ wrapping around to 0. * **Params**: REG1, REG2 * `REG1 = REG1 + REG2` * Unsigned addition + * ``` + 32 16 10 4 0 + opcode reg1 reg2 unused + / / / / + +-------------------------------------------+ + | 0000000000000000 | ...... | ...... | XXXX | + +-------------------------------------------+ + ``` * Mul * Opcode: 0x0001 * **Params**: REG1, REG2 * `REG1 = REG1 * REG2` * Unsigned multiplication + * ``` + 32 16 10 4 0 + opcode reg1 reg2 unused + / / / / + +-------------------------------------------+ + | 0000000000000001 | ...... | ...... | XXXX | + +-------------------------------------------+ + ``` * Div * Opcode: 0x0002 * **Params**: REG1, REG2 * `REG1 = REG1 / REG2` * Unsigned division + * ``` + 32 16 10 4 0 + opcode reg1 reg2 unused + / / / / + +-------------------------------------------+ + | 0000000000000010 | ...... | ...... | XXXX | + +-------------------------------------------+ + ``` * Mod * Opcode: 0x0003 * **Params**: REG1, REG2 * `REG1 = REG1 % REG2` (exact semantics TBD) + * ``` + 32 16 10 4 0 + opcode reg1 reg2 unused + / / / / + +-------------------------------------------+ + | 0000000000000011 | ...... | ...... | XXXX | + +-------------------------------------------+ + ``` * INeg * Opcode: 0x0004 * **Params**: REG1 * `REG1 = REG1 * -1` * Signed negative + * ``` + 32 16 10 0 + opcode reg1 unused + / / / + +----------------------------------------+ + | 0000000000000100 | ...... | XXXXXXXXXX | + +----------------------------------------+ + ``` * And * Opcode: 0x0005 * **Params**: REG1, REG2 * `REG1 = REG1 & REG2` + * ``` + 32 16 10 4 0 + opcode reg1 reg2 unused + / / / / + +-------------------------------------------+ + | 0000000000000101 | ...... | ...... | XXXX | + +-------------------------------------------+ + ``` * Or * Opcode: 0x0006 * **Params**: REG1, REG2 * `REG1 = REG1 | REG2` + * ``` + 32 16 10 4 0 + opcode reg1 reg2 unused + / / / / + +-------------------------------------------+ + | 0000000000000110 | ...... | ...... | XXXX | + +-------------------------------------------+ + ``` * Inv * Opcode: 0x0007 * **Params**: REG1 * `REG1 = ~REG1` + * ``` + 32 16 10 0 + opcode reg1 unused + / / / + +----------------------------------------+ + | 0000000000000111 | ...... | XXXXXXXXXX | + +----------------------------------------+ + ``` * Not * Opcode: 0x0008 * **Params**: REG1 @@ -103,19 +167,51 @@ wrapping around to 0. } ``` * Boolean NOT; equivalent of C's `!` unary operator + * ``` + 32 16 10 0 + opcode reg1 unused + / / / + +----------------------------------------+ + | 0000000000001000 | ...... | XXXXXXXXXX | + +----------------------------------------+ + ``` * Xor * Opcode: 0x0009 * **Params**: REG1, REG2 * `REG1 = REG1 ^ REG2` + * ``` + 32 16 10 4 0 + opcode reg1 reg2 unused + / / / / + +-------------------------------------------+ + | 0000000000001001 | ...... | ...... | XXXX | + +-------------------------------------------+ + ``` * Shl * Opcode: 0x000A * **Params**: REG1, REG2 * `REG1 = REG1 << REG2` + * ``` + 32 16 10 4 0 + opcode reg1 reg2 unused + / / / / + +-------------------------------------------+ + | 0000000000001010 | ...... | ...... | XXXX | + +-------------------------------------------+ + ``` * Shr * Opcode: 0x000B * **Params**: REG1, REG2 * `REG1 = REG1 >> REG2` * Does not sign extend + * ``` + 32 16 10 4 0 + opcode reg1 reg2 unused + / / / / + +-------------------------------------------+ + | 0000000000001011 | ...... | ...... | XXXX | + +-------------------------------------------+ + ``` ### TODO @@ -136,6 +232,14 @@ wrapping around to 0. } ``` * Sets the COMPARE flag to 1 if REG1 == REG2 + * ``` + 32 16 10 4 0 + opcode reg1 reg2 unused + / / / / + +-------------------------------------------+ + | 0001000000000000 | ...... | ...... | XXXX | + +-------------------------------------------+ + ``` * CmpLt * Opcode: 0x1001 * **Params**: REG1, REG2 @@ -147,17 +251,47 @@ wrapping around to 0. } ``` * Sets the COMPARE flag to 1 if REG1 < REG2 -* Jz + * ``` + 32 16 10 4 0 + opcode reg1 reg2 unused + / / / / + +-------------------------------------------+ + | 0001000000000001 | ...... | ...... | XXXX | + +-------------------------------------------+ + ``` +* Jmp * Opcode: 0x1100 * **Params**: REG1 + * `IP = REG1;` + * Jumps to the address in REG1 unconditionally. + * ``` + 32 16 10 0 + opcode reg1 unused + / / / + +----------------------------------------+ + | 0001000000000000 | ...... | XXXXXXXXXX | + +----------------------------------------+ + ``` + +* Jz + * Opcode: 0x1101 + * **Params**: REG1 * ``` if FLAGS[1] == 0 { IP = REG1; } ``` * Jumps to the address in REG1 if COMPARE flag is 0. + * ``` + 32 16 10 0 + opcode reg1 unused + / / / + +----------------------------------------+ + | 0001000000000001 | ...... | XXXXXXXXXX | + +----------------------------------------+ + ``` * Jnz - * Opcode: 0x1001 + * Opcode: 0x1002 * **Params**: REG1 * ``` if FLAGS[1] != 0 { @@ -165,6 +299,14 @@ wrapping around to 0. } ``` * Jumps to the address in REG1 if COMPARE flag is 1. + * ``` + 32 16 10 0 + opcode reg1 unused + / / / + +----------------------------------------+ + | 0001000000000002 | ...... | XXXXXXXXXX | + +----------------------------------------+ + ``` ## Data movement @@ -177,7 +319,7 @@ wrapping around to 0. * Sets REG1 to the value at the memory address in REG2. * ``` 32 16 10 4 0 - 64 - opcode reg1 reg2 unused + opcode reg1 reg2 unused / / / / +-------------------------------------------+ | 0010000000000000 | ...... | ...... | XXXX |