Unit 4
Unit 4
Instruction Codes
2. Computer Registers
3. Computer Instructions
4. Timing And Control
5. Instruction Cycle
6. Register – Reference Instructions
7. Memory – Reference Instructions
8. Input – Output And Interrupt
1. Instruction Codes:
1. The organization of the computer is defined by its internal registers, the timing and
control structure, and the set of instructions that it uses.
2. Internal organization of a computer is defined by the sequence of micro-operations it
performs on data stored in its registers.
3. Computer can be instructed about the specific sequence of operations it must
perform.
4. User controls this process by means of a Program.
5. Program: set of instructions that specify the operations, operands, and the sequence
by which processing has to occur.
6. Instruction: a binary code that specifies a sequence of micro-operations for the
computer.
7. The computer reads each instruction from memory and places it in a control register.
The control then interprets the binary code of the instruction and proceeds to execute
it by issuing a sequence of micro-operations - Instruction Cycle
8. Instruction Code: group of bits that instruct the computer to perform specific
operation.
9. Instruction code is usually divided into two parts: Opcode and address(operand)
Operation Code (opcode):
1. The Operation code (Opcode) field which specifies the operation to be performed.
2. Eg: add, subtract, multiply, shift, complement.
Address (operand):
1. The Address field which contains the location of the operand, i.e., register or memory
location.
2. Memory words are specified by their address
Mode:
The Mode field which specifies how the operand will be located.
Stored Program Organization:
1. The ability to store and execute instructions is the most important property of a
general-purpose computer. That type of stored program concept is called stored
program organization.
2. The simplest way to organize a computer is to have one processor register and an
instruction code format with two parts. The first part specifies the operation to be
performed and the second specifies an address.
3. The below figure shows the stored program organization
4. Instructions are stored in one section of memory and data in another.
5. For a memory unit with 4096 words we need 12 bits to specify an address since 212
=4096.
6. If we store each instruction code in one 16-bit memory word, we have available four
bits for the operation code (abbreviated opcode) to specify one out of 16 possible
operations, and 12 bits to specify the address of an operand.
❑ Accumulator (AC):
1. Computers that have a single-processor register usually assign to it the name
accumulator and label it AC.
2. The operation is performed with the memory operand and the content of AC.
Addressing of Operand:
1. Sometimes convenient to use the address bits of an instruction code not as an
address but as the actual operand.
2. When the second part of an instruction code specifies an operand, the instruction is
said to have an immediate operand.
3. When the second part specifies the address of an operand, the instruction is said to
have a direct address.
4. When second part of the instruction designate an address of a memory word in which
the address of the operand is found such instruction have indirect address.
5. One bit of the instruction code can be used to distinguish between a direct and an
indirect address.
6. The instruction code format shown in Fig. 5-2(a). 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.
7. A direct address instruction is shown in Fig. 5-2(b).
8. 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.
9. The control finds the operand in memory at address 457 and adds it to the content of
AC.
10. The instruction in address 35 shown in Fig. 5-2(c) has a mode bit I = 1.
11. Therefore, it is recognized as an indirect address instruction.
12. 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.
13. The operand found in address 1350 is then added to the content of AC.
14. The effective address to be the address of the operand in a computation-type
instruction or the target address in a branch-type instruction.
15. Thus the effective address in the instruction of Fig. 5-2(b) is 457 and in the instruction
of Fig 5-2(c) is 1350.
2. Computer Registers:
1. What is the need for computer registers?
2. The need of the registers in computer for
• Instruction sequencing needs a counter to calculate the address of the next instruction
after execution of the current instruction is completed (PC).
• Necessary to provide a register in the control unit for storing the instruction code after
it is read from memory (IR).
• Needs processor registers for manipulating data (AC and TR) and a register for holding
a memory address (AR).
3. The above requirements dictate the register configuration shown in Fig. 5-3.
4. The registers are also listed in Table 5.1 together with a brief description of their
function and the number of bits that they contain.
5. The data register (DR) holds the operand read from memory.
6. The accumulator (AC) register is a general purpose processing register.
7. The instruction read from memory is placed in the instruction register (IR).
8. The temporary register (TR) is used for holding temporary data during the processing.
9. The memory address register (AR) has 12 bits since this is the width of a memory
address.
10. 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.
11. 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.
Common Bus System:
1. The basic computer has eight registers, a memory unit, and a control unit
2. Paths must be provided to transfer information from one register to another and
between memory and registers.
3. A more efficient scheme for transferring information in a system with many registers is
to use a common bus.
4. The connection of the registers and memory of the basic computer to a common bus
system is shown in Fig. 5-4.
5. The outputs of seven registers and memory are connected to the common bus.
6. The specific output that is selected for the bus lines at any given time is determined
from the binary value of the selection variables S2, S1, and S0.
7. The number along each output shows the decimal equivalent of the required binary
selection.
8. For example, the number along the output of DR is 3. The 16-bit outputs of DR are
placed on the bus lines when S2S1S0 = 011.
9. The lines from the common bus are connected to the inputs of each register and the
data inputs of the memory.
10. The particular register whose LD (load) input is enabled receives the data from the bus
during the next clock pulse transition.
11. The memory receives the contents of the bus when its write input is activated.
12. The memory places its 16-bit output onto the bus when the read input is activated
and S2S1S0 = 111.
13. Two registers, AR and PC, have 12 bits each since they hold a memory address.
14. When the contents of AR or PC are applied to the 16-bit common bus, the four most
significant bits are set to 0's.
15. When AR or PC receives information from the bus, only the 12 least significant bits are
transferred into the register.
16. The input register INPR and the output register OUTR have 8 bits each.
17. They communicate with the eight least significant bits in the bus.
18. INPR is connected to provide information to the bus but OUTR can only receive
information from the bus.
19. This is because INPR receives a character from an input device which is then transferred to AC.
20. OUTR receives a character from AC and delivers it to an output device.
21. Five registers have three control inputs: LD (load), INR (increment), and CLR (clear).
22. This type of register is equivalent to a binary counter with parallel load and synchronous clear.
23. Two registers have only a LD input.
24. The input data and output data of the memory are connected to the common bus, but the memory
address is connected to AR.
25. Therefore, AR must always be used to specify a memory address.
26. The 16 inputs of AC come from an adder and logic circuit. This circuit has three sets of inputs.
o One set of 16-bit inputs come from the outputs of AC.
o Another set of 16-bit inputs come from the data register DR.
o 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).
o A third set of 8-bit inputs come from the input register INPR.
27. The content of any register can be applied onto the bus and an operation can be performed in the adder
and logic circuit during the same clock cycle.
28. For example, the two microoperations DR AC and AC DR can be executed at the same time.
29. This can be done by placing the content of AC on the bus (with S2S1S0 = 100), enabling the LD (load)
input of DR, transferring the content of DR through the adder and logic circuit into AC, and enabling the
LD (load) input of AC, all during the same clock cycle.
3. Computer Instructions:
1. The basic computer has three instruction code formats, as shown in Fig. 5-5. Each
format has 16 bits.
2. The operation code (opcode) part of the instruction contains three bits and the
meaning of the remaining 13 bits depends on the operation code encountered.
3. A memory-reference instruction uses 12 bits to specify the memory address 3 bits for
the opcode (000 to 110), and one bit to specify the addressing mode I.
4. I is equal to 0 for direct address and to 1 for indirect address.
5. The register-reference instructions- In this type of code, 12 bits indicate the register
operation address, 3 bits for the opcode (111), and 1 bit is utilized for setting the mode as
0. The instructions are executed on the register
6. A register-reference instruction specifies an operation on the AC register. So an
operand from memory is not needed. Therefore, the other 12 bits are used to specify
the operation to be executed.
7. An input—output instruction -The remaining 12 bits are used to specify the type of
input—output operation. 3 bits for the opcode (111), and 1 bit is utilized for setting the
mode as 1. These instructions are required to transfer to and from the AC register and
output device.
LDA: Load to AC
1. This instruction transfers the memory word specified by the effective address to AC.
2. The microoperations needed to execute this instruction are
STA: Store AC
1. This instruction stores the content of AC into the memory word specified by the
effective address.
2. Since the output of AC is applied to the bus and the data input of memory is
connected to the bus, we can execute this instruction with one microoperation.
5. A numerical example that demonstrates how this instruction is used with a subroutine
is shown in Fig. 5-10.
7. The BSA instruction is assumed to be in memory at address 20.
8. The I bit is 0 and the address part of the instruction has the binary equivalent of 135.
9. After the fetch and decode phases, PC contains 21, which is the address of the next
instruction in the program (referred to as the return address). AR holds the effective
address 135.
10. This is shown in part (a) of the figure.
11. The BSA instruction performs the following numerical operation:
12. The result of this operation is shown in part (b) of the figure.
13. The return address21 is stored in memory location 135 and control continues with the
subroutine program starting from address 136.
14. The return to the original program (at address 21) is accomplished by means of an
indirect BUN instruction placed at the end of the subroutine.
16. When this instruction is executed, control goes to the indirect phase to read the
effective address at location 135, where it finds the previously saved address 21.
17. When the BUN instruction is executed, the effective address 21 is transferred to PC.
18. The next instruction cycle finds PC with the value 21, so control continues to execute
the instruction at the return address.
19. The BSA instruction must be executed with a sequence of two microoperations:
ISZ: Increment and Skip if Zero
1. This instruction increment the word specified by the effective address, and if the
incremented value is equal to 0, PC is incremented by 1 to skip the next instruction in
the program.
2. Since it is not possible to increment a word inside the memory, it is necessary to read
the word into DR, increment DR, and store the word back into memory.
3. This is done with the following sequence of microoperations:
Control Flowchart:
A flowchart showing all microoperations for the execution of the seven memory-reference
instructions is shown in Fig. 5.11.
7. Input-Output and Interrupt:
1. Instructions and data stored in memory must come from some input device.
2. Computational results must be transmitted to the user through some output device.
3. To demonstrate the most basic requirements for input and output communication, we
will use as an illustration a terminal unit with a keyboard and printer.
Input-Output Configuration:
1. The terminal sends and receives serial information.
2. Each quantity of information has eight bits of an alphanumeric code.
3. The serial information from the keyboard is shifted into the input register INPR.
4. The serial information for the printer is stored in the output register OUTR.
5. These two registers communicate with a communication interface serially and with
the AC in parallel.
6. The input—output configuration is shown in Fig. 5-12.
7. The input register INPR consists of eight bits and holds alphanumeric input information.
8. The 1-bit input flag FGI is a control flip-flop.
9. The flag bit 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.
10. The output register OUTR works similarly but the direction of information flow is reversed.
11. Initially, the output flag FGO is set to 1.
12. The computer checks the flag bit; if it is 1, the information from AC is transferred in parallel to
OUTR and FGO is cleared to 0.
13. The output device accepts the coded information, prints the corresponding character, and
when the operation is completed, it sets FGO to 1.
Input-Output Instructions:
1. Input and output instructions are needed for transferring information to and from AC register,
for checking the flag bits, and for controlling the interrupt facility.
2. Input-output instructions have an operation code 1111 and are recognized by the control
when D7 = 1 and I = 1.
3. The remaining bits of the instruction specify the particular operation.
4. The control functions and microoperations for the input-output instructions are listed in Table
5-5.
5. These instructions are executed with the clock transition associated with timing signal
T3.
6. Each control function needs a Boolean relation D7IT3, which we designate for
convenience by the symbol p.
7. The control function is distinguished by one of the bits in IR (6-11).
8. By assigning the symbol Bi to bit i of IR, all control functions can be denoted by pBi for
i = 6 though 11.
9. The sequence counter SC is cleared to 0 when p = D7IT3 = 1.
10. The last two instructions set and clear an interrupt enable flip-flop IEN.
Program Interrupt:
1. The computer keeps checking the flag bit, and when it finds it set, it initiates an information
transfer.
2. The difference of information flow rate between the computer and that of the input—output
device makes this type of transfer inefficient.
3. An alternative to the programmed controlled procedure is to let the external device inform the
computer when it is ready for the transfer.
4. In the meantime the computer can be busy with other tasks. This type of transfer uses the
interrupt facility.
5. While the computer is running a program, it does not check the flags.
6. When a flag is set, the computer is momentarily interrupted from the current program.
7. The computer deviates momentarily from what it is doing to perform of the input or output
transfer.
8. It then returns to the current program to continue what it was doing before the interrupt.
9. The interrupt enable flip-flop IEN can be set and cleared with two instructions.
o When IEN is cleared to 0 (with the IOF instruction), the flags cannot interrupt the computer.
o When IEN is set to (with the ION instruction), the computer can be interrupted.
10. The way that the interrupt is handled by the computer can be explained by means of the
flowchart of Fig. 5-13.
11. An interrupt flip-flop R is included in the computer. When R = 0, the computer goes through an
instruction cycle.
12. During the execute phase of the instruction cycle IEN is checked by the control.
13. If it is 0, it indicates that the programmer does not want to use the interrupt,so control
continues with the next instruction cycle.
14. 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.
15. If either flag is set to 1 while 1EN = 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.
Interrupt cycle:
1. The interrupt cycle is a hardware implementation of a branch and save return address
operation.
2. The return address available in PC is stored in a specific location.
3. This location may be a processor register, a memory stack, or a specific memory
location.
4. An example that shows what happens during the interrupt cycle is shown in Fig. 5-14.
5. When an interrupt occurs and R is set to 1 while the control is executing the
instruction at address 255.
6. At this time, the returns address 256 is in PC.
7. The programmer has previously placed an input—output service program in memory
starting from address 1120 and a BUN 1120 instruction at address 1. This is shown in
Fig. 5.14(a).
8. When control reaches timing signal T0and finds that R = 1, it proceeds with the
interrupt cycle.
9. The content of PC (256) is stored in memory location 0, PC is set to 1, and R is cleared
to 0.
10. The branch instruction at address 1 causes the program to transfer to the input—
output service program at address 1120.
11. This program checks the flags, determines which flag is set, and then transfers the
required input or output information.
12. 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.
13. This is shown in Fig. 5-14(b).