next up previous
Next: 3 Assembly language Up: The Mintel Smalltium Microprocessor Previous: 1 The story so

2 Machine internals

This section will give you a brief introduction to how a microprocessor functions. To begin with, we assume you have a knowledge of binary numbers. If you are unfamiliar with binary numbers, any basic computer programming textbook will probably have a chapter or an appendix dealing with alternate numbering systems, including binary; or you can ask your teacher for assistance.

A computer has two main components that we will be dealing with: the processor and the system memory. The Smalltium processor is a 16-bit processor. The system memory is word-addressable, meaning that that you can't access an individual byte of memory--you can only to access a whole word. The Smalltium has 256 words of memory and each word is 16 bits. (At 2 bytes per word, this makes a total of 512 bytes of memory, but we only deal with memory in terms of words.) This may not sound like much, but this processor isn't designed to do much (that's why it's called the Smalltium). The system memory is sometimes referred to as core.

Although you write programs in languages such as C++ or Pascal, a processor can't directly understand these. Instead, the processor understands a language called machine language. Machine language is expressed in binary numbers. For a RISC processor, each instruction is the same number of bits, unlike a CISC processor, where the length of an instruction depends on which instruction it is. In the Smalltium, all instructions are 16 bits (one word).

Part of any machine language instruction has to say what kind of instruction it is. This part of the instruction is known as an opcode. The opcode in Smalltium instructions is the first four bits of the instruction. This means that there can be a total of 16 different kinds of instructions that it understands ( tex2html_wrap_inline803 ). This is a typical number of instructions for a RISC processor. A CISC processor, by comparison, will often have hundreds of different instructions. The other twelve bits in the instruction word can mean different things depending on what kind of instruction it is.

It takes a relatively long time for a processor to access memory because it is on another chip. Most processors therefore have a few memory words located inside the CPU, which are designed to be much faster than the system memory. These memory words are used as workspaces, and are called registers.

The Smalltium processor has 16 registers (numbered 0 through 15). This means that it takes four bits to specify a register number. Programs need to use the value 0 very often, so most RISC processors have one of their registers always contain the value 0. In the Smalltium, register number 0 (r0) always contains the value 0, and cannot be changed. Register 15 is also reserved for a special function, which we will discuss later.

Sometimes a processor will need to compare two values, and then use the results of that comparison in a later instruction. Since the results of a comparison only requires a few bits, using an entire register to store them doesn't make a whole lot of sense. Instead, processors often use condition flags. A flag is just a 1-bit boolean variable. It holds a zero if the condition is false, and a one if the condition is true. The Smalltium has four condition bits, which we will discuss later when we talk about the compare instruction (section 5.1).

In order to access memory, we need some way of specifying which particular word of memory we would like. Every memory word has a unique number associated with it, which is its memory address. Since the Smalltium has 256 words of memory, it takes an 8-bit number to specify a memory address.

There are a number of different ways we can specify such an address in a machine language instruction, but the Smalltium only uses two. The first is as an immediate address. This means that the address is a constant value given in the instruction word. This is the most common method of memory addressing. The Smalltium can also use a memory address based on the contents of two registers. The two registers are added together, and the result is used as the memory address (note that you can also use the contents of a single register by specifying r0 as the second register).

So with all that background out of the way, how does a processor actually work? The processor does its actual work in what is known as an ifetch loop. ``Ifetch'' stands for ``instruction fetch.'' The ifetch loop is composed of the following three parts:

  1. fetch
  2. decode
  3. execute

In the fetch part, the processor goes out to the system memory and loads the next instruction. The decode part involves figuring out what kind of instruction it is, and what the arguments to that instruction are. In the execute part is where the actual work of that instruction gets done. This loop keeps on iterating endlessly until the machine halts.

So how does the processor know the memory address of the next instruction? This is the role of register number 15, which is also called the program counter or PC. The PC always contains the memory address of the next instruction to execute. The fetch stage of the ifetch loop has the following two parts:

  1. Read the next instruction from the memory address contained in the PC.
  2. Increment the PC.

Note that the execute stage of the ifetch loop might also change the PC, if the instruction is one that causes the point of execution to move to a different part of the program (such as in a loop).


next up previous
Next: 3 Assembly language Up: The Mintel Smalltium Microprocessor Previous: 1 The story so

James Clingenpeel
Thu Feb 29 18:00:38 MST 1996