Binary Counters
Binary Counters
Binary Counters
binary counter
• A counter that follows the binary number sequence is called a
binary counter.
• An n-bit binary counter is a register of n flip-flops and associated
gates that follows a sequence of states according to the binary
count of n bits, from 0 to 2" - 1.
• Going through a sequence of binary numbers such as 0000, 0001,
0010, 001 1, and so on.
• The lower-order bit is complemented after every count and every
other bit is complemented from one count to the next if and only
if all its lower-order bits are equal to 1 .
4-bit synchronous binary counter.
Binary Counter with Parallel Load
• By enabling the count input during one clock period, the content of the register can be
incremented by one .
• With the clear, load, and increment inputs all at 0, the outputs do not change. If the clear and
load inputs are maintained at logic 0, the increment input controls the operation of the counter
and
• the outputs change to the next binary count for each positive transition of the
• clock.
• The input data are loaded into the flip-flops when the load control input is equal to I provided
that the clear is disabled, but the increment input can be 0 or I.
• The register is cleared to 0 with the clear control regardless of the values in the load and
increment inputs.
THE BASIC COMPUTER
CPU RAM
0
15 0
4095
Instruction codes
• Program
– A sequence of (machine) instructions
• Instruction code
sequence of micro-operation)
Operation Code
The operation code of the instruction is a group of bitst that define such
operations as add ,subtract,multiply,shift and complement.
• The instructions of a program, along with any needed data are stored in memory
• The CPU reads the next instruction from memory
• It is placed in an Instruction Register (IR)
Instruction codes
INSTRUCTION FORMAT
Instruction Format
15 14 12 11 0
I Opcode Address
Addressing
mode
Instruction codes
ADDRESSING MODES
• The address field of an instruction can represent either
– Direct address: the address in memory of the data to use (the address of the operand), or
– Indirect address: the address in memory of the address in memory of the data to use
+ +
AC AC
Instruction codes
PROCESSOR REGISTERS
PROCESSOR REGISTERS
11 0
PC
Memory
11 0 4096 x 16
AR
15 0
IR CPU
15 0 15 0
TR DR
7 0 7 0 15 0
OUTR INPR AC
List of BC Registers
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
Registers
Read INPR
Memory Write
4096 x 16 E ALU
Address
AC
L I C
L I C L
DR IR
L I C L I C
PC TR
AR OUTR LD
L I C
7 1 2 3 4 5 6
16-bit Common Bus
S 0 S1 S 2
Registers
• Three control lines, S2, S1, and S0 control which register the bus
selects as its input
S2 S1 S 0 Register
0 0 0 x
0 0 1 AR
0 1 0 PC
0 1 1 DR
1 0 0 AC
1 0 1 IR
1 1 0 TR
1 1 1 Memory
• Either one of the registers will have its load signal activated, or the
memory will have its read signal activated
– Will determine where the data from the bus gets loaded
• The 12-bit registers, AR and PC, have 0’s loaded onto the bus in the
high order 4 bit positions
• When the 8-bit register OUTR is loaded from the bus, the data
comes from the low order 8 bits on the bus
Instructions
CONTROL UNIT
3x8
decoder
7 6543 210
D0
I Combinational Control
D7
Control signals
T15 logic
T0
15 14 . . . . 2 1 0
4 x 16
decoder
TIMING SIGNALS
- Generated by 4-bit sequence counter and 416 decoder
- The SC can be incremented or cleared.
T0
T1
T2
T3
T4
D3
CLR
SC
INSTRUCTION CYCLE
• After an instruction is executed, the cycle starts again at step 1, for the
next instruction
T1 S2
T0 S1 Bus
S0
Memory
unit 7
Address
Read
AR 1
LD
PC 2
INR
IR 5
LD Clock
Common bus
Instrction Cycle
AR PC T0
T1
IR M[AR],PCPC + 1
T2
Decode Opcode in IR(12-14),
ARIR(0-11), IIR(15)
D'7IT3: AR M[AR]
D'7I'T3: Nothing
D7I'T3: Execute a register-reference instr.
D7IT3: Execute an input-output instr.
Instruction Cycle
AR = 135 135 21
136 Subroutine PC = 136 Subroutine
BSA:
D5T4:M[AR] PC, AR AR + 1
D5T5:PC AR, SC 0
AC
FGI 0
AC Data
yes yes
FGI=0
FGO=0
no
no
AC INPR
OUTR AC
D7IT3 = p
IR(i) = Bi, i = 6, …, 11
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
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
Output
LOOP, LDA DATA
LOP, SKO DEV
BUN LOP
OUT DEV
INTERRUPT INITIATED INPUT/OUTPUT
- Open communication only when some data has to be passed --> interrupt.
- The I/O interface, instead of the CPU, monitors the I/O device.
- When the interface founds that the I/O device is ready for data transfer,
it generates an interrupt request to the CPU
Fetch RT0: AR PC
RT1: IR M[AR], PC PC + 1
Decode RT2:
D0, ..., D7 Decode IR(12 ~ 14),
Indirect D7IT3: AR IR(0 ~ 11), I IR(15)
Interrupt
T T T (IEN)(FGI + FGO): AR M[AR]
0 1 2
RT0: R1
RT1: AR 0, TR PC
Memory-Reference RT2: M[AR] TR, PC 0
AND
PC PC + 1, IEN 0, R 0, SC 0
D0T4:
ADD D0T5:
D1T4: DR M[AR]
LDA D1T5: AC AC DR, SC 0
D2T4: DR M[AR]
STA
BUN D2T5: AC AC + DR, E Cout, SC 0
BSA D3T4: DR M[AR]
D4T4:
AC DR, SC 0
ISZ D5T4:
M[AR] AC, SC 0
D5T5:
D6T4: PC AR, SC 0
D6T5: M[AR] PC, AR AR + 1
D6T6: PC AR, SC 0
Description
Register-Reference
D7IT3 = r (Common to all register-reference instr)
IR(i) = Bi (i = 0,1,2, ..., 11)
r: SC 0
CLA rB11: AC 0
CLE rB10:
CMA E0
rB9:
CME AC AC
CIR rB8:
E E
CIL rB7:
INC rB6: AC shr AC, AC(15) E, E AC(0)
SPA rB5: AC shl AC, AC(0) E, E AC(15)
SNA rB4: AC AC + 1
SZA rB3: If(AC(15) =0) then (PC PC + 1)
SZE
rB2: If(AC(15) =1) then (PC PC + 1)
HLT
rB1:
If(AC = 0) then (PC PC + 1)
Input-Output rB0:
If(E=0) then (PC PC + 1)
D7IT3 = p S0
INP IR(i) = Bi
OUT (Common to all input-output instructions)
p:
SKI (i = 6,7,8,9,10,11)
pB11:
SKO pB10: SC 0
ION AC(0-7) INPR, FGI 0
pB9:
IOF
pB8: OUTR AC(0-7), FGO 0
Design of Basic Computer
From bus 12 AR
12
To bus
D'7
I Clock
T3 LD
T2 INR
CLR
R
T0
D
T4
Design of Basic Computer
CONTROL OF FLAGS
IEN: Interrupt Enable Flag
pB7: IEN 1 (I/O Instruction)
pB6: IEN 0 (I/O Instruction)
RT2: IEN 0 (Interrupt)
D7
I p
B7 J Q IEN
T3
B6
K
R
T2
Design of Basic Computer
x1 x2 x3 x4 x5 x6 x7 selected
S2 S1 S0
0 0 0 0 0 0 0 0 0 0 register
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 AR
For 0 0 0 0 0 1 1 1 1 Memory
D4T4: PC AR
D5T5: PC AR
x1 = D4T4 + D5T5
Design of AC Logic
Control
gates
CONTROL OF AC REGISTER
C i ADD LD
FA Ii J Q
AC(i)
C i+1 DR
K
From INPR
INPR
bit(i) COM
SHR
AC(i+1)
SHL
AC(i-1)