Module 3 DDCO
Module 3 DDCO
Arithmetic
Input and
logic
Memory
Output Control
I/O Processor
Registers
• Instruction register (IR)
• Program counter (PC)
• General-purpose register (R0 – Rn-1)
• Memory address register (MAR)
• Memory data register (MDR)
Typical Operating Steps
• Programs reside in the memory through input devices
• PC is set to point to the first instruction
• The contents of PC are transferred to MAR
• A Read signal is sent to the memory
• The first instruction is read out and loaded into MDR
• The contents of MDR are transferred to IR
• Decode and execute the instruction
Typical Operating Steps
• Get operands for ALU
➢General-purpose register
➢Memory (address to MAR – Read – MDR to ALU)
• Perform operation in ALU
• Store the result back
➢To general-purpose register
➢To memory (address to MAR, result to MDR – Write)
• During the execution, PC is incremented to
the next instruction
Interrupt
• Normal execution of programs may be preempted if
some device requires urgent servicing.
• The normal execution of the current program must be
interrupted – the device raises an interrupt signal.
• Interrupt-service routine
• Current system information backup and restore (PC,
general-purpose registers, control information, specific
information)
Bus Structures
• There are many ways to connect different parts
inside a computer together.
• A group of lines that serves as a connecting path for
several devices is called a bus.
• Address/data/control
Single-bus structure
Speed Issue
• Different devices have different transfer/operate
speed.
• If the speed of bus is bounded by the slowest device
connected to it, the efficiency will be very low.
• How to solve this?
• A common approach – use buffers.
Performance
• The most important measure of a computer is how
quickly it can execute programs.
• Three factors affect performance:
➢Hardware design
➢Instruction set
➢Compiler
Main Cache
memory memory Processor
Bus
Performance
• Elapsed time and Processor time
• Processor time to execute a program depends on
the hardware involved in the execution of
individual machine instructions.
• The processor and a relatively small cache memory
can be fabricated on a single integrated circuit chip.
• Speed
• Cost
• Memory management
Processor Clock
N S
Program execution time, T =
R
Pipeline and Superscalar Operation
• Instructions are not necessarily executed one after
another.
• The value of S doesn’t have to be the number of clock
cycles to execute one instruction.
• Pipelining – overlapping the execution of successive
instructions.
Add R1, R2, R3
• Superscalar operation – multiple instruction pipelines
are implemented in the processor.
• Goal – reduce S (could become <1!)
Clock Rate
• Increase clock rate
➢Improve the integrated-circuit (IC) technology to make
the circuits faster
➢Reduce the amount of processing done in one basic step
(however, this may increase the number of basic steps
needed)
• Increases in R that are entirely caused by
improvements in IC technology affect all aspects of
the processor’s operation equally except the time
to access the main memory.
CISC and RISC
• Tradeoff between N and S
• A key consideration is the use of pipelining
➢S is close to 1 even though the number of basic steps
per instruction may be considerably larger
➢It is much easier to implement efficient pipelining in
processor with simple instruction sets
• Reduced Instruction Set Computers (RISC)
• Complex Instruction Set Computers (CISC)
• Both are design principles and technique.
Compiler
• A compiler translates a high-level language program
into a sequence of machine instructions.
• To reduce N, we need a suitable machine instruction
set and a compiler that makes good use of it.
• Goal, Optimizing compiler – reduce N×S
• A compiler may not be designed for a specific
processor; however, a high-quality compiler is usually
designed for, and with, a specific processor.
Performance measurement
• Computer Designer, Manufacturer and Buyers will look through the
performance measure of any computer system.
• Performance measurement uses some benchmark programs.
• SPEC(System Performance Evaluation Corporation) selects & publishes the
standard programs along with their test results for different application domains
• The SPEC rating is computed as follows;
• If SPEC rating=50 means that the computer under test is 50times as fast as
reference computer.
• The test is repeated for all the programs in the SPEC suite, and the geometric
mean of the results is computed.
• Let SPECi be the rating for program i in the suite. The overall SPEC rating for
the computer is given by ;
last word
Memory words
Memory Location, Addresses, and Operation
32-bit word length example
32 bits
b 31 b 30 b1 b0
•
•
•
Sign bit: b 31= 0 for positive numbers
b 31= 1 for negative numbers
0 0 1 2 3 0 3 2 1 0
4 4 5 6 7 4 7 6 5 4
• •
• •
• •
k k k k k k k k k k
2 -4 2 -4 2 -3 2 - 2 2 - 1 2 - 4 2 - 1 2 - 2 2 -3 2 -4
Instruction
Opcode Operand(s) or Address(es)
Instruction Formats
The ordering of source and destination operands is different
In different computers.
Modern computers have number of General purpose
Registers(8 to 32).
Example: Load A
Add B
Store C
Example: Evaluate (A+B) (C+D)
• Three-Address
1. ADD R1, A, B ; R1 ← M[A] + M[B]
2. ADD R2, C, D ; R2 ← M[C] + M[D]
3. MUL X, R1, R2 ; M[X] ← R1 R2
Instruction Formats
Example: Evaluate (A+B) (C+D)
• Two-Address
1. MOV R1, A ; R1 ← M[A]
2. ADD R1, B ; R1 ← R1 + M[B]
3. MOV R2, C ; R2 ← M[C]
4. ADD R2, D ; R2 ← R2 + M[D]
5. MUL R1, R2 ; R1 ← R1 R2
6. MOV X, R1 ; M[X] ← R1
Instruction Formats
Example: Evaluate (A+B) (C+D)
• One-Address
1. LOAD A ; AC ← M[A]
2. ADD B ; AC ← AC + M[B]
3. STORE T ; M[T] ← AC
4. LOAD C ; AC ← M[C]
5. ADD D ; AC ← AC + M[D]
6. MUL T ; AC ← AC M[T]
7. STORE X ; M[X] ← AC
Instruction Formats
Example: Evaluate (A+B) (C+D)
• Zero-Address
1. PUSH A ; TOS ← A
2. PUSH B ; TOS ← B
3. ADD ; TOS ← (A + B)
4. PUSH C ; TOS ← C
5. PUSH D ; TOS ← D
6. ADD ; TOS ← (C + D)
7. MUL ; TOS ← (C+D)(A+B)
8. POP X ; M[X] ← TOS
Instruction Formats
Example: Evaluate (A+B) (C+D)
• RISC
1. LOAD R1, A ; R1 ← M[A]
2. LOAD R2, B ; R2 ← M[B]
3. LOAD R3, C ; R3 ← M[C]
4. LOAD R4, D ; R4 ← M[D]
5. ADD R1, R1, R2 ; R1 ← R1 + R2
6. ADD R3, R3, R4 ; R3 ← R3 + R4
7. MUL R1, R1, R3 ; R1 ← R1 R3
8. STORE X, R1 ; M[X] ← R1
• Let Ri is general purpose registers;
Load A, Ri
Store Ri, A
Add A, Ri
• Example: C=A+B
Mov A, Ri Mov A, Ri
Mov B, Rj Add B, Ri
Add Ri, Rj Mov Ri, C
Mov Rj, C
Using Registers
• Registers are faster
• Shorter instructions
• The number of registers is smaller (e.g. 32 registers need
5 bits)
• Potential speedup
• Minimize the frequency with which data is moved
back and forth between the memory and processor
registers.
Instruction Execution and Straight-
Line Sequencing
Address Contents
i
Assumptions:
Begin execution here Move A,R0
3-instruction - One memory operand per
i +4 Add B,R0 program
segment instruction
i +8 Move R0,C
- 32-bit word length
- Memory is byte addressable
- Full memory address can
A be directly specified in
single-word instruction
B Data for
the program Two-phase procedure
-Instruction fetch
-Instruction execute
C
•
•
•
i + 4n - 4 Add NUM n,R0
i + 4n Move R0,SUM
•
•
•
SUM
NUM1
NUM2
•
•
•
NUM n
Branching LOOP
Clear R0
Determine address of
"Next" number and add
Program "Next" number to R0
loop
Decrement R1
Branch>0 LOOP
Branch target
Move R0,SUM
Conditional branch
•
•
•
SUM
N n
NUM1
NUM2
•
•
A loop to add n numbers •
NUM n
Condition Codes
• Condition code flags (individual bits)
• Condition code register / status register
➢N (negative)- Set to 1, if the result is negative, else 0
➢Z (zero)-Set to 1, if the result is zero, else 0
➢V (overflow)- Set to 1, if arithmetic overflow occurs,
else 0
➢C (carry)-Set to 1, if a carry out result there in
arithmetic operation
• Different instructions affect different flags
Generating Memory Addresses
• How to specify the address of branch target?
• Can we give the memory operand address directly
in a single Add instruction in the loop?
• Use a register to hold the address of NUM1; then
increment by 4 on each pass through the loop.
Addressing Modes
• Data Structures- Programmers use organizing the data. (list,
arrays, queues)
• Programmers use arrays, pointers, local and global variables,
constants.
• Location of an operand is specified in an instruction –
addressing modes.
Instruction
Opcode Mode ...
• Implied
• AC is implied in “ADD M[A]” in “One-Address” instr.
• TOS is implied in “ADD” in “Zero-Address” instr.
• Immediate
• The use of a constant in “MOV R1, 5”, i.e. R1 ← 5
• Register
• Indicate which register holds the operand
Addressing Modes
• Register Indirect
• Indicate the register that holds the number of the register
that holds the operand
MOV R1, (R2) R1
• Autoincrement / Autodecrement R2 = 3
• Access & update in 1 instr.
• Direct Address R3 = 5
• Use the given address to access a memory location
AR = 101
Memory
100
101 0 1 0 4
102
103
104 1 1 0 A
Addressing Modes
• Relative Address Memory
• EA = PC + Relative Addr 0
a m
1
g r
PC = 2 2
r o
P
+
100
t a
a
AR = 100
D
101
102 1 1 0 A
Could be Positive or 103
Negative 104
(2’s Complement)
Addressing Modes
• Indexed
• EA = Index Register + Relative Addr Memory
Useful with XR = 2
“Autoincrement” or
“Autodecrement”
+
100
AR = 100
101
Could be Positive or
Negative 102 1 1 0 A
(2’s Complement) 103
104
Addressing Modes
• Base Register
• EA = Base Register + Relative Addr Memory
Could be Positive or AR = 2
Negative
(2’s Complement)
+
100 0 0 0 5
BR = 100
101 0 0 1 2
102 0 0 0 A
Usually points to 103 0 1 0 7
the beginning of 104 0 0 5 9
an array
Addressing Modes
Move N,R1
Move #NUM1,R2 Initialization
Clear R0
LOOP Add (R2)+,R0
Decrement R1
Branch>0 LOOP
Move R0,SUM