61
BASIC PROCESSING UNIT

Basic Processing Unit

Embed Size (px)

Citation preview

Page 1: Basic Processing Unit

BASIC PROCESSING UNIT

Page 2: Basic Processing Unit

Single-bus organization

Page 3: Basic Processing Unit

Single-bus organizationSteps for executing an instruction

1) Fetch the contents of memory location pointed by PC. The contents of this location is interpreted as instruction to be executed. Hence, they are loaded into IR.

IR [[PC]]

2) Assuming each instruction is of 4 bytes. PC is updated to point to the next instruction.

PC [PC] + 4

3) Carry out the actions specified by the instruction in the IR.Steps 1 and 2 are fetch phase, step 3 is execution phase.

Page 4: Basic Processing Unit

Single-bus organization

The multiplexer MUX selects either the output of register Y or a constant value 4 to be provided as input A of the ALU. The constant 4 is used to increment the contents of PC. The control input Select is to select Select4 and SelectY for selecting the constant 4 and register Y respectively.

Page 5: Basic Processing Unit

Single-bus organization

Page 6: Basic Processing Unit

Single-bus organization

Register TransferSuppose we want to transfer the contents of register R1 to register R4. Following steps are required.

1) Enable the output of register R1 by setting R1out to 1. This places the the contents of R1 on the processor bus.

2) Enable the the input of register R4 by setting R4in to 1. This loads the data from processor bus into register R4.

Page 7: Basic Processing Unit

Single-bus organizationPerforming Arithmetic and Logical operations

ALU performs operations on two operands. One operand is the output of multiplexer MUX and the other operand is obtained directly from the bus. The result produced by the ALU is stored temporarily in register Z.

Steps for executing instruction R3 R1 + R21) R1out , Yin

2)R2out, SelectY, Add, Zin

3) Zout, R3in

Page 8: Basic Processing Unit

Single-bus organization

Fetching a word from memory

Page 9: Basic Processing Unit

Single-bus organizationFetching a word from memory

Read Operation

Consider the instruction Move (R1), R2Steps for executing instruction1) MAR [R1]2) Start the read operation on memory bus3) Wait for the MFC (Memory FunctionCycle)

response from the memory.4) Load MDR from the memory bus.5) R2 [MDR]

Page 10: Basic Processing Unit

Single-bus organization

Read Operation

Move (R1), R21) R1out, MARin, Read2) MDRinE, WMFC3) MDRout, R2in

Page 11: Basic Processing Unit

Single-bus organizationStoring a Word in Memory

Write Operation

Consider the instruction Move R2, (R1)1) R1out, MARin2) R2out, MDRin, Write3) MDRoutE, WMFC

Page 12: Basic Processing Unit

Single-bus organizationExecuting the complete instruction

Consider the instruction Add (R3), R11) Fetch the instruction 2) Fetch the first operand ( the contents of the

memory location pointed to by R3).3) Perform the addition.4) Load the result in R1.

Page 13: Basic Processing Unit

Single-bus organizationExecuting the complete instruction

Add (R3), R11) Pcout, MARin, Read, Select4, Add, Zin2) Zout, PCin, Yin, WMFC3) MDRout, Irin4) R3out, MARin, Read5) R1out, Yin, WMFC6) MDRout, SelectY, Add, Zin7) Zout, R1in, End

Page 14: Basic Processing Unit

Branch Instruction• A branch instruction replaces the contents of

PC with the branch target address.

• This address is usually obtained by adding offset X, which is given in the branch instruction, to updated value of the PC.

• PCnew = PCcurrent + Offset (X)

Page 15: Basic Processing Unit

Branch InstructionControl Sequence for unconditional branch instruction1) PCout, MARin, Read, Select4, Add, Zin

2) Zout, PCin, Yin, WMFC

3) MDRout, IRin

4) Offset-field-of-IRout, SelectY, Add, Zin

5) Zout, PCin, End

Processing starts with Fetch phase. First 3 steps represent fetch phase. Fetch phase ends when the instruction is loaded in the IR. The offset value is extracted from IR by instruction decoding circuit . Since the value of updated PC is already available in register Y, the

offset value X is transferred onto the bus in step 4 and an addition operation is performed.

The result which is the branch target address is loaded into the PC in step 5.

Page 16: Basic Processing Unit

Branch InstructionControl Sequence for Conditional branch instruction In conditional branch, the status of condition code is

checked before loading a new value into the PC. For example, for a Branch-on-negative (Branch<0)

