Basic Computer Organization and Design
Basic Computer Organization and Design
Basic Computer Organization and Design
• Instruction Codes
• Computer Registers
• Computer Instructions
• Instruction Cycle
1
Basic Computer Organization & Design Instruction codes
INSTRUCTION CODES
• Program:
A set of instructions that specify the operations, operands, and the
sequence by which processing has to occur
• Instruction Code:
A group of bits that tells the computer to perform a specific operation
- Operation code:
• A group of bits that define the operation (add, subtract, shift)
• The operation (or macrooperation) specifies a set of microoperations
- Operand (or address of operand)
• Data stored in registers or in the memory, on which the operation is to
be performed
2
Basic Computer Organization & Design Instruction codes
Memory
4096 x 16
4 bits 12 bits
15 12 11 0
Instructions
Opcode Address
(program)
Instruction Format
15 0 Operands
Binary Operand (data)
15 0
Processor register
(Accumulator or AC)
3
Basic Computer Organization & Design Instruction codes
ADDRESSING MODES
Instruction Format
• Immediate Mode
Second part of instruction specifies an operand
4
Basic Computer Organization & Design Instruction codes
INDIRECT ADDRESS
Instruction Format
15 14 12 11 0
I = 0 Direct address
I Opcode Address I = 1 Indirect address
300 1350
457 Operand
1350 Operand
Effective
Address
+ +
AC AC
5
Basic Computer Organization & Design
Problem 5-1: A computer uses a memory unit with 256K words of 32 bits
each. A binary instruction code is stored in one word of memory. The
instruction has four parts: an indirect bit, an operation code, a register
code part to specify one of 64 registers, and an address part.
a. How many bits are there in the operation code, the register code part,
and the address part?
b. Draw the instruction word format and indicate the number of bits in
each part?
c. How many bits are there in the data and address inputs of the
memory?
6
Basic Computer Organization & Design Registers
COMPUTER REGISTERS
Registers in the Basic Computer (BC)
11 0
PC
11 0
AR Memory
15 0
4096 x 16
IR
15 0 15 0
TR DR
7 0 7 0 15 0
OUTR INPR AC
List of BC Registers
Symbol # of bits Name Function
DR 16 Data Register Holds memory operand
AR 12 Address Register Holds address for memory
AC 16 Accumulator Processor register
IR 16 Instruction Register Holds instruction code
PC 12 Program Counter Holds address of instruction
TR 16 Temporary Register Holds temporary data
INPR 8 Input Register Holds input character
OUTR 8 Output Register Holds output character
7
Basic Computer Organization & Design Registers
AR 1
INPR
IR 5
LD
TR 6
LD INR CLR
OUTR
Clock
LD
16-bit common bus
8
Basic Computer Organization & Design
a. AR ← PC
b. IR ← M[AR]
c. M[AR] ← TR
d. AC ← DR, DR ← AC
9
Basic Computer Organization & Design Instructions
COMPUTER INSTRUCTIONS
10
Basic Computer Organization & Design Instructions
11
Basic Computer Organization & Design Instructions
Instruction Types
Functional Instructions
- Arithmetic, logic, and shift instructions
- ADD, CMA, INC, CIR, CIL, AND, CLA
Transfer Instructions
- Data transfers between the main memory
and the processor registers
- LDA, STA
Control Instructions
- Program sequencing and control
- BUN, BSA, ISZ
Input/Output Instructions
- Input and output
- INP, OUT
12
Basic Computer Organization & Design Timing and control
3x8
decoder
7 6543 210
D0
I .. Control
D7 Control
logic outputs
T15
gates
..
T0
15 14 . . . . 2 1 0
4 x 16
decoder
13
Basic Computer Organization & Design Timing and control
TIMING SIGNALS
- Generated by 4-bit sequence counter and 4x16 decoder
- The SC can be incremented or cleared.
-Example: T0, T1, T2, T3, T4, T0, T1, . . .
Assume: At time T4, SC is cleared to 0 if decoder output D3 is active.
D3T4: SC ← 0
T0 T1 T2 T3 T4 T0
Clock
T0
T1
T2
T3
T4
D3
CLR
SC
COUNT 0 1 2 3 4 0 1
14
Basic Computer Organization & Design Timing and control
TIMING SIGNALS
- Example: T0: AR ← PC 0 S2
1 S1 Bus
0 S0
AR 1
T0
LD
PC 2
Clock
Common bus
T0 T1
Clock
T0
T1
COUNT 0 1 2
15
Basic Computer Organization & Design Instruction Cycle
INSTRUCTION CYCLE
16
Basic Computer Organization & Design Instruction Cycle
INSTRUCTION CYCLE
BC Instruction cycle: [Fetch Decode [Indirect] Execute]
Fetch T0: AR ← PC
T1: IR ← M[AR], PC ← PC + 1
Decode T2: D0, . . . , D7 ← Decode IR(12-14), AR ← IR(0-11), I ← IR(15)
T1 S2
LD Clock
Common bus
17
Basic Computer Organization & Design Instruction Cycle
T0
AR ← PC
T1
IR ← M[AR], PC ← PC + 1
T2
Decode Opcode in IR(12-14),
AR ← IR(0-11), I ← IR(15)
T3 T3 T3 T3
Execute Execute AR ← M[AR] Nothing
input-output register-reference
instruction instruction
SC ← 0 SC ← 0 Execute
memory-reference
instruction
SC ← 0
r = D7 I’ T3 Bi = IR(i) , i=0,1,2,...,11
r: SC ← 0 Clear SC
CLA rB11: AC ← 0 Clear AC
CLE rB10: E←0 Clear E
CMA rB9: AC ← AC’ Complement AC
CME rB8: E ← E’ Complement E
CIR rB7: AC ← shr AC, AC(15) ← E, E ← AC(0) Circulate right
CIL rB6: AC ← shl AC, AC(0) ← E, E ← AC(15) Circulate left
INC rB5: AC ← AC + 1 Increment AC
SPA rB4: if (AC(15) = 0) then (PC ← PC+1) Skip if AC positive
SNA rB3: if (AC(15) = 1) then (PC ← PC+1) Skip if AC negative
SZA rB2: if (AC = 0) then (PC ← PC+1) Skip if AC zero
SZE rB1: if (E = 0) then (PC ← PC+1) Skip if E zero
HLT rB0: S ← 0 (S is a start-stop flip-flop) Halt computer
19
Basic Computer Organization & Design
T0: AR ← PC
T1: IR ← M [AR], PC ← PC + 1
T2: D0,…,D7 ← Decode IR(12-14), AR ← IR(0-11), I ← IR(15)
D7I'T3B11: AC ← 0, SC ← 0
20
Basic Computer Organization & Design MR Instructions
- The effective address of the instruction is in AR and was placed there during
timing signal T2 when I = 0, or during timing signal T3 when I = 1
21
Basic Computer Organization & Design MR Instructions
AND to AC
D0T4: DR ← M[AR] Read operand
D0T5: AC ← AC ∧ DR, SC ← 0 AND with AC
ADD to AC
D1T4: DR ← M[AR] Read operand
D1T5: AC ← AC + DR, E ← Cout, SC ← 0 Add to AC and store carry in E
LDA: Load to AC
D2T4: DR ← M[AR]
D2T5: AC ← DR, SC ← 0
STA: Store AC
D3T4: M[AR] ← AC, SC ← 0
22
Basic Computer Organization & Design MR Instructions
Next instruction in
program sequence
Program jumps
to instruction
out of sequence
Memory Memory
PC ← 135
23
Basic Computer Organization & Design MR Instructions
Subroutine call
Return address
AR = 135 135 21
136 Subroutine PC = 136 Subroutine
Subroutine return
BSA:
D5T4: M[AR] ← PC, AR ← AR + 1
D5T5: PC ← AR, SC ← 0
24
Basic Computer Organization & Design MR Instructions
ISZ:
D6T4: DR ← M[AR]
D6T5: DR ← DR + 1
D6T6: M[AR] ← DR, if (DR = 0) then (PC ← PC + 1), SC ← 0
25
Basic Computer Organization & Design MR Instructions
Memory-reference instruction
26
Basic Computer Organization & Design
Problem 5-11: Show the contents in hexadecimal of registers PC, AR, DR,
IR, and SC of the basic computer when an ISZ indirect instruction is
fetched from memory and executed: The initial content of PC is 7FF. The
content of memory at address 7FF is EA9F. The content of memory at
address A9F is 0C35. The content of memory at address C35 is FFFF.
Give the answer in a table with five columns, one for each register and a
row for each timing signal.
27
Basic Computer Organization & Design
28
Basic Computer Organization & Design I/O and Interrupt
Input-Output Configuration
Serial Computer
Input - output communication registers and
terminal interface flip-flops
Printer Receiver
interface OUTR FGO
INPR Input register - 8 bits
OUTR Output register - 8 bits
FGI Input flag FF - 1 bit AC
FGO Output flag FF - 1 bit
Keyboard Transmitter
interface INPR FGI
29
Basic Computer Organization & Design I/O and Interrupt
Start
FGI ← 0
yes
FGI=0
no
AC ← INPR
yes More
Character
no
END
30
Basic Computer Organization & Design I/O and Interrupt
Start
AC ← Data
yes
FGO=0
no
OUTR ← AC
FGO ← 0
yes More
Character
no
END
31
Basic Computer Organization & Design I/O and Interrupt
INPUT-OUTPUT INSTRUCTIONS
Symbol HEX_
INP F800
OUT F400
SKI F200
SKO F100
D7IT3 = p ION F080
IR(i) = Bi, i = 6, …, 11 IOF F040
p: SC ← 0 Clear SC
INP pB11: AC(0-7) ← INPR, FGI ← 0 Input char. to AC
OUT pB10: OUTR ← AC(0-7), FGO ← 0 Output char. from AC
SKI pB9: if (FGI = 1) then (PC ← PC + 1) Skip on input flag
SKO pB8: if (FGO = 1) then (PC ← PC + 1) Skip on output flag
ION pB7: IEN ← 1 Interrupt enable on
IOF pB6: IEN ← 0 Interrupt enable off
32
Basic Computer Organization & Design I/O and Interrupt
PROGRAM-CONTROLLED INPUT/OUTPUT
• Program-controlled I/O
- Continuous CPU involvement
I/O takes valuable CPU time
- CPU slowed down to I/O speed
- Simple
- Least hardware
Input
LOOP, SKI /Check input flag
BUN LOOP /FGI=0, branch to check again
INP /FGI=1, input character
Output
LOOP, SKO /Check output flag
BUN LOOP /FGO=0, branch to check again
OUT /FGO=1, output character
33
Basic Computer Organization & Design I/O and Interrupt
- The I/O interface, instead of the CPU, monitors the I/O device
- When the interface finds that the I/O device is ready for data transfer, it
generates an interrupt request to the CPU
34
Basic Computer Organization & Design I/O and Interrupt
R = Interrupt FF
Instruction cycle =0 =1 Interrupt cycle
R
Execute =0
IEN
instruction
=1 Branch to location 1
PC ← 1
=1
FGI
=0
IEN ← 0
=1
FGO R←0
=0
R←1
35
Basic Computer Organization & Design I/O and Interrupt
Memory
Interrupt cycle
Before interrupt After interrupt cycle
0 0 256
Store return address
in location 0 1 0 BUN 1120 PC = 1 0 BUN 1120
M[0] ← PC
Problem 5-18:
An output program resides in memory starting from address 2300.
a. What instruction must be placed at address 1?
b. What must be the last two instructions of the output program?
36
Basic Computer Organization & Design I/O and Interrupt
Execute =0
IEN
instruction
=1 Branch to location 1
PC ← 1
=1
FGI
=0
IEN ← 0
=1
FGO R←0
=0
R←1
RT0: AR ← 0, TR ← PC
RT1: M[AR] ← TR, PC ← 0
RT2: PC ← PC + 1, IEN ← 0, R ← 0, SC ← 0
37
Basic Computer Organization & Design Description
COMPLETE COMPUTER DESCRIPTION
Flowchart of Operations
start
SC ← 0, IEN ← 0, R ← 0
38
Basic Computer Organization & Design Description
COMPLETE COMPUTER DESCRIPTION
Microoperations
Fetch R’T0: AR ← PC
R’T1: IR ← M[AR], PC ← PC + 1
Decode R’T2: D0, ..., D7 ← Decode IR(12 ~ 14),
AR ← IR(0 ~ 11), I ← IR(15)
Indirect D7’IT3: AR ← M[AR]
Interrupt
T0’T1’T2’(IEN)(FGI + FGO): R←1
RT0: AR ← 0, TR ← PC
RT1: M[AR] ← TR, PC ← 0
RT2: PC ← PC + 1, IEN ← 0, R ← 0, SC ← 0
Memory-Reference
AND D0 T 4 : DR ← M[AR]
D0 T 5 : AC ← AC ∧ DR, SC ← 0
ADD D1 T 4 : DR ← M[AR]
D1 T 5 : AC ← AC + DR, E ← Cout, SC ← 0
LDA D2 T 4 : DR ← M[AR]
D2 T 5 : AC ← DR, SC ← 0
STA D3 T 4 : M[AR] ← AC, SC ← 0
BUN D4 T 4 : PC ← AR, SC ← 0
BSA D5 T 4 : M[AR] ← PC, AR ← AR + 1
D5 T 5 : PC ← AR, SC ← 0
ISZ D6 T 4 : DR ← M[AR]
D6 T 5 : DR ← DR + 1
D6 T 6 : M[AR] ← DR, if(DR=0) then (PC ← PC + 1), SC ← 0
39
Basic Computer Organization & Design Description
COMPLETE COMPUTER DESCRIPTION
Microoperations
Register-Reference
D7I’T3 = r (Common to all register-reference instr)
IR(i) = Bi (i = 0,1,2, ..., 11)
r: SC ← 0
CLA rB11: AC ← 0
CLE rB10: E←0
CMA rB9: AC ← AC’
CME rB8: E ← E’
CIR rB7: AC ← shr AC, AC(15) ← E, E ← AC(0)
CIL rB6: AC ← shl AC, AC(0) ← E, E ← AC(15)
INC rB5: AC ← AC + 1
SPA rB4: If(AC(15) =0) then (PC ← PC + 1)
SNA rB3: If(AC(15) =1) then (PC ← PC + 1)
SZA rB2: If(AC = 0) then (PC ← PC + 1)
SZE rB1: If(E=0) then (PC ← PC + 1)
HLT rB0: S←0
40
Basic Computer Organization & Design Design of Basic Computer
41
Basic Computer Organization & Design Design of Basic Computer
42
Basic Computer Organization & Design Design of Basic Computer
D0T4: DR ← M[AR]
D0T5: AC ← AC ∧ DR, SC ← 0
D1T4: DR ← M[AR]
D1T5:
D2T4:
AC ← AC + DR, E ← Cout, SC ← 0
DR ← M[AR]
Read = R′T1 + D7′IT3 + (D0 + D1 + D2 + D6 )T4
D2T5: AC ← DR, SC ← 0
D3T4: M[AR] ← AC, SC ← 0 16 16
D4T4: PC ← AR, SC ← 0 From bus
M[AR] ← PC, AR ← AR + 1 D'7 To bus
D5T4: Memory
D5T5: PC ← AR, SC ← 0 I
D6T4: DR ← M[AR]
D6T5: DR ← DR + 1 T3 Read
T1
D6T6: M[AR] ← DR, if(DR=0) then (PC ← PC + 1),
SC ← 0 R
D0
T4
Problem 5-22: D1
43
Basic Computer Organization & Design Design of Basic Computer
CONTROL OF FLIP-FLOPS
IEN: Interrupt Enable Flag
pB7: IEN ← 1 (I/O Instruction)
pB6: IEN ← 0 (I/O Instruction)
RT2: IEN ← 0 (Interrupt)
D
7
p
I J IEN
Q
B7
T3
B6
K
R
T2
Problem 5-23:
Show the complete logic of interrupt flip-flop R.
44
Basic Computer Organization & Design Design of Basic Computer
selected
x1 x2 x3 x4 x5 x6 x7 S2 S1 S0 register
0 0 0 0 0 0 0 0 0 0 none
1 0 0 0 0 0 0 0 0 1 AR
0 1 0 0 0 0 0 0 1 0 PC
0 0 1 0 0 0 0 0 1 1 DR
0 0 0 1 0 0 0 1 0 0 AC
0 0 0 0 1 0 0 1 0 1 IR
0 0 0 0 0 1 0 1 1 0 TR
0 0 0 0 0 0 1 1 1 1 Memory
x1
x2 S2
Multiplexer
x3
Encoder S1 bus select
x4
x5 inputs
x6 S0
x7
For AR D4T4: PC ← AR
D5T5: PC ← AR Problem 5-24:
Derive the Boolean
logic expression for x2.
x1 = D4T4 + D5T5
45
Basic Computer Organization & Design Design of AC Logic
8 circuit To bus
From INPR
Control
gates
46
Basic Computer Organization & Design Design of AC Logic
CONTROL OF AC REGISTER
D0T5: AC ← AC ∧ DR
D1T5: AC ← AC + DR
D2T5: AC ← DR
pB11: AC(0-7) ← INPR
rB9: AC ← AC’
rB7 : AC ← shr AC, AC(15) ← E
rB6 : AC ← shl AC, AC(0) ← E From Adder 16 16
rB11 : AC ← 0 AC To bus
and Logic
rB5 : AC ← AC + 1
D0 D0T5 Clock
LD
T5 INR
D1 D1T5
CLR
D2 D2T5
T5
p pB11
p = D7IT3
B 11
r rB9
r = D7I’T3
B9
rB7
B7
rB6
B6
rB5
B5
rB11
B 11
47
Basic Computer Organization & Design Design of AC Logic
D0T5
AC(i)
DR(i)
48
Basic Computer Organization & Design Design of AC Logic
DR(i) AC(i)
D0T5
LD
Ci D1T5
FA Ii J Q
D2T5 AC(i)
C i+1
pB11 K
INPR(i)
rB9
One stage of AC register
rB7
AC(i+1)
rB6
AC(i-1)
49