Chap 5
Chap 5
Instruction Code
An instruction code is a group of bits that instruct the computer to perform a specific operation.
Operation Code
The operation code of an instruction is a group of bits that define such operations as add,
subtract, multiply, shift, and complement. The number of bits required for the operation code of
an instruction depends on the total number of operations available in the computer. The
n
operation code must consist of at least n bits for a given 2 (or less) distinct operations.
Accumulator (AC)
Computers that have a single-processor register usually assign to it the name accumulator (AC)
accumulator and label it AC. The operation is performed with the memory operand and the
content of AC.
1|Page
UNIT-II
Unit 2 – Basic Computer Organization and Design
If we store each instruction code in one 16-bit memory word, we have available four bits
for operation code (abbreviated opcode) to specify one out of 16 possible operations,
and 12 bits to specify the address of an operand.
The control reads a 16-bit instruction from the program portion of memory.
It uses the 12-bit address part of the instruction to read a 16-bit operand from the data
portion of memory.
It then executes the operation specified by the operation code.
Computers that have a single-processor register usually assign to it the name
accumulator and label it AC.
If an operation in an instruction code does not need an operand from memory, the rest
of the bits in the instruction can be used for other purposes.
For example, operations such as clear AC, complement AC, and increment AC operate on
data stored in the AC register. They do not need an operand from memory. For these
types of operations, the second part of the instruction code (bits 0 through 11) is not
needed for specifying a memory address and can be used to specify other operations for
the computer.
Direct and Indirect addressing of basic computer.
The second part of an instruction format specifies the address of an operand, the
instruction is said to have a direct address.
In Indirect address, the bits in the second part of the instruction designate an address of
a memory word in which the address of the operand is found.
One bit of the instruction code can be used to distinguish between a direct and an
indirect address.
It consists of a 3-bit operation code, a 12-bit address, and an indirect address mode bit
designated by I.
The mode bit is 0 for a direct address and 1 for an indirect address.
A direct address instruction is shown in Figure 2.2. It is placed in address 22 in memory.
The I bit is 0, so the instruction is recognized as a direct address instruction.
The opcode specifies an ADD instruction, and the address part is the binary equivalent of
457.
The control finds the operand in memory at address 457 and adds it to the content of
AC.
The instruction in address 35 shown in Figure 2.3 has a mode bit I = 1, recognized as an
indirect address instruction.
The address part is the binary equivalent of 300.
The control goes to address 300 to find the address of the operand. The address of the
operand in this case is 1350. The operand found in address 1350 is then added to the
content of AC.
2|Page
UNIT-II
Unit 2 – Basic Computer Organization and Design
The indirect address instruction needs two references to memory to fetch an operand.
1. The first reference is needed to read the address of the operand
2. Second reference is for the operand itself.
The memory word that holds the address of the operand in an indirect address
instruction is used as a pointer to an array of data.
15 14 12 11 0
I Opcode Address
Memory Memory
300 1350
457 Operand
1350 Operand
+ +
AC AC
3|Page
UNIT-II
Unit 2 – Basic Computer Organization and Design
The data register (DR) holds the operand read from memory.
The accumulator (AC) register is a general purpose processing register.
The instruction read from memory is placed in the instruction register (IR).
The temporary register (TR) is used for holding temporary data during the processing.
The memory address register (AR) has 12 bits.
The program counter (PC) also has 12 bits and it holds the address of the next instruction
to be read from memory after the current instruction is executed.
Instruction words are read and executed in sequence unless a branch instruction is
encountered. A branch instruction calls for a transfer to a nonconsecutive instruction in
the program.
Two registers are used for input and output. The input register (INPR) receives an 8-bit
character from an input device. The output register (OUTR) holds an 8-bit character for
an output device.
4|Page
UNIT-II
Unit 2 – Basic Computer Organization and Design
5|Page
UNIT-II
Unit 2 – Basic Computer Organization and Design
Five registers have three control inputs: LD (load), INR (increment), and CLR (clear). Two
registers have only a LD input.
AR must always be used to specify a memory address; therefore memory address is
connected to AR.
The 16 inputs of AC come from an adder and logic circuit. This circuit has three sets of
inputs.
1. Set of 16-bit inputs come from the outputs of AC.
2. Set of 16-bits come from the data register DR.
3. Set of 8-bit inputs come from the input register INPR.
The result of an addition is transferred to AC and the end carry-out of the addition is
transferred to flip-flop E (extended AC bit).
The clock transition at the end of the cycle transfers the content of the bus into the
designated destination register and the output of the adder and logic circuit into AC.
6|Page
UNIT-II
Unit 2 – Basic Computer Organization and Design
7|Page
UNIT-II
Unit 2 – Basic Computer Organization and Design
8|Page
UNIT-II
Unit 2 – Basic Computer Organization and Design
labeled T0 in the diagram will trigger only those registers whose control inputs are
connected to timing signal T0.
SC is incremented with every positive clock transition, unless its CLR input is active.
This procedures the sequence of timing signals T0, T1, T2, T3 and T4, and so on. If SC is not
cleared, the timing signals will continue with T5, T6, up to T15 and back to T0.
T0 T1 T2 T3 T4 T0
Clock
T0
T1
T2
T3
T4
D3
CLR SC
The last three waveforms shows how SC is cleared when D3T4 = 1. Output D3 from the
operation decoder becomes active at the end of timing signal T 2. When timing signal T4
becomes active, the output of the AND gate that implements the control function D 3T4
becomes active.
This signal is applied to the CLR input of SC. On the next positive clock transition the
counter is cleared to 0. This causes the timing signal T 0 to become active instead of T5
that would have been active if SC were incremented instead of cleared.
9|Page
UNIT-II
Unit 2 – Basic Computer Organization and Design
Instruction cycle
A program residing in the memory unit of the computer consists of a sequence of
instructions. In the basic computer each instruction cycle consists of the following
phases:
1. Fetch an instruction from memory.
2. Decode the instruction.
3. Read the effective address from memory if the instruction has an indirect address.
4. Execute the instruction.
After step 4, the control goes back to step 1 to fetch, decode and execute the nex
instruction.
This process continues unless a HALT instruction is encountered.
The flowchart presents an initial configuration for the instruction cycle and shows how
the control determines the instruction type after the decoding.
If D7 = 1, the instruction must be register-reference or input-output type. If D7 = 0, the
operation code must be one of the other seven values 110, specifying a memory-
reference instruction. Control then inspects the value of the first bit of the instruction,
which now available in flip-flop I.
If D7 = 0 and I = 1, we have a memory-reference instruction with an indirect address. It is
then necessary to read the effective address from memory.
The three instruction types are subdivided into four separate paths. The selected
10 | P a g e
UNIT-II
Unit 2 – Basic Computer Organization and Design
operation is activated with the clock transition associated with timing signal T3.This can
be symbolized as follows:
D’7 I T3: AR M [AR]
D’7 I’ T3: Nothing
D7 I’ T3: Execute a register-reference instruction
D7 I T3: Execute an input-output instruction
When a memory-reference instruction with I = 0 is encountered, it is not necessary to do
anything since the effective address is already in AR.
However, the sequence counter SC must be incremented when D’7 I T3 = 1, so that the
execution of the memory-reference instruction can be continued with timing variable T4.
A register-reference or input-output instruction can be executed with the click
associated with timing signal T3. After the instruction is executed, SC is cleared to 0 and
control returns to the fetch phase with T0 =1. SC is either incremented or cleared to 0
with every positive clock transition.
Register reference instruction.
When the register-reference instruction is decoded, D7 bit is set to 1.
Each control function needs the Boolean relation D7 I' T3
15 12 11 0
0 1 1 1 Register Operation
These 12 bits are available in IR (0-11). They were also transferred to AR during time T2.
These instructions are executed at timing cycle T3.
The first seven register-reference instructions perform clear, complement, circular shift,
and increment microoperations on the AC or E registers.
The next four instructions cause a skip of the next instruction in sequence when
11 | P a g e
UNIT-II
Unit 2 – Basic Computer Organization and Design
The effective address of the instruction is in the address register AR and was placed
there during timing signal T2 when I = 0, or during timing signal T3 when I = 1.
The execution of the memory-reference instructions starts with timing signal T4.
AND to AC
This is an instruction that performs the AND logic operation on pairs of bits in AC and the
memory word specified by the effective address. The result of the operation is
transferred to AC.
D0T4: DRM[AR]
D0T5: AC AC DR, SC 0
ADD to AC
This instruction adds the content of the memory word specified by the effective address
to the value of AC. The sum is transferred into AC and the output carry C out is transferred
to the E (extended accumulator) flip-flop.
D1T4: DR M[AR]
D1T5: AC AC + DR, E Cout, SC 0
12 | P a g e
UNIT-II
Unit 2 – Basic Computer Organization and Design
LDA: Load to AC
This instruction transfers the memory word specified by the effective address to AC.
D2T4: DR M[AR]
D2T5: AC DR, SC 0
STA: Store AC
This instruction stores the content of AC into the memory word specified by the effective
address.
D3T4: M[AR] AC, SC 0
BUN: Branch Unconditionally
This instruction transfers the program to instruction specified by the effective address.
The BUN instruction allows the programmer to specify an instruction out of sequence
and the program branches (or jumps) unconditionally.
D4T4: PC AR, SC 0
BSA: Branch and Save Return Address
This instruction is useful for branching to a portion of the program called a subroutine or
procedure. When executed, the BSA instruction stores the address of the next
instruction in sequence (which is available in PC) into a memory location specified by the
effective address.
M[AR] PC, PC AR + 1
M[135] 21, PC 135 + 1 = 136
It is not possible to perform the operation of the BSA instruction in one clock cycle when
we use the bus system of the basic computer. To use the memory and the bus properly,
the BSA instruction must be executed with a sequence of two microoperations:
D5T4: M[AR] PC, AR AR + 1
D5T5: PC AR, SC 0
ISZ: Increment and Skip if Zero
These instruction increments the word specified by the effective address, and if the
incremented value is equal to 0, PC is incremented by 1. Since it is not possible to
13 | P a g e
UNIT-II
Unit 2 – Basic Computer Organization and Design
increment a word inside the memory, it is necessary to read the word into DR, increment
DR, and store the word back into memory.
D6T4: DR M[AR]
D6T5: DR DR + 1
D6T4: M[AR] DR, if (DR = 0) then (PC PC + 1), SC 0
Control Flowchart
14 | P a g e
UNIT-II
Unit 2 – Basic Computer Organization and Design
The terminal sends and receives serial information and each quantity of information has
eight bits of an alphanumeric code.
The serial information from the keyboard is shifted into the input register INPR.
The serial information for the printer is stored in the output register OUTR.
These two registers communicate with a communication interface serially and with the
AC in parallel.
The transmitter interface receives serial information from the keyboard and transmits it
to INPR. The receiver interface receives information from OUTR and sends it to the
printer serially.
The 1-bit input flag FGI is a control flip-flop. It is set to 1 when new information is
available in the input device and is cleared to 0 when the information is accepted by the
computer.
The flag is needed to synchronize the timing rate difference between the input device
and the computer.
The process of information transfer is as follows:
15 | P a g e
UNIT-II
Unit 2 – Basic Computer Organization and Design
Once the flag is cleared, new information can be shifted into INPR by striking another
key.
16 | P a g e
UNIT-II
Unit 2 – Basic Computer Organization and Design
Interrupt Cycle
The way that the interrupt is handled by the computer can be explained by means of the
flowchart shown in figure 2.13.
An interrupt flip-flop R is included in the computer.
When R = 0, the computer goes through an instruction cycle.
During the execute phase of the instruction cycle IEN is checked by the control.
If it is 0, it indicates that the programmer does not want to use the interrupt, so control
continues with the next instruction cycle.
If IEN is 1, control checks the flag bits.
If both flags are 0, it indicates that neither the input nor the output registers are ready
for transfer of information.
In this case, control continues with the next instruction cycle. If either flag is set to 1
while IEN = 1, flip-flop R is set to 1.
At the end of the execute phase, control checks the value of R, and if it is equal to 1, it
goes to an interrupt cycle instead of an instruction cycle.
17 | P a g e
UNIT-II
Unit 2 – Basic Computer Organization and Design
address.
Control then inserts address 1 into PC and clears IEN and R so that no more interruptions
can occur until the interrupt request from the flag has been serviced.
An example that shows what happens during the interrupt cycle is shown in Figure 2.14:
Suppose that an interrupt occurs and R = 1, while the control is executing the instruction
at address 255. At this time, the return address 256 is in PC.
The programmer has previously placed an input-output service program in memory
starting from address 1120 and a BUN 1120 instruction at address 1.
The content of PC (256) is stored in memory location 0, PC is set to 1, and R is cleared to
0.
At the beginning of the next instruction cycle, the instruction that is read from memory is
in address 1 since this is the content of PC. The branch instruction at address 1 causes
the program to transfer to the input-output service program at address 1120.
This program checks the flags, determines which flag is set, and then transfers the
required input or output information. Once this is done, the instruction ION is executed
to set IEN to 1 (to enable further interrupts), and the program returns to the location
where it was interrupted.
The instruction that returns the computer to the original place in the main program is a
branch indirect instruction with an address part of 0. This instruction is placed at the end
of the I/O service program.
The execution of the indirect BUN instruction results in placing into PC the return
address from location 0.
18 | P a g e
UNIT-II
Unit 2 – Basic Computer Organization and Design
19 | P a g e
UNIT-II
Unit 2 – Basic Computer Organization and Design
REFERENCE :
1. COMPUTER SYSTEM ARCHITECTURE, MORRIS M. MANO, 3RD EDITION, P RENTICE
HALL INDIA.
20 | P a g e
UNIT-II