CPU Simulation in a Spreadsheet

August 9th 2008 04:31 pm

I spent several years teaching an introductory computing class to non-majors. Originally, the class covered computer technology in great detail, and students were expected to understand the CPU instruction execution cycle. Since the students were learning Excel anyway, I decided to make things simple: I created a CPU simulator that ran in Excel.

Simple CPU example

The Basic Principle

The Simple CPU implements a one-address instruction set. It uses two cycles, Fetch and Execute, and we change the CPU’s state as we go from one cycle to the other. The spreadsheet image above shows the computed values appearing in the various processor registers. When we cycle the CPU, we change between the Fetch and Execute states. When we cycle, there is often the side-effect of storing a new value in certain static registers, like the program counter (PC) and the Fetch/Execute flag. The state change may also fetch or store data in the RAM.

The fetching and storing of RAM uses a set of fetch and store indirect functions written in Visual Basic and implemented through the Excel Macro mechanism.

The Spreadsheet CPU (SSCPU, described more below) implements multiple instruction cycles, to allow for indirection or two-address instruction execution.

The TX-0 Computer

The instruction set was inspired by MIT’s TX-0 computer (“Transistor Experiment #0), one of the first computers built from transistors. The TX-0 was an incredibly simple computer. It had four instructions: add, store, jump, and “specials.” While this makes it hard to write sophisticated programs, it’s enough to write demonstration programs.

MIT's TX-0 computer, circa 1960

The Spreadsheet CPU

A more sophisticated version of the Simple CPU allows a simple form of “microprogramming” (actually, “control store programming,” to respect Wilkes’ terminology). This makes it usable to teach computer organization and simple machine language programming.

For More Information

Below are links to various spreadsheet examples, papers, talks, and explanations.

The Excel files are often in “.xlt” or “template” format. To use these, you simply double click on the file, and it creates a new spreadsheet with the CPU already installed. The file is given a default name so you won’t accidentally save a modified CPU atop the original one.

  • Simple CPU
    • How to use the Simple CPU (a simple demonstration)
    • The SimpleCPU spreadsheet
    • SimpleCPU paper – a description written for a 2006 regional conference of the American Society of Engineering Education.
    • SimpleCPU talk – slides for the talk given at a 2006 regional conference of the American Society of Engineering Education.
  • Spreadsheet CPU
  • Other Spreadsheet CPU examples – Each of these is a separate, stand-alone CPU simulation. These aren’t guaranteed to work perfectly – there may be problems with when internal registers transfer their contents, relative to what should happen during different parts of the instruction cycle. They provide examples of how the SSCPU ought to support alternative designs.

I would appreciate hearing from people who use these simulations. Either send me an email or post a comment.

Creative Commons License
This article by Rick Smith is licensed under a
Creative Commons Attribution 3.0 United States License.

Bookmark and Share

Posted under Tech Teaching | No Comments »

Trackback URI | Comments RSS

Leave a Reply

You must be logged in to post a comment.