Introduction to CPU Sim

CPU Sim is an interactive computer simulation package in which the user specifies the details of the CPU to be simulated, including the register set, memory, the microinstruction set, machine instruction set, and assembly language instructions. Users can write machine or assembly language programs and run them on the CPU they've created.

CPU Sim simulates computer architectures at the register-transfer level. That is, the basic hardware units from which a hypothetical CPU is constructed consist of registers, condition bits, and memory (RAM). The user does not need to deal with individual transistors or gates on the digital logic level of a machine. The basic units used to define machine instructions consist of microinstructions of a variety of types. The details of how the microinstructions get executed by the hardware are not important at this level.

A user of CPU Sim who wants to simulate a new hypothetical CPU must first specify the hardware units and microinstructions for the CPU and then create the machine instruction set. Each machine instruction is implemented via an associated sequence of microinstructions specified by the user.

Once the instruction set has been specified, the user can write programs for the new CPU, in either machine language or assembly language, which can be run in the CPU Sim environment.

CPU Sim executes a program through repeated execution of machine cycles. Each machine cycle has two parts: the fetch sequence, which is a sequence of microinstructions that typically loads the next instruction to be executed into an instruction register and decodes it, and the execute sequence, which is the sequence of microinstructions associated with the newly-decoded instruction. The fetch sequence is the same for all cycles, but the execute sequence can, and usually does, vary from cycle to cycle. Execution of the program halts when a user-specified "halt" bit is set to 1.

CPU Sim has many useful features for running programs and debugging them. For example, CPU Sim has a built-in text editor and assembler for creating and assembling programs. The editor will highlight the offending section of the program when the assembler finds an error. Assembled programs can be executed without stopping or they can be executed in debugging mode which allows the users to step through the execution of a program, one machine instruction or microinstruction at a time. After each step, users can edit the contents of any register or memory and then continue stepping or even back up one machine instruction or microinstruction at a time, all the way back to the initial state of the machine.

The ideas for this simulator came from the STARTLE simulator developed by J.M. Kerridge of the University of Sheffield.