instruction, step 4 is replaced with

Offset-field-of-IRout, Add, Zin, If N=0 then End

If N=0 , the processor returns to step 1 immediately after step 4.

If N=1, step 5 is performed to load a new value into the PC =, thus performing the branch operation.

Page 17: Basic Processing Unit

Multiple-Bus Organization(Three-bus organization)

• In single-bus organization, as there is single bus, only one item can be transferred over the bus in a clock cycle.

• To reduce the number of steps needed, most commercial processors provide multiple internal paths (multiple-bus) that enable several transfers to take place in parallel.

Page 18: Basic Processing Unit

Multiple-Bus Organization(Three-bus organization)

Page 19: Basic Processing Unit

Three-bus organization

• Three bus organization is used to connect the registers and the ALU of a processor.

• All the general purpose registers are combined in a single block called the register file.

• The register file has two outputs, allowing the contents of two different registers to be accessed simultaneously and have their contents placed on buses A and B.

• The register file has one input from bus C to load a third register during the same clock cycle.

Page 20: Basic Processing Unit

Three-bus organization• Buses A and B are used to transfer the source

operands to the A and B inputs of the ALU, where arithmetic or logic operation may be performed. The result is transferred to the destination over bus C.

• If needed, the ALU may simply pass one of its two input operands unmodified to bus C. We call the ALU control signals for such an operation R=A or R=B

• Three bus organization eliminates the need of Y and Z register.

Page 21: Basic Processing Unit

Three-bus organization

• The Incrementer unit is used to increment the value of PC by 4. This eliminates the need of adding 4 to the PC using main ALU as in single bus orgnization.

• The source for the constant 4 at the ALU input multiplexer is still useful to increment other addresses such as memory addresses in LoadMultiple or StoreMultiple instructions.

Page 22: Basic Processing Unit

Three-bus organizationConsider the three-operand instruction

Add R4, R5, R6

1) Pcout, R=B, MARin, Read, IncPC2) WMFC3) MDRoutB, R=B, IRin4) R4outA, R5outB, SelectA, Add, R6in, End.

Page 23: Basic Processing Unit

Three-bus organizationAdd R4, R5, R6

• In step 1, the contents of PC are passed through the ALU, using the R=B control signal and loaded into the MAR to start a memory read operation. At the same time, PC is incremented by 4. Note that the value loaded in MAR is the original contents of the PC. The incremented value is loaded into the PC at the end of the clock cycle and will not affect the contents of the MAR.

• In step 2, the processor waits for MFC and loads the data received into the MDR, then transfers them to IR in step 3.

• Finally the execution phase of the instruction requires only one control step to complete, step 4.

Page 24: Basic Processing Unit

Generation of Control Signals

• The Control unit of the processor generates the control signals for execution of an instruction.

• There are two techniques for generating the control signals

1) Hardwired Control2) Microprogrammed Control

Page 25: Basic Processing Unit

Hardwired Control

Page 26: Basic Processing Unit

Hardwired Control• Consider the instruction Add (R3), R1Control steps for executing Add (R3), R1Step Action

1) Pcout, MARin, Read, Select4, Add, Zin2) Zout, PCin, Yin, WMFC3) MDRout, IRin4) R3out, MARin, Read5) R1out, Yin, WMFC6) MDRout, SelectY, Add, Zin7) Zout, R1in, End

Page 27: Basic Processing Unit

Hardwired Control• Each step in this sequence is completed in one clock cycle

period. A counter may be used to keep track of the control steps as shown in figure.

• Each state, or count, of this counter corresponds to one control step. The required control signals are determined by the following information.

• Contents of the control step counter• Contents of the instruction register• Contents of the condition code flags• External input signals, such as MFC and interrupt requests

Page 28: Basic Processing Unit

Hardwired Control

• The decoder/encoder is a combinational circuit that generates the required control outputs, depending on the state of all its inputs. By separating the decoding and encoding functions, we obtain the detailed block diagram as shown in figure below.

Page 29: Basic Processing Unit

Hardwired Control

Page 30: Basic Processing Unit

Hardwired Control• The step decoder provides a separate signal line for

each step, or time slot, in the control sequence. • Similarly, the output of the instruction decoder

consists of a separate line for each machine instruction.

• For any instruction loaded in the IR, one of the output lines INS1 though INSm is set to 1 and all other lines are set to 0.

