Introduction to the CPU
Objectives
We would like to :
Understand the basic components of a cpu
Understand the fetch-decode-execute cycle
Notes
Sorry, no reference
Jorgensen chapter 2, but he lacks detail.
There are lots of good architecture references but probably too much detail.
Way too much detail, but I am working on
Ben Eater's 8 bit computer
So pay attention and ask questions.
The Central Processing Unit (CPU)
We will look at a single core computer.
In another set of notes, and other classes we will discuss multi core/multi processor.
The CPU is the heart of the core/processor
The CPU consists of the following
Registers
Registers are temporary memory to hold data.
General purpose registers are generally usable by the programmer for any purpose but some have special restrictions.
Intel has 16 registers
*ax, *bx, *cx, *dx
*si, *di
*bp, *sp
*r8-*r16
In our example program the rax register will hold the result of a system call.
all of the registers above are GP registers.
*bp and *sp have very strict special uses, but are general purpose.
As we saw in the program, we used the registers to hold data to pass to the system calls.
Later we will use these registers to hold "variables" during a computation.
The number and use of GP registers is an architecture topic
How to build a register is a computer organization topic.
Special purpose registers.
These are registers that the user does not have direct control over.
Intel has a FLAGS register
it contains information
about the status of a computation.
We will discuss some other SP registers soon.
These are added as needed by the demands of the architecture.
Side Note: When we are performing an instruction in hardware, we say that we are
executing
that instruction.
The instruction register
This is a SP register that holds the instruction that is currently being executed.
The Program Counter or Instruction Pointer
This is a SP register that holds the address in memory of the next instruction to be executed.
The ALU or Arithmetic Logic Unit
This is a component that performs the "math" in a cpu.
Memory
Memory is not part of the cpu proper, but it is closely tied tot he cpu.
Memory is a huge array of bytes (not bits)
Memory is addressable from byte 0, to the maximum byte
The cpu can write to memory
The cpu can read from memory
Memory tends to be MUCH slower than the cpu
The Memory Management Unit
This is a hardware component that interacts with memory.
It has two special purpose registers
The memory address register, or MAR holds the address in memory we wish to interact with.
The memory data register, or MDR, holds the data we will send to /receive from memory.
To read from memory
Place the address in the MAR
Tell memory to read
Get the data from the MDR
To write to memory
Place the address in the MAR
Place the data in the MDR
Tell memory to write
Note we take a CPU centric view of memory
The Control Unit or CU
This is responsible for performing the operations of the cpu
This is the "little guy" behind the scenes pulling the levers.
But there is no little guy.
The Bus connects all of the components.
In general the CPU runs an algorithm called the Fetch-Decode-Execute cycle.
The instruction pointed to by the PC is fetched from memory and stored in the IR
The CU decodes the instruction in the IR
The CU issues the control signals required to execute the instruction.
Assume we have the simple assembly language like that of the
eight bit computer
.
Load will load a value from memory into the A register
Add will add the value from memory to the A register
Store will store the A register to memory
Output will print the value of the A register
Halt will halt the program.
The program:
address instruction 0 load A 1 add B 2 store C 3 output 4 halt A 10 B 20 C
Trace this.