The CPU Central Processing Unit. 2 Reminder - how it fits together processor (CPU) memory I/O...

Post on 01-Jan-2016

214 views 0 download

Transcript of The CPU Central Processing Unit. 2 Reminder - how it fits together processor (CPU) memory I/O...

The CPU

Central Processing Unit

2

Reminder - how it fits together

processor (CPU) memory

I/O devices

bus

3

What does the CPU do?

The CPU is the heart of the computer. it:

• Executes programs written in machine code

• Performs arithmetic and logic calculations

• Controls the bus

• Controls the operation of memory and I/O devices, via the bus

4

How does the CPU do this?

• When you want the CPU to perform a task, how does it know?

• It knows, because it gets operations to perform from memory

• It is continually reading machine code instructions, executing them, and going on to the next instruction

• This is called the “fetch-execute cycle”, and is what the CPU does nearly all of the time

5

The Fetch-Execute Cycle

1. Read the next machine-code instruction from memory

2. Perform the actions specified by that instruction

6

What actions must be included in a set of machine-code instructions?• Load Data

– (from a specified memory or I/O address)

• Store Data– (to a specified memory or I/O address)

• Operate on Data– arithmetic and logical operations

• What else?

7

CPU Registers

• The CPU needs to store some data internally

• Other data can be stored internally, to speed up operations (memory accesses take a relatively long time)

• For this purpose, the CPU has registers• These are simple (typically 8 or 16 bit)

storage units inside the CPU

8

Examples of Register Use

• The address of the next machine-code instruction

• the address-bus value for the current bus cycle

• the value of the current instruction

• the result of the most recent arithmetic operation

9

What is a register?

• A register is a collection of flip-flops!

• A flip-flop can store only one bit (a 1 or a 0), so we need a string of them

• When a value is written to the flip-flop, it stores that value as long as the power remains on, or until it is overwritten with another value

A very simple CPU

10

11

Some abbreviations

MAR Memory Address Register - controls the address bus

MBR Memory Buffer Register - interface to data bus (also called MDR: Memory Data Register)

IR Instruction Register - contains current instruction (often divided into an op-code and an address)

op-code Operation code - the part of a machine-code operation that specifies the operation

12

Some abbreviations

PC Program Counter - address of next instruction (don’t get confused by the term “PC”!)

Acc Accumulator - holds operands and results of ALU operations

ALU Arithmetic Logic Unit - performs addition, subtraction, logical AND, logical OR etc.

13

The Control Unit (1)• Translates each op-code (which is simply a

binary number) into a sequence of primitive actions

• These actions carry out the operation specified by the op-code

14

The Control Unit (2)

Primitive actions are:– switching data pathways on and off– clocking data into and out of registers– selecting ALU functions

These actions are carried out by internal control lines (nothing to do with the control bus!)

15

Example: how the CPU executes a commandFor all commands:

• copy PC to MAR; increment PC– program counter contains memory address of next op-code

• perform bus read cycle– causes op-code to be read from memory location now held in MAR

• copy MBR to IR (op-code)– MBR (input from data bus) will contain the op-code, read from memory;

this is copied into the Instruction Register

16

Example: store accumulator to memoryThis op-code is going to require an address, so we will need to get that next

• copy PC to MAR; increment PC– get the memory address for store operation from next memory location

• perform bus read cycle• copy MBR to IR (addr)

– we now have the op-code and address in the IR

• copy IR(addr) to MAR– specify in MAR where we’re going to write to

• copy accumulator to MBR– ready to go out on data bus

• perform bus write cycle– causes contents of MBR to be written to address held in MAR

17

What’s happening?

• Follow the example on the previous two slides, with reference to the CPU diagram

18

Test Yourself!

1. What is the fetch-execute cycle?2. What are CPU registers used for?3. What is a flip-flop?4. Can you identify all the components of the CPU

in the diagram given? Can you remember what they do? See next slide…

5. Write down the sequence of operations the CPU has to perform to implement read accumulator from memory

19

Fill in the blanks

Possible question: What is the component labelled x?

Or: label the blanks