CPU

From VO-EM Wiki
Jump to: navigation, search

The CPU is the core of the VO-EM machine. It handles all non-graphical processing. It is closely based on the theoretical DLX CPU, but currently does not implement the floating point unit. As in, anything that compiles or assembles bytecode for the DLX CPU should theoretically run on the VO-EM CPU. Unless it uses floating point math.

Technical Overview

Clock speed: 72,000 instructions per second
Registers: 32
Instruction length: 4 bytes

Clock cycle

The CPU's clock cycle has two phases - Fetch and Execute.

Fetch

In the Fetch cycle, the CPU first checks for, and handles, any interrupts or exceptions that have occurred since the last cycle.

If the [Opcodes#wait|wait] instruction has been used and no exceptions have occurred, the CPU will stop here and continue waiting for an interrupt or exception.

Otherwise, the CPU will read the data located at the address currently indicated by PC into IR, then increment PC by 4.

Execute

The CPU decodes the instruction in IR, and then executes it.

Registers

General purpose

There are 32 general purpose registers in the VO-EM CPU, named r0 to r31. r0 always contains zero, regardless of what is written to it. Each register is 32 bits long.

Special registers

In addition to the general purpose registers, there are some special registers that perform specific functions. Some can be accessed directly.

PSW, XBR and XAR can be read and written using [[[Opcodes#movs21|movs2i]]] and [[[Opcodes#movi2s|movi2s]]] respectively.

PC

Program Counter 
This register contains the address of the next instruction to be loaded. It can be changed using jump commands. It cannot be read directly.

IR

Instruction Register 
Contains the instruction to be executed. Cannot be read or written to.

PSW

Processor Status Word 
Controls interrupt and exception handling.

XBR

Exception Base Register 
This is the address of your interrupt and exception handling jump table.

XAR

Exception Address Register 
When an exception occurs, the address of the instruction that caused the exception is stored here.

Instructions

Main article: Opcodes

The VO-EM CPU uses entirely 4-byte instructions. See the opcode reference for detailed information regarding them.

When an instruction is loaded, it is loaded with a lw operation, meaning that its address must be aligned to a multiple of 4, or the read will fail.