Sei sulla pagina 1di 27

# Lecture 14:

## DOC 112: Computer Hardware Lecture 14

Slide 1

A Manual Processor
Inside every computer there is at least one processor (CPU) which can take an instruction some operands and produce a result. Processors can be operated in various ways:
As a peripheral of another computer (array processor or graphics processor). One instruction at a time (e.g. a calculator).

Slide 2

## Block Diagram of a Processor

Both the data and the instruction will be binary numbers. The processing will be a sequence of one or more steps controlled by a clock.

## Data Manual Processor Instruction Result

Operate
DOC 112: Computer Hardware Lecture 14 Slide 3

## Block Diagram of the 8 bit Processor

We will build an 8-bit processor, and will have a common input stream for data and instructions. Both data and instructions will be organised in 8-bit bytes
Data or Instructions

Manual Processor

8 Result
Carry (out)

Operate
DOC 112: Computer Hardware Lecture 14 Slide 4

## How does a simple processor work?

Example: Average of two numbers. Result = (A+B)/2 The following steps must be carried out:
1. Set up the processor to receive the first number from the input stream and save it in a register called A 2. Set up the processor to receive the second number from the input stream and save it in a register called B

Slide 5

## How does a simple processor work?

3. Set the processor to add register A to register B. and then shift the result right by one bit. The operation is executed and the results may be stored internally in a results register. 4. Set up the processor to load the results on the output register.

## DOC 112: Computer Hardware Lecture 14

Slide 6

Designing a Processor
To design a general purpose processor, we need (at least):
Two data registers, A and B A Results register A register to hold the operation code (Instruction register(IR)). Circuits to do arithmetic and shifting

The results register may be augmented with a one-bit register which holds the carry out bit.

Slide 7

## The processor Data Paths

INPUT

8
A (8 bits)

8
Arithmetic and shift operations

Res (8 bits)

B (8 bits)

OUTPUT C bit

8
Instruction (8 bits)
DOC 112: Computer Hardware Lecture 14 Slide 8

## Internal Registers and the Data Paths

Notice that:
on the data paths diagram there is no information about when the data transfers occur. The diagram shows only the possible paths where data can be transferred. the arithmetic and shift operations are done by combinational circuits without more registers. The function that is computed is controlled by the bits in the instruction register. the processor is unable to execute further operations on the results.
DOC 112: Computer Hardware Lecture 14 Slide 9

## The Arithmetic - Logic Unit (4 bits)

Hardware design packages provide us with ArithmeticLogic Units of different precisions, for example 4 bit:

The select lines determine what function of A and B appears on the output
DOC 112: Computer Hardware Lecture 14 Slide 10

## The Arithmetic - Logic Unit (operations)

Selection Bits/Results 000 000 zero 001 B-A minus 010 A-B minus 011 A+B plus 100 A B xor 101 A or B or 110 A B and 111 1111 -1

This table assumes that Cin=0. When Cin=1, three arithmetic operations become:
011 : results = A plus B plus 1 010 : results = A minus B minus 1 001 : results = B minus A minus 1
DOC 112: Computer Hardware Lecture 14 Slide 11

Designing an ALU
An arithmetic logic unit is a simple combinatorial circuit that can be built from components that we have already designed. To provide the arithmetic functions we use adders and subtractors.
DOC 112: Computer Hardware Lecture 14 Slide 12

Designing an ALU
The logic functions are provided by simple gates. We need a multiplexer for each bit of the ALU we are designing.

## DOC 112: Computer Hardware Lecture 14

Slide 13

Designing an ALU
To finish the job we need one more multiplexer to provide the carry out.

Slide 14

## The Arithmetic - Logic Unit (8 bits)

We could design an ALU for any bit size we want, but often it is useful to proceed functionally. For example we can build an 8 bit ALU out of two four bit circuits.

Slide 15

## The Control of the C(in) Bit

We can use a 2-to-1 multiplexer to allow two different carry input bits. The Carry(in) may come from Carry(out), this helps multiple precision.
F/cy A B
8 8

F/alu (3 bits)

A B
1

8 8

8 bit ALU
Cin Cout

Out

MUX

Cy/out

It can also be set to logic 1 in order to use the extra three arithmetic functions. Clearing the C flip-flop will supply a logic Hardware Lecture 14 DOC 112: Computer 0. Slide 16

## The Shifter Circuit

Earlier in the course we discussed a specialised register, called the shift register, which could shift its contents let or right depending on a multiplexer selection. We could incorporate such a shift register in our design, but, to save on circuitry, we will make use of a simpler shifter which does not store the result.

Slide 17

## The Binary Shifter

F/shift
2

Data in
8

Data out

CYin

Shifter

The Binary Shifter circuit is a combinational circuit. It has eight input data bits plus a carry in, and 2 function selection bits which determine the data out.
DOC 112: Computer Hardware Lecture 14 Slide 18

## Important Shifting Functions

ARITHMETIC LEFT SHIFT MSB LSB Cy

## ARITHMETIC RIGHT SHIFT

MSB LSB

ROTATE RIGHT
DOC 112: Computer Hardware Lecture 14

MSB LSB
Slide 19

## The Shifter - basic design

The basic shifter will perform four operations depending on its two control inputs. These are:
00 01 10 11 Hold Arithmetic shift left (with carry in) Arithmetic shift right Rotate right

## It is implemented simply using multiplexers. There is one multiplexer per bit.

DOC 112: Computer Hardware Lecture 14 Slide 20

## The Shifter - Basic design

An eight bit shifter is shown, but clearly the design can be easily scaled up to any size.

00: Hold 01: Shift left with carry 10: Arithmetic shift right 11: Rotate right
DOC 112: Computer Hardware Lecture 14 Slide 21

## Increasing the Shifter functionality

There are many different possible shifts that programmers may want to use. One possibility our design doesn't do is:
0 Logical Shift Right MSB LSB

This could be done by using first an ALU operation (Data AND 11111110) followed by a rotate right, but that would involve more processing steps and therefore be slow.
DOC 112: Computer Hardware Lecture 14 Slide 22

## Increasing the shifter functionality

An alternative would be to add another multiplexer to implement the shift directly. This would mean a faster processor but at the cost of more hardware.
F/shift

F/cin
Data in Data in 0
8

Data out

MUX

Carry in

Shifter
Slide 23

## Increasing the shifter functionality

More functionality can be provided by making the carry multiplexer four way. F/shft F/Cin
Input
8

Output
8

## Input 0 Input CYin

Shifter

MUX 00 -01 -10 -11 Input 0 Input Carry in 00 -01 -10 -11 -unchanged left shift right shift right shift
Slide 24

## Function Table of the Shifter

A variety of shifts is now provided, but functions [0,0,0] and [1,0,0] are the same.

Slide 25

Slide 26

Data In
IR7
8

IR0

Control Unit

IR

ClkIR

SelA MUX
8

F-ALU A ClkA
8 8

A B Res
8

## F-Shifter SHIFTER RES ClkR

8

B ClkB SelC
1

Data Out

ALU
CY-in CY-out C ClkC

MUX

Carry Out

Slide 27