How Computers Work

To understand the machine that we emulate in this project, you have to understand something about the way computers work.

At the very heart of computers is the CPU, or central processing unit. For the most part, this is the thing which needs emulating by our program. This CPU is the part of the machine which understand the native assembly language of the machine. As we explained in our introduction to the first C tutorial on this site, assembly language is very primitive, and differs between different kinds of machine.

The CPU (what we will call the processor from now on) does all the computing work of the machine. It runs around, fetching data from memory, storing it inside tiny data stores, which are called registers, which reside inside the processor itself. It performs various arithmetic and logic manipulations of the data while it is in these registers, and then it shunts the data back out to memory and into the various bits of hardware inside the computer, such as the graphics card, hard disk, etc.

In reality, the processor is a single chip inside your computer. If you own a PC, then Pentium, Celeron, Athlon or whatever, refers to the type of processing chip you have. These days, such chips contain millions and even billions of transistors. Fortunately for us however, we do not need to emulate the circuit design of one of these chips, but merely the functionality of a processor (and a fictitious one at that).

In our case, we will emulate a 16 bit microprocessor. This simply means that each of the registers inside the chip, contains 16 bits of data. Another way of saying the same thing is that the registers contain two bytes of information each (a byte being 8 bits). Each bit can be either a 1 or a 0 (computers use binary rather than base 10 arithmetic like us. Each digit in a number can have only two values, 0 or 1. We have 10 digits in our numbers, 0, 1, 2, ... , 9). Thus, given that there are only 2 possibilities for each bit, there are 2x2x2x....x2 = 2^16 = 65536 different possible values that can be stored in each register.

One of the restrictions that having a 16 bit processor places on us, is that only 65536 memory locations can be addressed at a time (that is if we want to store a memory address in a single register). Many real world 16 bit computers get around this limitation by using more than one register at a time to address memory. We will stick with 65536 bytes = 64 kb of memory, though (one kilobyte, 1 kb, is 2^10 = 1024 bytes of memory. Thus 64 kb = 64 x 1024 = 65536 bytes).