UNIT 1 - Basic Structure of Computers
UNIT 1 - Basic Structure of Computers
of Computers
Functional Units
Functional Units
Arithmetic
Input and
logic
Memory
Output Control
I/O Processor
Data
PC Address Register #
Register A
Instructions Bank L Address
U
Register #
Instruction Data Memory
Memory
Register #
Data
MAR MDR
Control
PC R0
R1
Processor
IR
ALU
Rn - 1
n general purpose
registers
Main Cache
memory memory Processor
Bus
N S
T
R
How to improve T?
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)
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 – 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
T is difficult to compute.
Measure computer performance using benchmark programs.
System Performance Evaluation Corporation (SPEC) selects and
publishes representative application programs for different application
domains, together with test results for many commercially available
computers.
Compile and run (no simulation)
Reference computer
i 1
Machine Instructions
and Programs
Objectives
Machine instructions and program execution,
including branching and subroutine call and return
operations.
Number representation and addition/subtraction in
the 2’s-complement system.
Addressing methods for accessing register and
memory operands.
Assembly language for representing machine
instructions, data, and programs.
Program-controlled Input/Output operations.
Memory Locations,
Addresses, and
Operations
Memory Location, Addresses,
and Operation
n bits
first word
Memory consists
second word
of many millions of
storage cells,
each of which can •
store 1 bit. •
•
Data is usually i th word
accessed in n-bit
groups. n is called
word length. •
•
•
last word
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
1. LOAD A ; AC ← M[A]
2. ADD B ; AC ← AC + M[B]
3. STORET ; M[T] ← AC
4. LOAD C ; AC ← M[C]
5. ADD D ; AC ← AC + M[D]
6. MUL T ; AC ← AC M[T]
7. STOREX ; 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
i
Assumptions:
Begin execution here Move A,R0
i +4
3-instruction
program
- One memory operand
Add B,R0
i +8
segment per instruction
Move R0,C
- 32-bit word length
- Memory is byte
addressable
A - Full memory address
can be directly specified
in a single-word instruction
B Data for
the program
Two-phase procedure
-Instruction fetch
-Instruction execute
C
Page 43
•
•
•
i + 4n - 4 Add NUMn,R0
i + 4n Move R0,SUM
•
•
•
SUM
NUM1
NUM2
•
•
•
NUMn
Branching LOOP
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
•
•
NUMn
•
Condition Codes
Condition code flags
Condition code register / status register
N (negative)
Z (zero)
V (overflow)
C (carry)
Different instructions affect different flags
Conditional Branch
Instructions
Example: A: 11110000
A: 1 1 1 1 0 0 0 0 +(−B): 1 1 1 0 1 1 0 0
B: 0 0 0 1 0 1 0 0 11011100
C=1 Z=0
S=1
V=0
Status Bits
Cn-1
A B
Cn ALU
F
V Z S C
Fn-1
Zero Check
Addressing Modes
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
100
101 0 1 0 4
102
103
104 1 1 0 A
Addressing Modes
Relative Address
0
EA = PC + Relative Addr 1
PC = 2 2
100
AR = 100
101
102 1 1 0 A
Could be Positive 103
or Negative 104
(2’s Complement)
Addressing Modes
Indexed
EA = Index Register + Relative Addr
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
Could be Positive AR = 2
or Negative
(2’s Complement)
+
100 0 0 0 5
BR = 100
101 0 0 1 2
102 0 0 0 A
Usually points 103 0 1 0 7
to the beginning 104 0 0 5 9
of an array
Addressing Modes
Name Assem bler syn tax Addressing function
The different
ways in which Immediate #Value Op erand = Value
the location of
an operand is Register Ri EA = Ri
specified in Absolute (Direct) LOC EA = LOC
an instruction
are referred to Indirect (Ri ) EA = [Ri ]
as addressing (LOC) EA = [LOC]
modes.
Index X(R i) EA = [Ri ] + X
Figure 2.16. The Autoincrement addressing mode used in the program of Figure 2.12.
Assembly Language
Types of Instructions
Data Transfer Instructions
Name Mnemonic Data value is
Load LD not modified
Store ST
Move MOV
Exchange XCH
Input IN
Output OUT
Push PUSH
Pop POP
Data Transfer Instructions
Mode Assembly Register Transfer
Direct address LD ADR AC ← M[ADR]
Indirect address LD @ADR AC ← M[M[ADR]]
Relative address LD $ADR AC ← M[PC+ADR]
Immediate operand LD #NBR AC ← NBR
Index addressing LD ADR(X) AC ← M[ADR+XR]
Register LD R1 AC ← R1
Register indirect LD (R1) AC ← M[R1]
Autoincrement LD (R1)+ AC ← M[R1], R1 ← R1+1
Data Manipulation Instructions
Arithmetic Name Mnemonic
Increment INC
Logical & Bit Manipulation Decrement DEC
Add ADD
Shift Subtract SUB
Multiply MUL
Divide DIV
Name Mnemonic Add with carry ADDC
Clear CLR Subtract with borrow SUBB
Complement COM Name Negate MnemonicNEG
AND AND Logical shift right SHR
OR OR Logical shift left SHL
Exclusive-OR XOR Arithmetic shift right SHRA
Clear carry CLRC Arithmetic shift left SHLA
Set carry SETC Rotate right ROR
Complement Rotate left ROL
COMC
carry Rotate right through
Enable interrupt EI RORC
carry
Program Control Instructions
Name Mnemonic
Branch BR
Jump JMP
Skip SKP
Subtract A – B but
Call CALL don’t store the result
Return RET
Compare
CMP
(Subtract) 10110001
Test (AND) TST
00001000
Mask
00000000
Conditional Branch
Instructions
Processor
DATAIN DATAOUT
SIN SOUT
- Registers
- Flags Keyboard Display
- Device interface
Current
Top of Stack
LIFO TOS 0
Last In First Out 1
2
3
4
5
SP 6 0 1 2 3
7 0 0 5 5
FULL EMPTY 8 0 0 0 8
9 0 0 2 5
Stack Bottom 10 0 0 1 5
Stack
Stack Organization
Current 1 6 9 0
Top of Stack
PUSH TOS 0
SP ← SP – 1 1
M[SP] ← DR 2
3
If (SP = 0) then (FULL ← 1) 4
EMPTY ← 0 5 1 6 9 0
SP 6 0 1 2 3
7 0 0 5 5
FULL EMPTY 8 0 0 0 8
9 0 0 2 5
Stack Bottom 10 0 0 1 5
Stack
Stack Organization
Current
Top of Stack
POP TOS 0
DR ← M[SP] 1
SP ← SP + 1 2
3
If (SP = 11) then (EMPTY ← 1) 4
FULL ← 0 5 1 6 9 0
SP 6 0 1 2 3
7 0 0 5 5
FULL EMPTY 8 0 0 0 8
9 0 0 2 5
Stack Bottom 10 0 0 1 5
Stack
Stack Organization
Memory Stack
PUSH PC 0
1
SP ← SP – 1 2
M[SP] ← DR
POP AR 100
101
DR ← M[SP]
102
SP ← SP + 1
200
SP 201
202