• The input signals to the encoder block in figure are combined to generate the individual control signals Yin, PCout, Add, End and so on.

Page 31: Basic Processing Unit

Hardwired Control• An example how the encoder generates the Zin control signal for the processor

organization in single bus organization is shown in figure below.

Page 32: Basic Processing Unit

Hardwired Control

This circuit implements the logic function Zin = T1 + T6.ADD + T4.BR + …….

This signal is asserted during time slot T1 for all instructions, during T6 for an Add instruction , during T4 for an unconditional branch instruction and so on.

The logic function Zin is derived from the control sequences in figure 7.6 and 7.7.

Page 33: Basic Processing Unit

Hardwired Control

Page 34: Basic Processing Unit

Hardwired Control• The above circuit that generates the End control signal from the logic

function

End = T7.ADD + T5.BR + (T5.N + T4.N).BRN + ….

• The End signal starts a new instruction fetch cycle by resetting the control step counter to its starting value.

• Figure 7.11 contains another control signal called RUN. When set to 1, RUN causes the counter to be incremented by one at the end of every clock cycle. When RUN is equal to 0, the counter stops counting. This is needed whenever the WMFC signal is issued, to cause the processor to wait for the reply from the memory.

Page 35: Basic Processing Unit

A Complete Processor

Page 36: Basic Processing Unit

A Complete Processor

• Instruction unit fetches instruction from instruction cache or from the main memory when the desired instructions are not already in the cache.

• Separate processing units to deal with integer data and point-floating data.

• A data cache is inserted between these units and the main memory.

• The processor is connected to system bus and to rest of the computer by means of bus interface.

Page 37: Basic Processing Unit

Microprogrammed Control

• In Microprogrammed control, control signals are generated by a program similar to machine language programs.

Some common terms of microprogrammed control.Control Word (CW) Each of the control steps in the control sequence of an

instruction defines a unique combination of 1s and 0s in the CW. The control words corresponding to 7 steps of below program are shown in figure below.

Page 38: Basic Processing Unit

Microprogrammed Control• Consider the instruction Add (R3), R1Control steps for executing Add (R3), R11) PCout, MARin, Read, Select4, Add, Zin2) Zout, PCin, Yin, WMFC3) MDRout, Irin4) R3out, MARin, Read5) R1out, Yin, WMFC6) MDRout, SelectY, Add, Zin7) Zout, R1in, End

Page 39: Basic Processing Unit

Microprogrammed Control

Page 40: Basic Processing Unit

Microprogrammed Control

• We have assumed that SelectY is represented by Select=0 and Select4 by Select=1.

• A sequence of control words (CWs) corresponding to the control sequence of a machine instruction is called as the microroutine for that instruction and the individual control words in this microroutine are called as microinstructions.

Page 41: Basic Processing Unit

Microprogrammed Control

Page 42: Basic Processing Unit

Microprogrammed Control• The microroutine for all instructions in the instruction set of a

computer are stored in a special memory called the control store.• The control unit can generate the control signals for any

instruction by sequentially reading the CWs of the corresponding microroutine from the control store.

• To read the control words sequentially from the control store, a microprogram counter (µPC) is used.

• Every time a new instruction is loaded into the IR, the output of the block labeled “starting address generator” is loaded into the µPC.

• The µPC is then automatically incremented by the clock, causing successive microinstructions to be read from the control store. Hence, the control signals are delivered to various parts of the processor in the correct sequence.

Page 43: Basic Processing Unit

Microprogrammed Control

• To execute a Branch instruction, conditional branch microinstructions are used.

• In addition to branch address, these microinstructions specify which of the external inputs, condition codes or possibly bits of instruction register, should be checked as a condition for branching to take place.

Page 44: Basic Processing Unit

Microprogrammed Control

• The instruction Branch < 0 implemented by microroutine is given below.

AddressMicroinstruction0 PCout, MARin, Read, Select4, Add, Zin

1 Zout, PCin, Yin, WMFC

2 MDRout, IRin

3 Branch to starting address of appropriate microroutine

………………………………………………………………………….25 If N=0, then branch to microinstruction 026 Offset-field-of-IRout, SelectY, Add, Zin

27 Zout, PCin, End

Figure : Microroutine for the instruction Branch < 0

Page 45: Basic Processing Unit

Microprogrammed Control

• After loading instruction Branch < 0 into IR, a branch microinstruction transfers control to the corresponding microroutine, which is assumed to start at location 25 in the control store. This address is the output of the starting address generator block in fig. 7.16.

