Professional Documents
Culture Documents
Contents
Basic Operational Concepts
Organization of ALU
Stack Organization
Instruction Execution
Instruction Cycle
Pipelining
Addressing Modes
Instruction Formats
Hardwired and micro programmed control unit
RISC vs CISC
1
Organization of ALU
Let’s see the CPU first
2
cont.…
3
Cont.…
4
Cont.…
The basic function of a CPU is to:
◦ Fetch
◦ decode and
◦ execute instructions held in ROM or RAM.
These are the process by which a computer retrieves a program
instruction from its memory, determines what actions the instruction
requires, and carries out those actions.
The whole process is done in an instruction cycle (sometimes called
fetch-decode-execute (FDX))
5
Cont.…
Hence, instruction cycle is the amount of time for fetching,
decoding and executing of a single instruction.
In simpler CPUs, the instruction cycle is executed sequentially:
◦ each instruction is completely processed before the next one is
started.
In most modern CPUs, the instruction cycle is instead executed
concurrently in parallel, as an instruction pipeline:
◦ the next instruction starts being processed before the previous
instruction is finished
6
Typically,clock signals are generated by a quartz crystal, which
generates a constant signal wave while power is applied.
Cont.…
instruction cycle
7
Cont.…
The circuits used in the CPU during the cycle are:
Program counter (PC) - an incrementing counter that keeps
track of the memory address of the instruction that is to be
executed next.
Memory address register (MAR) - holds the address of a
memory block to be read from or written to.
Memory data register (MDR) - a two-way register that
holds data fetched from memory (and ready for the CPU
to process) or data waiting to be stored in memory
Instruction register (IR) - a temporary holding ground for
the instruction that has just been fetched from memory 8
Control unit (CU) - decodes the program instruction in the IR,
selecting machine resources such as a data source register and a
particular arithmetic operation, and coordinates activation of those
resources
Arithmetic logic unit (ALU) - performs mathematical and logical
operations.
◦ Hence the ALU is the basic part of the computer system that performs
mathematical and logical operations in every instruction cycle.
Cont.…
◦ For example let’s see a one bit ALU that performs arithmetic and logical
9
operations.
Block diagram of 1 bit ALU
10
Count..
Count..
Count..
Count..
Count..
Steps in program Execution
Fetch the Instruction (address in Program Counter PC)
Increment PC (prepared to get next instruction)
Decode the Instruction (find out tasks to do)
Fetch the Operands (data needed for the tasks)
Execute the Operation (do the tasks, may involve ALU)
Summary
Store the Results (in a register or in memory)
16
Repeat For the next instruction
Execution Cycle
Next
Determine successor instruction
Instruction
17
S A stack is a sequence of items that are accessible
at only one end of the sequence
stack
18
Stack operations
There are three basic stack terms we should know
1) The Push instruction
put the value of the data in register in to the top of the
stack.
19
Cont’d…
2) The POP instruction
◦ take the value on the top of the stack memory
20
Cont’d…
3) Top of stack
◦ The place in the stack memory which is ready to be
accessed
21
A general block diagram of stack operation
22
Summary of stack
Itis LIFO system Last In First Out
Example See how the elephant comes to the first
location and the bird will be at the last in stack point of
view.
23
Example cont’d…
24
Cont’d…
25
Accessing stack example cont’d..
26
Accessing stack with example
27
In stack we can access the data on the
top
28
Computer programming languages
end_of_loop:
HIGH LEVEL LANGUAGE
From the foregoing we can see that assembly language is
not much of an improvement on machine code!
A more problem-oriented (rather than machine-oriented)
mechanism for creating computer programs would also
be desirable.
Hence the advent of high(er) level languages
commencing with the introduction of “Autocodes”, and
going on to Fortran, Pascal, Basic, C, C++, java etc.
The HLL must be converted in to machine language to
be executed. This is done by compiler.
32
PIPELINING
33
What is Pipelining ?
A technique used in advanced microprocessors where the
microprocessor begins executing a second instruction before the
first has been completed.
A Pipeline is a series of stages, where some work is done at each
stage. The work is not finished until it has passed through all stages.
With pipelining, the computer architecture allows the next
instructions to be fetched while the processor is performing
arithmetic operations, holding them in a buffer close to the
processor until each instruction operation can performed.
34
Consider an example with 6 stages
◦ FI = fetch instruction
◦ DI = decode instruction
◦ CO = calculate location of operand
◦ FO = fetch operand
◦ EI = execute instruction
◦ WO = write operand
Pipelining (store result)
(continued)
35
Pipelining Example
X X
Instruction 4 Instruction 3
X X
Four sample instructions, executed linearly
Example
37
5
IF ID EX M W
1
IF ID EX M W
1
IF ID EX M W
1
IF ID EX M W
38
Description of each step
The instruction Fetch (IF) stage is responsible for obtaining
the requested instruction from memory.
The Instruction Decode (ID) stage is responsible for
decoding the instruction and sending out the various control
lines to the other parts of the processor.
The Execution (EX) stage is where any calculations are
performed. The main component in this stage is the ALU. The
ALU is made up of arithmetic, logic and capabilities.
39
Cont’d…
40
Operation Timings
Instruction 2ns
Estimated timings for each of Fetch
the stages:
Instruction 1ns
Decode
Execution 2ns
Memory 2ns
and IO
Write Back 1ns
41
Advantages/Disadvantages of pipelining
Advantages:
More efficient use of processor
Quicker time of execution of large number of
instructions
Disadvantages:
Pipelining involves adding hardware to the chip
Inability to continuously run the pipeline at full speed
because of pipeline hazards which disrupt the smooth
execution of the pipeline. 42
Pipeline Hazards
Data Hazards – an instruction uses the result of the previous
instruction. A hazard occurs exactly when an instruction tries
to read a register in its ID stage that an earlier instruction
intends to write in its WB stage.
43
ta Hazards
Select R2 and R3 for ADD R2 and R3 STORE SUM IN
ALU Operations R1
44
Solution Stalling
STALL IF ID EX M WB
STALL IF ID EX M WB
STALL IF ID EX M WB
45
SUB R4, R1, R5 IF ID EX M WB
Addressing modes
◦ Direct
◦ Indirect
◦ Register
◦ Register Indirect
◦ Displacement (Indexed)
◦ Stack
47
Immediate Addressing
◦ 5 is operand
Instruction
Opcode Address A
Memory
Operand
50
Indirect Addressing (1)
51
Indirect Addressing (2)
Instruction
Opcode Address A
Memory
Pointer to operand
Operand
53
Register Addressing (1)
54
Register Addressing (2)
55
Register Addressing Diagram
Instruction
Operand
56
Register Indirect Addressing
EA = (R)
Operand is in memory cell pointed to by contents of
register R
Large address space (2n)
One fewer memory access than indirect addressing
57
Register Indirect Addressing Diagram
Instruction
Registers
58
Displacement Addressing
EA = A + (R)
Address field hold two values
◦ A = base value
◦ R = register that holds displacement
◦ or vice versa
59
Displacement Addressing Diagram
Instruction
Registers
60
Stack Addressing
D
C
B
A
61
Comparison of Microprogrammed and hardwired CU
62
Basic CPU Architectures
63
RISC and CISC
Save/Restore based on procedure nesting depth Save/Restore based on cache replacement algorithm
RISC Characteristics
◦ One instruction per cycle
◦ Register to register operations
◦ Few, simple addressing modes
◦ Few, simple instruction formats
◦ Fixed instruction format
5. RISC versus CISC Controversy
Quantitative
◦ compare program sizes and execution speeds
Qualitative
◦ examine issues of high level language support and use of VLSI
real estate
Problems
◦ No pair of RISC and CISC that are directly comparable
◦ No definitive set of test programs
◦ Difficult to separate hardware effects from complier effects
◦ Most commercial devices are a mixture
Comparison of CISC and RISC
CISC RISC
Complex,
Simple hard-wired machine code and
powerful instructions
control unit
Numerous memory addressing options
Compiler and IC developed
for operands
simultaneously
Have micro programmed CU
Have hardwired CU
CISC systems shorten execution time RISC systems shorten execution time by
by reducing the number of instructions reducing the clock cycles per instruction
per program 79
Exercise
1) What is the advantage of micro programmed CU over
hardwired CU and Vis.versa?
2) a) how many types of CPU architectures do we have?
Mention them
80
3) if mov instruction needs 1cycle , ADD needs 1 cycle
and loop needs 1 cycle,
A) what is the total cycle for the ff program
Mov Ax,5
Mov Cx,3
again:Add Ax,Ax
Loop again
B) What is the values of registers Ax and Cx
after the execution of the program
cont’d…
81
Overview of CU and timing diagram
82
A Simplified Control Unit
Fetch
Fetch Unit
Decode
Decode Unit
Write Back
Write Back Unit
83
Timing Diagram
CLK
Fetch
Decode
Execute
Write Back
84
Let’s Sample The Signals
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
85
Another Way to Generate Signals
1000
0100
0010
0001
86