CPU Simulation in a Spreadsheet

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

Simple CPU: 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.

TX-0 Computer

The Spreadsheet CPU

A more sophisticated version of the Simple CPU allows a simple form of “microprogramming” (actually, “control store programming,” to respect the terminology as used by Maurice Wilkes). 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 all carry the “xls” suffix. In fact, a few of them are in “.xlt” or “template” format (the web server here doesn’t want to store/serve “xlt” files).

Also, be warned: These Excel files contain macros. The macros contained nothing malicious when I uploaded them. If you download them and distribute them, try to keep them safe from malicious changes.

  • Simple CPU
    • How to use the Simple CPU (a simple demonstration)
    • The SimpleCPU spreadsheet template file
    • 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.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.