Basic Structure of Computers
Basic Structure of Computers
Computers
C.Bala Subramanian,
AP/CSE,
KLU
Memory
Output Control
I/O Processor
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?
i 1
0 1 1 1 + 7 +7 + 7
0 1 1 0 + 6 +6 + 6
0 1 0 1 + 5 +5 + 5
0 1 0 0 + 4 +4 + 4
0 0 1 1 + 3 +3 + 3
0 0 1 0 + 2 +2 + 2
0 0 0 1 + 1 + 1 + 1
0 0 0 0 + 0 +0 + 0
1 0 0 0 - 0 -7 - 8
1 0 0 1 - 1 -6 - 7
1 0 1 0 - 2 -5 - 6
1 0 1 1 - 3 -4 - 5
1 1 0 0 - 4 -3 - 4
1 1 0 1 - 5 -2 - 3
1 1 1 0 - 6 - 1 - 2
1 1 1 1 - 7 -0 - 1
-1 +0 -1 +0
-2 1111 0000 +1 -2 1111 0000 +1
1110 0001 1110 0001
-3 +2 -3
1101 1101 +2
0010 0010
-4 -4
1100 0011 +3 1100 0011 +3
-5 1011 -5 1011
0100 +4 0100 +4
1010 1010
-6 0101 -6 0101
1001
+5 +5
0110 1001
0110
-7 1000 0111 +6 -7 1000 +6
0111
-8 +7 -8 +7
5 + 3 = -8 -7 - 2 = +7
C.Bala Subramanian, AP/CSE, KLU 42
Overflow Conditions
0111 1000
5 0101 -7 1001
3 0011 -2 1100
-8 1000 7 10111
Overflow Overflow
0000 1111
5 0101 -3 1101
2 0010 -5 1011
7 0111 -8 11000
No overflow No overflow
Overflow when carry-in to the high-order bit does not equal carry out
C.Bala Subramanian, AP/CSE, KLU 43
Sign Extension
Task:
Given w-bit signed integer x
Rule:
Make k copies of sign bit:
• • •
X • • • • • •
k
C.Bala Subramanian, AP/CSE, KLU w 44
Sign Extension Example
last word
C.Bala Subramanian, AP/CSE, KLU 47
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
Opcode C.Bala
Operand(s) or Address(es)
Subramanian, AP/CSE, KLU 59
Instruction Formats
Example: Evaluate (A+B) (C+D)
Three-Address
1. ADD A, B, R1 ; R1 ← M[A] + M[B]
2. ADD C, D, R2 ; R2 ← M[C] + M[D]
3. MUL R1, R2, X ; M[X] ← R1 R2
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 NUM n,R0
i + 4n Move R0,SUM
•
•
•
SUM
NUM1
NUM2
•
•
•
NUM n
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
•
•
•
NUM nAP/CSE, KLU
C.Bala Subramanian, 66
Condition Codes
Condition code flags
Condition code register / status register
N (negative)
Z (zero)
V (overflow)
C (carry)
Different instructions affect different flags
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
Cn-1
A B
Cn ALU
F
V Z S C
Fn-1
Zero Check
Direct Address
Use the given address to access a memory
location
100
101 0 1 0 4
102
103
104 1 1 0 A
Relative Address
0
EA = PC + Relative Addr 1
PC = 2 2
100
AR = 100
101
102 1 1 0 A
Could be Positive or 103
Negative 104
(2’s Complement)
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
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
Autoincremen t (R i )+ EA = [R i ] ;
Incremen t R i
Autodecrement (R i )
C.Bala Subramanian, AP/CSE, KLU
Decremen t R i ; 78
EA = [R i]
Indexing and Arrays
Index mode – the effective address of the operand
is generated by adding a constant value to the
contents of a register.
Index register
X(Ri): EA = X + [Ri]
The constant X may be given either as an explicit
number or as a symbolic name representing a
numerical value.
If X is shorter than a word, sign-extension is needed.
Figure 2.16. The Autoincrement addressing mode used in the program of Figure 2.12.
Assembly
Language
Return RET
Compare
CMP
(Subtract) 10110001
Test (AND) TST
00001000
Mask
00000000
C.Bala Subramanian, AP/CSE, KLU 87
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
C.Bala Subramanian, AP/CSE, KLU 98
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
C.Bala Subramanian, AP/CSE, KLU 99
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
C.Bala Subramanian, AP/CSE, KLU 100
Stack Organization
Memory Stack
PUSH PC 0
1
SP ← SP – 1 2
M[SP] ← DR
POP AR 100
DR ← M[SP] 101
102
SP ← SP + 1
200
SP 201
202
(A B +) (D E +) C F +
Stack Operation
(3) (4) (5) (6) +
PUSH 3
PUSH 4
6
MULT
PUSH 5 30
4
5
PUSH 6
3
42
12
MULT
ADD
C.Bala Subramanian, AP/CSE, KLU 104
Additional
Instructions
before: 0 0 1 1 1 0 . . . 0 1 1
after: 1 1 1 0 . . . 0 1 1 0 0
0 R0 C
before: 0 1 1 1 0 . . . 0 1 1 0
after: 0 0 0 1 1 1 0 . . . 0 1
R0 C
before: 1 0 0 1 1 . . . 0 1 0 0
after: 1 1 1 0 0 1 1 . . . 0 1
before: 0 1 1 1 0 . . . 0 1 1
Rotate
0
after: 1 1 1 0 . . . 0 1 1 0 1
C R0
before: 0 0 1 1 1 0 . . . 0 1 1
after: 1 1 1 0 . . . 0 1 1 0 0
R0 C
before: 0 1 1 1 0 . . . 0 1 1 0
after: 1 1 0 1 1 1 0 . . . 0 1
R0 C
before: 0 1 1 1 0 . . . 0 1 1 0
after: 1 0 0 1 1 1 0 . . . 0 1