Unit-3 Basic Computer Organization
Unit-3 Basic Computer Organization
Chapter Exercises
Computer Instructions and Instruction Codes
3
Computer Instructions
4
Instruction Codes
5
Instruction Codes
The most basic part of an instruction code is its OPERATION CODE (or
OPCODE); it is a group of bits that define operations such as add, subtract,
multiply, shift, and complement.
For instance, the ADD operation can be assigned the opcode 110010. When
the computer sees this opcode, it automatically knows to add the operands.
6
Stored Program Organization
and the second part specifies the address of the required operand.
7
Stored Program Organization
The first part of an instruction i.e., the opcode, specifies a particular operation
to be performed. This operation has to be performed on some operand i.e.,
data, stored in a computer register or in the main memory.
> Immediate
> Direct
> Indirect
9
Addressing Modes
Immediate Addressing: When the second part of the instruction code specifies the required
operand, the instruction is referred to as an “Immediate Instruction” (because it has an
immediate operand).
Direct Addresssing: When the second part of the instruction code specifies the address of
the required operand, the instruction is said to have a “Direct Address” (because the address
of the operand is directly present in the instruction itself).
Indirect Addressing: When the second part of the instruction code contains not the address
of the operand but rather the address of the memory word in which the address of the
operand is present, the instruction is said to have an “Indirect Address”.
10
Immediate Direct Indirect
Addressing Addressing Addressing
Operand
11
The leftmost bit (I)
signifies the addressing
mode.
I = 0 indicates direct
addressing
I = 1 indicates indirect
addressing
Effective
Address
Effective
Address
Computer Registers
13
Computer Registers
OUTR
14
Common Bus System
A basic computer has eight registers, a memory unit, and a control unit;
paths must be provided to transfer information from one unit to another.
15
Common Bus System
Computer Instructions
17
Computer Instructions
18
Memory-Reference Instructions
The opcode in a memory-reference instruction can take any value from 000 to 110.
19
Register-Reference Instructions
A input-output instruction does not need an operand from the memory, and so the
12 bits (that are generally used to specify the address) are used to specify the
input-output operation instead. 21
Basic Computer Instructions
22
Instruction Set Completeness
23
Timing and Control
24
Timing and Control
The clock pulses are applied to all flip-flops and registers in the
system, as well as, the flip-flops and registers in the control unit.
The clock pulses DO NOT change the state of a register
until the register is enabled by a control signal
generated in the control unit.
25
Two Major Types of Control Organizations
26
Block Diagram of a Typical Control Unit
27
Block Diagram of a Typical Control Unit
An instruction read
from the memory
is placed in the IR
I signifies the
addressing mode
I = 0 :- direct addressing
I = 1 :- indirect addressing
29
Example of Control Timing Signals
30
Example of Control Timing Signals
31
Example of Control Timing Signals
32
Example of Control Timing Signals
33
Example of Control Timing Signals
When D3T4 = 1
SC is cleared
34
Example of Control Timing Signals
35
Relationship Between Data Transfer,
Clock Transitions, and Timing Signals
T0 : AR ß PC
37
Instruction Cycle
A program residing in the memory is basically a sequence of instructions,
and a specific cycle has to be followed for the execution of each instruction,
as illustrated below:
38
Instruction Cycle: Fetch and Decode
Initially, the PC is loaded with the address of the first instruction in the program. The
sequence counter (SC) is cleared to 0, providing a decoded timing signal T0.
After each clock pulse, the SC is incremented by 1, so that the next timing signals
T1 , T2, T3 and so on can be generated.
The microoperations for the fetch and decode phases can be specified by the
following register transfer statements:
T0 : AR ß PC
T1 : IR ß M[AR], PC ß PC+1
T2 : D0, D1,….., D7 ß Decode IR (12-14), AR ß IR (0-11), I ß IR(15)
39
Fetch and Decode: Microoperation 1
T0 : AR ß PC
40
Fetch and Decode: Microoperation 2
T1 : IR ß M[AR], PC ß PC+1
The contents of the memory word M, whose address is present in AR, is moved to
IR, and the PC is incremented by one (so that it now points to the next instruction to
be fetched). This happens with the clock transition associated with the next timing
signal, i.e., T1.
41
Fetch and Decode: Microoperation 3
At time T2 :
i) the opcode (which is present in bits 12, 13, and 14 of the IR) is decoded.
ii) the address of the operand (which is present in bits 0 – 11 of the IR) is
transferred to AR.
iii) the single bit (bit 15 of the IR) which indicates the indirect addressing
mode is transferred to flip-flop I.
42
Diagramatic Representation of The Fetch Phase
43
Flowchart for
Instruction Cycle:
Initial Configuration
44
Memory-Reference Instructions
45
Memory-Reference Instructions
AC ß AC ∧M[AR]
This instruction performs the AND logic operation on pairs of bits in the AC
(accumulator) and the memory word specified by the effective address present in
AR. The result is then transferred to AC.
The microoperations that execute this instruction are:
D0T4: DR ß M[AR]
D0T5: AC ß AC ∧ DR, SC ß 0
47
Memory-Reference Instructions
2. ADD to AC
AC ß AC + M[AR], E ß Cout
This instruction adds the contents of the memory word specified by the effective
address to the value of AC. The sum is transferred to AC and the output carry is
transferred to E (extended accumulator) flip-flop.
The microoperations needed to execute this instruction are:
D1T4: DR ß M[AR]
D1T5: AC ß AC + DR, E ß Cout, SC ß 0
48
Memory-Reference Instructions
3. LDA: Load to AC
AC ß M[AR]
This instruction transfers the memory word specified by the effective address to AC.
The microoperations needed to execute this instruction are:
D2T4: DR ß M[AR]
D2T5: AC ß DR, SC ß 0
49
Memory-Reference Instructions
4. STA: Store AC
M[AR] ß AC
This instruction stores the contents of AC into the memory word specified by the
effective address.
The microoperation needed to execute this instruction is:
50
Memory-Reference Instructions
PC ß AR
This instruction transfers the control of the program to the instruction specified the
effective address.
The microoperation needed to execute this instruction is:
D4T4: PC ß AR, SC ß 0
51
Memory-Reference Instructions
When executed, this intruction stores the address of the next instruction into a
memory location specified by the effective address. The effective address plus one is
then added to PC (which will serve as the first address in the subroutine).
52
Example of BSA Instruction Execution
Address contained
I = 0 (i.e., direct)
Addresses in BSA
53
Example of BSA Instruction Execution
During Execution:
(i.e., indirect)
54
Example of BSA Instruction Execution
55
Memory-Reference Instructions
56
Memory-Reference Instructions
7. ISZ: Increment and Skip if Zero (this is the longest instruction)
M[AR] ß M[AR] + 1
If M[AR] +1 = 0 then PC ß PC+1
This instruction increments the word specified by the effective address, and if the
incremented value is equal to 0, PC is incremented by 1.
The microoperations needed to execute this instruction are:
D6T4: DR ß M[AR]
D6T5: DR ß DR + 1
D5T6: M[AR] ß DR, if (DR = 0) then (PC ß PC+1), SCß 0
57
Control Flowchart of Memory-Reference Instructions
58
Input and Output
59
Input and Output
60
Input-Output Configuration
Output Register
Input Register
61
Input-Output Configuration: Flow of Information Transfer
63
Input-Output Configuration: Flow of Information Transfer
64
Input/Output Instructions
65
Program Interrupt
66
Programmed Control Transfer
67
Programmed Control Transfer
68
Program Interrupt: An Alternative to Programmed Control Transfer
Step 2
Step 3
When the When a flag is The computer
computer is set, the computer momentarily
running a is interrupted deviates from
program, it does from its current what it is doing to
not check the program, and is take care of the
flags. informed that a input/output
flag has been set . operation, before
returning to its
original task.
70
Flowchart of Interrupt Cycle
R= Interrupt Flip-Flop
71
Demonstration of Interrupt Cycle
Before Interrupt
72
Demonstration of Interrupt Cycle
PC is set to 1
and R is cleared to 0
After Interrupt
73
Demonstration of Interrupt Cycle
After Interrupt
74
Demonstration of Interrupt Cycle
After Interrupt
75
Microoperations for Interrupt Cycle
1. RT0: AR ß 0, TR ß PC
(During the first timing signal, AR is cleared to 0, and the content of PC is transferred to a
temporary register TR.)
3. RT2: PC ß PC + 1, IEN ß 0, R ß 0, SC ß 0
(During the third timing signal, PC is incremented, IEN, R, and SC are cleared to 0.)
76
Complete Computer Description
77
Complete Flowchart
for Computer Operation
78
Design of a Basic Computer
79
Components of a Basic Computer
Nine registers (PC, AR, DR, AC, IR, TR, OUTR, INPR, SC)
81
Control Functions and Microoperations for Basic Computer
82
83
Exercises
84
1.
85
Solution:
256 K = 28 x 210 = 218
64 = 26
a. Address part: 18 bits, Register code part: 6 bits, Indirect bit: 1 bit
b.
c. No. of bits in data input: 32 bits, No. of bits in address input: 18 bits
86
2.
87
Solution:
A direct address instruction needs TWO references to memory: one to read the
instruction and one to read the operand.
88
3.
89
Fig. 5-4. 111
001
010
011
100
101
110
90
Solution:
92
Solution:
93
Solution:
94
5.
95
Solution
a. IR ← M[PC]
IR ← M[AR]
b. AC ← AC+TR
Add operation must be performed with DR; contents of TR must first be moved to DR.
DR ← TR
AC ← AC+DR
96
Solution (continued)
97
Solution (continued)
c. Suppose AC = 10 and DR = 5.
AC ← DR, DR ← AC AC = 5, DR = 10
AC ← AC+DR AC = 10 + 5 = 15
AC ← DR, DR ← AC AC = 10, DR = 15
98
6.
99
Fig. 5-5
100
Table 5-2
101
Solution:
102
Table 5-2
103
Solution:
104
Table 5-2
105
Solution:
106
Table 5-2
107
7.
Solution:
CLE: Clear E
CME: Complement E
108
Table 5-2
109
8.
110
Solution:
111
9.
112
Solution
1. CLA: Clear AC
Hexadecimal code for CLA is 7800, where ‘7’ is the opcode and ‘800’ is the address.
2. CLE: Clear E
Hexadecimal code for CLE is 7400, where ‘7’ is the opcode and ‘400’ is the address.
113
Solution (continued)
3. CMA: Complement AC
Hexadecimal code for CMA is 7200, where ‘7’ is the opcode and ‘200’ is the address.
A 9 3 7
4. CME: Complement E
Hexadecimal code for CME is 7100, where ‘7’ is the opcode and ‘100’ is the address.
115
Solution (continued)
Hexadecimal code for CIR is 7080, where ‘7’ is the opcode and ‘080’ is the address.
A 9 3 7
116
Solution (continued)
Hexadecimal code for CIL is 7040, where ‘7’ is the opcode and ‘050’ is the address.
CIL : AC ← shl AC, AC(0) ← E, E ← AC(15)
A 9 3 7
117
Solution (continued)
7. INC: Increment AC
Hexadecimal code for INC is 7020, where ‘7’ is the opcode and ‘020’ is the address.
Hexadecimal code for SPA is 7010, where ‘7’ is the opcode and ‘010’ is the address.
118
Solution (continued)
Hexadecimal code for SNA is 7008, where ‘7’ is the opcode and ‘008’ is the address.
Hexadecimal code for SZA is 7004, where ‘7’ is the opcode and ‘004’ is the address.
119
Solution (continued)
Hexadecimal code for SZE is 7002, where ‘7’ is the opcode and ‘002’ is the address.
Hexadecimal code for HLT is 7001, where ‘7’ is the opcode and ‘001’ is the address.
120
Solution
121
10.
122
Solution
Instruction at address 021 has I = 0 and opcode of the AND instruction. The address part is 083.
AND: DR ← M[AR]
AC ← AC ∧ DR When I = 0,
AND instruction has
AC: A 9 3 7 the hexadecimal code
0xxx
1010 1001 0011 0111
DR: B 8 F 2
ADD: DR ← M[AR]
When I = 0,
AC ← AC + DR, E ← Cout ADD instruction has
the hexadecimal code
1xxx
AC: A 9 3 7
1010 1001 0011 0111
DR: B 8 F 2
1011 1000 1111 0010
125
Solution (continued)
127
Solution (continued)
128
Solution
129
11.
130
Solution
Address Memory
PC = 7FF EA9F
A9F 0C35
C35 FFFF
131
Solution
DR ß DR + 1
132
Solution (continued)
DR ß DR + 1
133
Solution (continued)
DR ß DR + 1
134
Solution (continued)
DR ß DR + 1
135
Solution (continued)
DR ß DR + 1
136
Solution (continued)
DR ß DR + 1
137
Solution (continued)
DR ß DR + 1
138
12.
139
Solution
9 = 1001
So, 932E becomes 1001 32E = 1 001 32E = 1 ADD 32E
1 ADD 32E
140
Solution (continued)
b. AC = 7EC3
09AC
DR 8B9F
141
Solution (continued)
c. PC = 3AF + 1 = 3B0
IR = 932E
AR = 9AC
DR = 8B9F
AC = 0A62
E=1
I=1
SC = 0000
142
13.
143
Table 5-4
144
13.
145
Solution
AC ß AC ∧M[AR] AC ß AC + M[EA]
146
Solution (continued)
M[EA] ß M[EA] + AC
AC ß AC + M[AR], E ß Cout
147
Solution (continued)
Original Instruction New Instruction
and Microoperations and Microoperations
AC ß M[AR] AC ß AC - M[EA]
D2T7: AC ß AC + 1
D2T8: AC ß DR + AC, SC ß 0
148
Solution (continued)
149
Solution (continued)
AC ß TR, SC ß 0
150
Solution (continued)
151
14.
152
Solution:
153
15.
154
Fig. 5.3
Fig. 5.5(a)
155
Flowchart for
Instruction Cycle:
Initial Configuration
(Fig. 5-9)
156
Solution:
157
16.
158
Fig. 5.3
159
Solution
a. Diagram of the
computer showing
memory and registers.
160
Solution (continued)
161
Solution (continued)
162
17.
163
Solution
Solution
165
Solution
166
19.
167
Fig. 2-12
168
Solution (Step 1)
169
Solution (Step 2)
170
Solution (Step 3)
171
Solution (Step 4)
172
Solution (Step 5)
173
Solution (Step 6)
174
Solution (Step 7)
175
Solution (Step 8)
176
20.
177
Solution
The control logic will be designed using the control variables w, x, y, z, T1, T2, T3,
and T5.
The control logic will essentially serve as inputs to the JK flip-flop (i.e., JF and KF).
178
Solution (continued)
179
Solution (continued)
JF = xT3 + zT2 + ?
KF = yT1 + zT2 + ?
180
Solution (continued)
181
Solution (continued)
182
22.
Solution
183
23.
Solution
(T0 + T1 + T2)' (IEN) (FGI + FGO) : R ← 1
RT2 : R ← 0
184
Solution (continued)
185
25.
Solution
Clearing the sequence counter means CLR (SC), i.e., any microoperation that
involves the part “SC ß 0”.
186
Solution (continued)
187