Change instruction encodings to avoid null instructions

Lots of null bytes in a row are a common thing, so the instructions
available can't start with a null pair of bytes anymore.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-03-09 15:11:32 -04:00
parent b697b000a4
commit 65972fcbbe
6 changed files with 54 additions and 56 deletions

51
vm.md
View File

@@ -128,43 +128,43 @@ Arithmetic instructions store their result in the first register specified. Over
wrapping around to 0.
* Add
* Opcode: 0x0000
* Opcode: 0x1000
* Params: Destination, source
* Sub
* Opcode: 0x0001
* Opcode: 0x1001
* Params: Destination, source
* Mul
* Opcode: 0x0002
* Opcode: 0x1002
* Params: Destination, source
* Div
* Opcode: 0x0003
* Opcode: 0x1003
* Params: Destination, source
* Mod
* Opcode: 0x0004
* Opcode: 0x1004
* Params: Destination, source
* And
* Opcode: 0x0005
* Opcode: 0x1005
* Params: Destination, source
* Or
* Opcode: 0x0006
* Opcode: 0x1006
* Params: Destination, source
* Xor
* Opcode: 0x0007
* Opcode: 0x1007
* Params: Destination, source
* Shl
* Opcode: 0x0008
* Opcode: 0x1008
* Params: Destination, source
* Shr
* Opcode: 0x0009
* Opcode: 0x1009
* Params: Destination, source
* INeg
* Opcode: 0x000a
* Opcode: 0x100a
* Params: Destination, source
* Inv
* Opcode: 0x000b
* Opcode: 0x100b
* Params: Destination, source
* Not
* Opcode: 0x000c
* Opcode: 0x100c
* Params: Destination, source
### TODO
@@ -176,25 +176,25 @@ wrapping around to 0.
## Control flow
* CmpEq
* Opcode: 0x1000
* Opcode: 0x2000
* Params: Source, source
* CmpLt
* Opcode: 0x1001
* Opcode: 0x2001
* Params: Source, source
* Jmp
* Opcode: 0x1002
* Opcode: 0x2002
* Params: Source
* Jz
* Opcode: 0x1003
* Opcode: 0x2003
* Params: Source
* Jnz
* Opcode: 0x1004
* Opcode: 0x2004
* Params: Source
## Functions
* Call
* Opcode: 0x2000
* Opcode: 0x3000
* Params: Source
* When this instruction is executed, these actions occur:
* Push the current stack frame pointer
@@ -202,26 +202,26 @@ wrapping around to 0.
* Update the IP (i.e., jump) to the value at the given source.
* Update the frame pointer to the current stack pointer - 16
* Ret
* Opcode: 0x2001
* Opcode: 0x3001
* When this instruction is executed, these actions occur:
* Update the stack pointer to the current frame pointer + 16.
* Pop the IP of the next instruction.
* Pop the old stack frame.
* Restore the last three values in an undefined order
* Push
* Opcode: 0x2002
* Opcode: 0x3002
* Params: Source
* When this instruction is executed, these actions occur:
* Set the value in memory at the current stack pointer to the source value.
* Increment the stack pointer by the size of value at the source.
* Pop
* Opcode: 0x2003
* Opcode: 0x3003
* Params: Dest
* When this instruction is executed, these actions occur:
* Decrement the stack pointer by the size of value at the destination.
* Copy the value at the stack pointer into the destination.
* Int
* Opcode: 0x2004
* Opcode: 0x3004
* Params: Source, Source
* When this instruction is executed, these actions occur:
* Push the current stack frame pointer
@@ -235,7 +235,7 @@ wrapping around to 0.
* Update the R1 register to the value in the second parameter
* Update the frame pointer to the current stack pointer - 48
* IRet
* Opcode: 0x2005
* Opcode: 0x3005
* When this instruction is executed, these actions occur:
* Update the stack pointer to the current frame pointer + 48
* Pop the old R1 value
@@ -249,7 +249,7 @@ wrapping around to 0.
## Data movement
* Mov
* Opcode: 0x3000
* Opcode: 0x4000
* Params: Source, Dest
## Miscellaneous
@@ -410,7 +410,6 @@ A VM must provide support for the following meta-values:
# General TODO
* Interrupts
* MMIO regions
* Paging?
* Determine how address sizes are determined