• The microinstruction at location 25 tests the N bit of the condition codes. If this is equal to 0, a branch takes place at location 0 to fetch a new machine instruction. Otherwise, the microinstruction at location 26 is executed to put the branch target address into register Z, as in step 4 in figure 7.17.

• The microinstruction in location 27 loads this address into the PC.

Page 46: Basic Processing Unit

Microprogrammed ControlTo support microprogram branching, the organization of the control unit is

modified as shown below in figure.

Page 47: Basic Processing Unit

Microprogrammed Control• The starting address generator block becomes the starting and branch address

generator. This block loads a new address into the µPC when a microinstruction instructs it to do so.

• To allow the implementation of a conditional branch, inputs to this block consist of the external inputs and condition codes as well as the contents of the IR.

• The µPC is incremented every time a new instruction is fetched from the microprogram memory except in the following situations.

1) When a new instruction is loaded into the IR, the µPC is loaded with the starting address of the microroutine for that instruction.

2) When a Branch microinstruction is encountered and the branch condition is satisfied, the µPC is loaded with the branch address.

3) When an End microinstruction is encountered, the µPC is loaded with the address of first CW in the microroutine for the instruction fetch cycle (this address is 0 in figure 7.17)

Page 48: Basic Processing Unit

Prefetching Microinstructions• One drawback of microprogrammed control is that it leads to a

slower operating speed because of the time it takes to fetch microinstructions from the control store.

• Faster operation may be achieved if the next microinstruction is prefetched while the current one is being executed.

• In this way, the execution time can be overlapped with the fetch time.

• Prefetching microinstructions present some organizational difficulties. Sometimes the status flags and the results of the currently executed microinstruction are needed to determine address of the next microinstruction.

• Thus straightforward prefetching occasionally prefetches a wrong microinstruction.

• In these cases, the fetch must be repeated with the correct address, which requires more complex hardware.

Page 49: Basic Processing Unit

Emulation• Given a computer with a certain instruction set, it is

possible to define additional machine instructions and implement them with extra microroutines.

• Programs written in the Machine language of M2 can be run on computer M1, that is, M1 emulates M2.

• If replacement computer fully emulates original one, then no software changes have to be made to run existing programs.

• Thus emulation facilitates transitions to new computer systems with minimal disruption.

• Emulation is easy for machines having similar architectures. But it is also succeeded for machines having totally different architectures.

Page 50: Basic Processing Unit
Page 51: Basic Processing Unit
Page 52: Basic Processing Unit

Arithmetic• Arithmetic operations in a computer occurs at

the machine instruction level.• Arithmetic operations are implemented using

basic logic functions such as AND, OR, NOT and Exclusive-OR in ALU of the processor.

• Logic operations are easy to implement as compared to arithmetic operations.

• Addition and subtraction are easy to implement.• Multiply and Divide operations require more

complex circuitry.

Page 53: Basic Processing Unit

Number RepresentationThere are three ways to represent numbers in the computer.

b3 b2 b1 b0 sign and 1’s complement 2’s complement

magnitude

0 1 1 1 +7 +7 +70 1 1 0 +6 +6 +60 1 0 1 +5 +5 +50 1 0 0 +4 +4 +40 0 1 1 +3 +3 +30 0 1 0 +2 +2 +20 0 0 1 +1 +1 +10 0 0 0 +0 +0 +01 0 0 0 -0 -7 -81 0 0 1 -1 -6 -71 0 1 0 -2 -5 -61 0 1 1 -3 -4 -51 1 0 0 -4 -3 -41 1 0 1 -5 -2 -31 1 1 0 -6 -1 -21 1 1 1 -7 -0 -1

Page 54: Basic Processing Unit

Addition of positive numbers

• Positive numbers are represented using sign and magnitude form.0 1 0 1

+ + + +0 0 1 1

_______________ ______ ______ 0 1 1 10

Carry-out

Page 55: Basic Processing Unit

Addition of positive numbersxi yi Carry-in(Ci) Sum (Si) Carry-out (Ci+1)

0 0 0 0 00 0 1 1 00 1 0 1 00 1 1 0 11 0 0 1 01 0 1 0 11 1 0 0 11 1 1 1 1

Page 56: Basic Processing Unit
Page 57: Basic Processing Unit
Page 58: Basic Processing Unit
Page 59: Basic Processing Unit
Page 60: Basic Processing Unit
Page 61: Basic Processing Unit