Processors

The Basic Idea

Before assembly languge or machine language can make any sense, we need to get a (very) basic idea about how a (conventional) processor works.

cpu.gif

The Bus

The bus contains a number of lines (around one hundred in many modern processors).

Address and Data Lines

These are used for reading from memory or devices and writing to memory or devices. The number of address lines determines how many words of memory can possibly be addressed. The number of data lines determines how much data can be moved at one time.

Power and Ground Lines

The power line is a convenient way to get a 1 whenever you need one; the ground line gives you your 0.

IO/~MEM Line

When 1 (IO), the address line specifies the "address" of a port on a device connected to the bus; when 0 (MEM) the address line specifies a memory address.

R/~W Line

When 1 (R), we want to read what's on the data bus; when 0 (W) we want to write the contents of the data bus to memory or to a device.

Clock Line

This alternates between 0 and 1, a given number of times per second.

Registers

Parts of the processor that can store data and do arithmetic and logic. Most processors work by reading data from memory or a device into registers, doing computations, and writing back out to memory or devices. We need registers since it is generally too expensive to put arithmetic and logic circuitry within every memory cell.

Some registers aren't for computation but rather to provide information (status) or put the processor in a particular mode of operation (control).

The Instruction Pointer

This register contains the address (in memory) of the next "instruction" to be executed.

The Fetch-Execute Cycle

As long as the processor is on, and not in a "halted" state, it will repeatedly:

  1. Read (fetch) the word in memory whose address is in the instruction pointer register, the increment the register.
  2. Do something based on the fetched value (execute).

The fetched value is an instruction. For example, a processor could be designed so that if the octet 8C were fetched, it would cause two of its registers to be multiplied together. And maybe a 35 would cause a register to be decremented, and a C9 would cause the contents of a register to be written to memory.

Note how the autoincrementing of the instruction pointer means that a "program" is a sequence of instructions in consecutive memory locations. Almost every processor though, has a jump instruction which is implemented by writing a completely different value into the instruction pointer.