1
0
Fork 0
mirror of https://github.com/pnx/m16vm synced 2026-06-16 03:44:55 +02:00

README.md: style changes.

This commit is contained in:
Henrik Hautakoski 2019-04-26 15:24:28 +02:00
parent 0a58a7857f
commit 825642e8b5
No known key found for this signature in database
GPG key ID: 839F3A7EAFAEAFAA

206
README.md
View file

@ -1,100 +1,106 @@
m16vm - 16 bit processor virtual machine
# m16vm - 16 bit processor virtual machine ========================================
This is a virtual machine for a RISC-processor designed for educational purposes. This is a virtual machine for a RISC-processor designed for educational purposes.
The design is taken from the real world and tries to mimic existing RISC-architectures. The design is taken from the real world and tries to mimic existing RISC-architectures. So it should in theory be possible to construct actual hardware based on the instruction set. Maybe not build a transistor-chip (it's hard, unless you know someone working at Intel/Amd or something) but by putting together a bunch of gate-chips on a breadboard.
So it should in theory be possible to construct actual hardware based on the instruction set.
Maybe not build a transistor-chip (it's hard, unless you know someone working at Intel/Amd or something) The instruction set is by no means designed to be "fast" or "optimal" but focus more on being easy to understand and modify/play with.
but by putting together a bunch of gate-chips on a breadboard.
Specification
The instruction set is by no means designed to be "fast" or "optimal" but focus -------------
more on being easy to understand and modify/play with.
The cpu has 16 general purpose registers, r0 - r15. Each register is 16-bit.
## Specification
Memory addresses are aligned by 2 bytes (16 bit) and the machine has a total of `65536` bytes of memory (per default, can be changed at compile time).
The cpu has 16 general purpose registers, r0 - r15. Each register is 16-bit.
instruction set overview
Memory addresses are aligned by 2 bytes (16 bit) and the machine has ------------------------
a total of `65536` bytes of memory (per default, can be changed at compile time).
There are 16 different instructions.
## instruction set overview | opcode | Name | Type | Description |
|--------|------|------|-----------------------------------------|
There are 16 different instructions. | 0000 | noop | \- | No operation |
| 0001 | add | R | Addition |
| opcode | Name | Type | Description | | 0010 | movl | I | move value to register (lowest 8-bits) |
| ------ | -----| ---- | --------------------------------------- | | 0011 | movh | I | move value to register (highest 8-bits) |
| 0000 | noop | - | No operation | | 0100 | ld | RI | load word |
| 0001 | add | R | Addition | | 0101 | sw | RI | store word |
| 0010 | movl | I | move value to register (lowest 8-bits) | | 0110 | beq | RI | Branch on equal |
| 0011 | movh | I | move value to register (highest 8-bits) | | 0111 | jmp | J | Jump |
| 0100 | ld | RI | load word | | 1000 | jr | I | Jump (register) |
| 0101 | sw | RI | store word | | 1001 | \- | \- | Reserved |
| 0110 | beq | RI | Branch on equal | | 1010 | \- | \- | Reserved |
| 0111 | jmp | J | Jump | | 1011 | \- | \- | Reserved |
| 1000 | jr | I | Jump (register) | | 1100 | \- | \- | Reserved |
| 1001 | - | - | Reserved | | 1101 | \- | \- | Reserved |
| 1010 | - | - | Reserved | | 1110 | \- | \- | Reserved |
| 1011 | - | - | Reserved | | 1111 | int | I | Interrupt |
| 1100 | - | - | Reserved |
| 1101 | - | - | Reserved | NOTE: Subtraction can be implemented via `add` and negative register values, so no special opcode is needed.
| 1110 | - | - | Reserved |
| 1111 | int | I | Interrupt | Instruction set format
----------------------
NOTE: Subtraction can be implemented via `add` and negative register values, so no
special opcode is needed. Register operation (R):
## Instruction set format ```
opcode (4) | rs (4) | r0 (4) | r1 (4)
Register operation (R):
r0,r1 - Operand registers.
opcode (4) | rs (4) | r0 (4) | r1 (4) rs - save register
```
r0,r1 - Operand registers.
rs - save register Register operation offset (RI):
Register operation offset (RI): ```
opcode (4) | rs (4) | r0 (4) | offset (signed 4)
opcode (4) | rs (4) | r0 (4) | offset (signed 4)
r0 - Operand registers.
r0 - Operand registers. offset - constant offset from r0 value.
offset - constant offset from r0 value. rs - save register
rs - save register ```
Constant operation format (I): Constant operation format (I):
opcode (4) | reg (4) | data (signed 8) ```
opcode (4) | reg (4) | data (signed 8)
reg - Register
data - Constant data to insert into reg. reg - Register
data - Constant data to insert into reg.
Jump format (J): ```
opcode (4) | addr (12) Jump format (J):
## Interrupts ```
opcode (4) | addr (12)
There can be a total of `16` Interrupts and the instruction uses the `I-format`. ```
The interrupt number is stored in `reg` (note that for interrupts this is a constant and not a register). Interrupts
----------
The `data` field can be used as an argument to the interrupt.
There can be a total of `16` Interrupts and the instruction uses the `I-format`.
| Number | Name | data | Description |
| ---------: | -----------| ------ | -------------------------------------------------------- | The interrupt number is stored in `reg` (note that for interrupts this is a constant and not a register).
| 10 | I/O Write | format | Outputs a value to the screen, value are stored in `r15` |
The `data` field can be used as an argument to the interrupt.
### I/O Write - int 10
| Number | Name | data | Description |
The formatting of the output can be controlled by the number in `data` as follows: |-------:|-----------|--------|----------------------------------------------------------|
| 10 | I/O Write | format | Outputs a value to the screen, value are stored in `r15` |
| Argument | Datatype |
| ------------ | ----------------------- | ### I/O Write - int 10
| 0 | Integer (16 bit signed) |
| 1 | Integer (8 bit signed) | The formatting of the output can be controlled by the number in `data` as follows:
| 2 | Character |
| Argument | Datatype |
## Example programs. |----------|-------------------------|
| 0 | Integer (16 bit signed) |
in the `programs` directory, there is some example programs to run. | 1 | Integer (8 bit signed) |
| 2 | Character |
Example programs.
-----------------
in the `programs` directory, there is some example programs to run.