CS 39 -- Virtual Machine Description


Overview

The instruction format is designed to be simple for the virtual machine to decode and for a user to read. It is not like a real machine code format in that it is human-readable bytes of text. As a result, though, the machine code format looks much like assembly code.

Note that this instruction format is also not as extensive as a real instruction set would be. For example, only integer manipulation is directly supported -- no floating point numbers.

Although it is simple, this instruction set is sufficient to perform significant computations. Therefore, it will allow us to create short- and long-lived processes that are performing actual computation. This page documents the instruction set, including the registers that can be used as well as the interrupts and interrupt handling mechanisms.


The register set

Below are listed the registers available for this machine.


Traps and trap register values

Below are listed all of the traps that the virtual machine may generate, and that the kernel may receive. Along with each trap, we provide the offset into the trap table (that is, the trap table entry number) for that trap. In that trap table entry must be a pointer to the kernel trap handler function for that type of trap. We also list, for each trap, the values placed into the system registers (%s0 - %s3) before execution is vectored into the kernel.


Advancing the PC

The processor will normally advance the PC to the next instruction after executing the current instruction. However, there are some circumstances under which the PC is not advanced. These are the exceptions:

  1. An invalid instruction interrupt occurs. These are raised when an opcode cannot be decoded, or when the operands provided are not valid.

  2. An invalid memory access interrupt occurs. If an instruction fetch, load, or store attempts to use an invalid address, this interrupt is generated.

  3. A successful branch or jump occurs. When such an instruction succeeds in setting the PC to a new value, that new PC value is not incremented.

In all other circumstances the PC is advanced. Note that the setting of the PC by the kernel does not form an exception to its normal advancement.


Instruction format

Each instruction is exactly 32 bytes, irrespective of the instruction used. The simple multiplication of two constants, in machine code format, would look something like this:

STRI 00000005 103ef200 00000000
STRI 0000001c 00000004 00000000
MULR 0000000b 00000005 0000001c
    

More generally, notice the common characteristics of every instruction:

This exact format must be followed. If it is not, then the decoding component of the virtual machine will likely get confused, and complain that some part of the code contains an illegal instruction, an illegal address, or an invalid register number.

(Note that, technically, the space characters between the opcode and operands could be any character, including, say, a tab character. There must be *some* character, though, that the decoder can skip before examining the next piece.)


Instruction Index

Below is a catalog of instructions and their associated interpretation of the operands that follow. Specifically, in each description, we will refer to the opcode, as well as operand-0, operand-1, and operand-2.


Scott F. Kaplan
Last modified: Sat Sep 27 14:49:37 EDT 2003