diff --git a/vm.md b/vm.md index 4463349..2bcb7ce 100644 --- a/vm.md +++ b/vm.md @@ -23,7 +23,8 @@ CPU registers are addressed by a value between 0-63 (6 bits). All registers are * SP - Stack pointer * FP - Frame pointer * FLAGS - CPU flags -* (10 unused registers) +* (9 unused registers) +* STATUS - Generic status code * R0-R49 ## CPU Flags @@ -82,10 +83,12 @@ wrapping around to 0. * Shr * **Params**: REG1, REG2 * `REG1 = REG1 >> REG2` + * Does not sign extend ### TODO * Add signed instructions (iadd, imul, etc) +* Sign-extending SHR * Overflow flag? ## Control flow @@ -99,6 +102,7 @@ wrapping around to 0. FLAGS[1] = 0; } ``` + * Sets the COMPARE flag to 1 if REG1 == REG2 * CmpLt * **Params**: REG1, REG2 * ``` @@ -108,20 +112,27 @@ wrapping around to 0. FLAGS[1] = 0; } ``` + * Sets the COMPARE flag to 1 if REG1 < REG2 * Jz * **Params**: REG1 * ``` - if FLAGS[0] == 0 { + if FLAGS[1] == 0 { IP = REG1; } ``` + * Jumps to the address in REG1 if COMPARE flag is 0. * Jnz * **Params**: REG1 * ``` - if FLAGS[0] != 0 { + if FLAGS[1] != 0 { IP = REG1; } ``` + * Jumps to the address in REG1 if COMPARE flag is 1. +* Halt + * **Params**: (none) + * `FLAGS[0] = 1` + * Halts the machine ## Data movement @@ -130,17 +141,41 @@ wrapping around to 0. * ``` REG1 = MEM[REG2]; ``` + * Sets REG1 to the value at the memory address in REG2. * Store * **Params**: REG1, REG2 * ``` MEM[REG2] = REG1; ``` + * Sets the value at the memory address in REG2 to the value in REG1. * StoreImm32 * **Params**: REG1, IMM_32 * `REG1 = IMM_32` + * Sets REG1 to the specified 32-bit number. * MemCopy * **Params**: REG1, REG2 * `MEM[REG1] = MEM[REG2]` + * Copies the value at the memory address in REG2 to the memory address in REG1. * RegCopy * **Params**: REG1, REG2 * `REG1 = REG2` + * Copies the value in REG2 into REG1. + +## Other instructions TODO + +* Call + * Takes address and number of bytes on the stack that are for args(?) + * Updates SP, FP, IP, storing previous values starting at the new FP +* Ret + * Uses FP to determine previous SP, FP, and IP and restores them +* Push +* Pop +* More immediate stores? + +# General TODO + +* Interrupts +* MMIO regions +* Execution pipeline + * Helps to define when certain side effects happen (e.g. when the IP increments) +* Paging?