Coa Unit-2 Full Notes
Coa Unit-2 Full Notes
Coa Unit-2 Full Notes
Contents:
Control memory
Address Sequencing
Microprogram Example
Design of Control Unit
Introduction:
The function of the control unit in a digital computer is to initiate sequence of
microoperations.
Control unit can be implemented in two ways
o Hardwired control
o Microprogrammed control
Hardwired Control:
When the control signals are generated by hardware using conventional logic design
techniques, the control unit is said to be hardwired.
The key characteristics are
oHigh speed of operation
oExpensive
oRelatively complex
oNo flexibility of adding new instructions
Examples of CPU with hardwired control unit are Intel 8085, Motorola 6802, Zilog
The general configuration of a micro-programmed control unit organization is shown as block diagram below.
A computer with a microprogrammed control unit will have two separate memories: a main memory and a
control memory
The microprogram consists of microinstructions that specify various internal control signals for execution of
register microoperations
These microinstructions generate the microoperations to:
fetch the instruction from main memory
evaluate the effective address
execute the operation
return control to the fetch phase for the next instruction
2. Address Sequencing:
Microinstructions are stored in control memory in groups, with each group specifying a routine.
Each computer instruction has its own microprogram routine to generate the microoperations.
The hardware that controls the address sequencing of the control memory must be capable of sequencing the
microinstructions within a routine and be able to branch from one routine to another
Steps the control must undergo during the execution of a single computer instruction:
o Load an initial address into the CAR when power is turned on in the computer. This address is usually
the address of the first microinstruction that activates the instruction fetch routine – IR holds
instruction
o The control memory then goes through the routine to determine the effective address of the operand
– AR holds operand address
o The next step is to generate the microoperations that execute the instruction by considering the
opcode and applying a mapping process.
The transformation of the instruction code bits to an address in control memory where the
routine of instruction located is referred to as mapping process.
o After execution, control must return to the fetch routine by executing an unconditional branch
In brief the address sequencing capabilities required in a control memory are:
o Incrementing of the control address register.
o Unconditional branch or conditional branch, depending on status bit conditions.
o A mapping process from the bits of the instruction to an address for control memory.
o A facility for subroutine call and return.
The below figure shows a block diagram of a control memory and the associated hardware needed for
selecting the next microinstruction address.
The microinstruction in control memory contains a set of bits to initiate microoperations in computer registers
and other bits to specify the method by which the next address is obtained.
In the figure four different paths form which the control address register (CAR) receives the address.
o The incrementer increments the content of the control register address register by one, to select the
next microinstruction in sequence.
o Branching is achieved by specifying the branch address in one of the fields of the microinstruction.
o Conditional branching is obtained by using part of the microinstruction to select a specific status bit in
order to determine its condition.
o An external address is transferred into control memory via a mapping logic circuit.
o The return address for a subroutine is stored in a special register, that value is used when the
micoprogram wishes to return from the subroutine.
Conditional Branching:
Conditional branching is obtained by using part of the microinstruction to select a specific status bit in order to
determine its condition.
The status conditions are special bits in the system that provide parameter information such as the carry-out
of an adder, the sign bit of a number, the mode bits of an instruction, and i/o status conditions.
The status bits, together with the field in the microinstruction that specifies a branch address, control the
branch logic.
The branch logic tests the condition, if met then branches, otherwise, increments the CAR.
If there are 8 status bit conditions, then 3 bits in the microinstruction are used to specify the condition and
provide the selection variables for the multiplexer.
For unconditional branching, fix the value of one status bit to be one load the branch address from control
memory into the CAR.
Mapping of Instruction:
A special type of branch exists when a microinstruction specifies a branch to the first word in control memory
where a microprogram routine is located.
The status bits for this type of branch are the bits in the opcode.
Assume an opcode of four bits and a control memory of 128 locations. The mapping process converts the 4-bit
opcode to a 7-bit address for control memory shown in below figure.
Mapping consists of placing a 0 in the most significant bit of the address, transferring the four
operation code bits, and clearing the two least significant bits of the control address register.
This provides for each computer instruction a microprogram routine with a capacity of four microinstructions.
Subroutines:
Subroutines are programs that are used by other routines to accomplish a particular task and can be called
from any point within the main body of the microprogram.
Frequently many microprograms contain identical section of code.
Microinstructions can be saved by employing subroutines that use common sections of microcode.
Microprograms that use subroutines must have a provision for storing the return address during a subroutine
call and restoring the address during a subroutine return.
A subroutine register is used as the source and destination for the addresses
3. Microprogram Example:
The process of code generation for the control memory is called microprogramming.
The block diagram of the computer configuration is shown in below figure.
Two memory units:
Main memory – stores instructions and data
Control memory – stores microprogram
Four processor registers
Program counter – PC
Address register – AR
Data register – DR
Accumulator register - AC
Two control unit registers
Control address register – CAR
Subroutine register – SBR
Transfer of information among registers in the processor is through MUXs rather than a bus.
The computer instruction format is shown in below figure.
The example will only consider the following 4 of the possible 16 memory instructions
The microinstruction format for the control memory is shown in below figure.
The microinstruction format is composed of 20 bits with four parts to it
Three fields F1, F2, and F3 specify microoperations for the computer [3 bits each]
The CD field selects status bit conditions [2 bits]
The BR field specifies the type of branch to be used [2 bits]
The AD field contains a branch address [7 bits]
Each of the three microoperation fields can specify one of seven possibilities.
No more than three microoperations can be chosen for a microinstruction.
If fewer than three are needed, the code 000 = NOP.
The three bits in each field are encoded to specify seven distinct microoperations listed in below table.
The branch field (BR) consists of two bits and is used with the address field to choose the address of the
next microinstruction.
Each line of an assembly language microprogram defines a symbolic microinstruction and is divided into five
parts
1. The label field may be empty or it may specify a symbolic address. Terminate with a colon (: ).
2. The microoperations field consists of 1-3 symbols, separated by commas. Only one symbol from each
field. If NOP, then translated to 9 zeros
3. The condition field specifies one of the four conditions
4. The branch field has one of the four branch symbols
5. The address field has three formats
a. A symbolic address – must also be a label
b. The symbol NEXT to designate the next address in sequence
c. Empty if the branch field is RET or MAP and is converted to 7 zeros
The symbol ORG defines the first address of a microprogram routine.
ORG 64 – places first microinstruction at control memory 1000000.
Fetch Routine:
The control memory has 128 locations, each one is 20 bits.
The first 64 locations are occupied by the routines for the 16 instructions, addresses 0-63.
Can start the fetch routine at address 64.
The fetch routine requires the following three microinstructions (locations 64-66).
The microinstructions needed for fetch routine are:
The control memory out of each subfield must be decoded to provide the distinct microoperations.
The outputs of the decoders are connected to the appropriate inputs in the processor unit.
The below figure shows the three decoders and some of the connections that must be made from their
outputs.
The three fields of the microinstruction in the output of control memory are decoded with a 3x8 decoder to
provide eight outputs.
Each of the output must be connected to proper circuit to initiate the corresponding microoperation as
specified in previous topic.
When F1 = 101 (binary 5), the next pulse transition transfers the content of DR (0-10) to AR.
Similarly, when F1= 110 (binary 6) there is a transfer from PC to AR (symbolized by PCTAR). As shown
in Fig, outputs 5 and 6 of decoder F1 are connected to the load input of AR so that when either
one of these outputs is active, information from the multiplexers is transferred to AR.
The multiplexers select the information from DR when output 5 is active and from PC when
output 5 is inactive.
The transfer into AR occurs with a clock transition only when output 5 or output 6 of the decoder is
active.
For the arithmetic logic shift unit the control signals are instead of coming from the logical gates,
now these inputs will now come from the outputs of AND, ADD and DRTAC respectively.
Microprogram Sequencer:
The basic components of a microprogrammed control unit are the control memory and the circuits that select
the next address.
The address selection part is called a microprogram sequencer.
The purpose of a microprogram sequencer is to present an address to the control memory so that a
microinstruction may be read and executed.
The next-address logic of the sequencer determines the specific address source to be loaded into the control
address register.
The block diagram of the microprogram sequencer is shown in below figure.
The control memory is included in the diagram to show the interaction between the sequencer and the
memory attached to it.
There are two multiplexers in the circuit.
o The first multiplexer selects an address from one of four sources and routes it into control address
register CAR.
o The second multiplexer tests the value of a selected status bit and the result of the test is applied to
an input logic circuit.
The output from CAR provides the address for the control memory.
The content of CAR is incremented and applied to one of the multiplexer inputs and to the subroutine register
SBR.
The other three inputs to multiplexer come from
o The address field of the present microinstruction
o From the out of SBR
o From an external source that maps the instruction
The CD (condition) field of the microinstruction selects one of the status bits in the second multiplexer.
If the bit selected is equal to 1, the T variable is equal to 1; otherwise, it is equal to 0.
The T value together with two bits from the BR (branch) field goes to an input logic circuit.
The input logic in a particular sequencer will determine the type of operations that are available in the unit.
The input logic circuit in above figure has three inputs I0, I1, and T, and three outputs, S0, S1, and L.
Variables S0 and S1 select one of the source addresses for CAR. Variable L enables the load input in SBR.
The binary values of the selection variables determine the path in the multiplexer.
For example, with S1,S0 = 10, multiplexer input number 2 is selected and establishes transfer path from SBR to
CAR.
The truth table for the input logic circuit is shown in Table below.
Instruction Formats
Addressing Modes
Program Control
Introduction:
The main part of the computer that performs the bulk of data-processing operations is called the central
processing unit and is referred to as the CPU.
The CPU is made up of three major parts, as shown in Fig. 8-1.
The register set stores intermediate data used during the execution of the instructions.
The arithmetic logic unit (ALU) performs the required microoperations for executing the instructions.
The control unit supervises the transfer of information among the registers and instructs the ALU as to which
operation to perform.
1. Stack Organization:
A stack or last-in first-out (LIFO) is useful feature that is included in the CPU of most computers.
Stack:
o A stack is a storage device that stores information in such a manner that the item stored last is the first
item retrieved.
The operation of a stack can be compared to a stack of trays. The last tray placed on top of the stack is the first
to be taken off.
In the computer stack is a memory unit with an address register that can count the address only.
The register that holds the address for the stack is called a stack pointer (SP). It always points at the top item in
the stack.
The two operations that are performed on stack are the insertion and deletion.
The operation of insertion is called PUSH.
The operation of deletion is called POP.
These operations are simulated by incrementing and decrementing the stack pointer register (SP).
Register Stack:
A stack can be placed in a portion of a large memory or it can be organized as a collection of a finite number of
memory words or registers.
The below figure shows the organization of a 64-word register stack.
The stack pointer register SP contains a binary number whose value is equal to the address of the word
is currently on top of the stack. Three items are placed in the stack: A, B, C, in that order.
In above figure C is on top of the stack so that the content of SP is 3.
For removing the top item, the stack is popped by reading the memory word at address 3 and decrementing the
content of stack SP.
Now the top of the stack is B, so that the content of SP is 2.
Similarly for inserting the new item, the stack is pushed by incrementing SP and writing a word in the next-
higher location in the stack.
In a 64-word stack, the stack pointer contains 6 bits because 26 = 64.
Since SP has only six bits, it cannot exceed a number greater than 63 (111111 in binary).
When 63 is incremented by 1, the result is 0 since 111111 + 1. = 1000000 in binary, but SP can accommodate
only the six least significant bits.
Then the one-bit register FULL is set to 1, when the stack is full.
Similarly when 000000 is decremented by 1, the result is 111111, and then the one-bit register EMTY is set 1
when the stack is empty of items.
DR is the data register that holds the binary data to be written into or read out of the stack.
PUSH:
Initially, SP is cleared to 0, EMTY is set to 1, and FULL is cleared to 0, so that SP points to the word at address 0
and the stack is marked empty and not full.
If the stack is not full (if FULL = 0), a new item is inserted with a push operation.
The push operation is implemented with the following sequence of microoperations:
The stack pointer is incremented so that it points to the address of next-higher word.
A memory write operation inserts the word from DR the top of the stack.
The first item stored in the stack is at address 1.
The last item is stored at address 0.
If SP reaches 0, the stack is full of items, so FULL is to 1.
This condition is reached if the top item prior to the last push way location 63 and, after incrementing SP, the
last item is stored in location 0.
Once an item is stored in location 0, there are no more empty registers in the stack, so the EMTY is cleared to 0.
POP:
A new item is deleted from the stack if the stack is not empty (if EMTY = 0).
The pop operation consists of the following sequence of min operations:
Memory Stack:
In the above discussion a stack can exist as a stand-alone unit. But in the CPU implementation of a stack is done
by assigning a portion of memory to a stack operation and using a processor register as stack pointer.
The below figure shows a portion computer memory partitioned into three segments: program, data, and
stack.
The program counter PC points at the address of the next instruction in program.
The address register AR points at an array of data.
The stack pointer SP points at the top of the stack.
The three registers are connected to a common address bus, and either one can provide an address for
memory.
o PC is used during the fetch phase to read an instruction.
o AR is used during the exec phase to read an operand.
o SP is used to push or pop items into or from stack.
As shown in Fig. 8-4, the initial value of SP is 4001 and the stack grows with decreasing addresses.
Thus the first item stored in the stack is at address 4000, the second item is stored at address 3999, and the last
address that can be used for the stack is 3000.
No provisions are available for stack limit checks.
The items in the stack communicate with a data register DR. A new item is inserted with the push operation as
follows:
SP SP-1
M [SP] DR
The stack pointer is decremented so that it points at the address of the next word.
A memory write operation inserts the word from DR into the top of stack. A new item is deleted with a pop
operation as follows:
DR M [SP]
SP SP+1
The top item is read from the stack into DR. The stack pointer is then decremented to point at the next item in
the stack.
Most computers do not provide hardware to check for stack overflow (full stack) or underflow (empty stack).
The stack limits can be checked by using processor registers:
o one to hold the upper limit (3000 in this case)
o Other to hold the lower limit (4001 in this case).
After a push operation, SP compared with the upper-limit register and after a pop operation, SP is a compared
with the lower-limit register.
The two microoperations needed for either the push or pop are
The advantage of a memory stack is that the CPU can refer to it without having specify an address, since the
address is always available and automatically updated in the stack pointer.
Reverse Polish notation, combined with a stack arrangement of registers, is the most efficient way known for
evaluating arithmetic expressions.
This procedure is employed in some electronic calculators and also in some computer.
The following numerical example may clarify this procedure. Consider the arithmetic expression
(3*4) + (5*6)
34 * 56* +
Each box represents one stack operation and the arrow always points to the top of the stack.
Scanning the expression from left to right, we encounter two operands.
First the number 3 is pushed into the stack, then the number 4.
The next symbol is the multiplication operator *.
This causes a multiplication of the two top most items the stack.
The stack is then popped and the product is placed on top of the stack, replacing the two original operands.
Next we encounter the two operands 5 and 6, so they are pushed into the stack.
The stack operation results from the next * replaces these two numbers by their product.
The last operation causes an arithmetic addition of the two topmost numbers in the stack to produce the final
result of 42.
2. Instruction Formats:
The format of an instruction is usually depicted in a rectangular box symbolizing the bits of the instruction as
they appear in memory words or in a control register.
The bits of the instruction are divided into groups called fields.
The most common fields found in instruction formats are:
1. An operation code field that specifies the operation to be perform
2. An address field that designates a memory address or a processor register.
3. A mode field that specifies the way the operand or the effective address is determined.
Computers may have instructions of several different lengths containing varying number of addresses.
The number of address fields in the instruct format of a computer depends on the internal organization of its
registers.
Most computers fall into one of three types of CPU organizations:
1. Single accumulator organization.
2. General register organization.
3. Stack organization.
In an accumulator type organization all the operations are performed with an implied accumulator register.
The instruction format in this type of computer uses one address field.
For example, the instruction that specifies an arithmetic addition defined by an assembly language
instruction as
ADD X
Where X is the address of the operand. The ADD instruction in this case results in the operation AC AC
+M[X]. AC is the accumulator register and M[X] symbolizes the memory word located at address X.
The instruction format in this type of computer needs three register address fields.
Thus the instruction for an arithmetic addition may be written in an assembly language as
ADD R1, R2, R3
to denote the operation R1R2 + R3. The number of address fields in the instruction can be
reduced from three to two if the destination register is the same as one of the source registers.
Thus the instruction ADD R1, R2 would denote the operation R1 R1 + R2. Only register addresses for R1
and R2 need be specified in this instruction.
General register-type computers employ two or three address fields in their instruction format.
Each address field may specify a processor register or a memory word.
An instruction symbolized by ADD R1, X would specify the operation R1 R1 + M[X].
It has two address fields, one for register R1 and the other for the memory address X.
Stack organization:
The stack-organized CPU has PUSH and POP instructions which require an address field.
Thus the instruction PUSH X will push the word at address X to the top of the stack.
The stack pointer is updated automatically.
Operation-type instructions do not need an address field in stack-organized computers.
This is because the operation is performed on the two items that are on top of the stack.
The instruction ADD in a stack computer consists of an operation code only with no address field.
This operation has the effect of popping the two top numbers from the stack, adding the numbers, and
pushing the sum into the stack.
There is no need to specify operands with an address field since all operands are implied to be in the stack.
The influence of the number of addresses on computer programs, we will evaluate the arithmetic statement
X= (A+B) * (C+D)
Using zero, one, two, or three address instructions and using the symbols ADD, SUB, MUL and DIV for four
arithmetic operations; MOV for the transfer type operations; and LOAD and STORE for transfer to and from
memory and AC register.
Assuming that the operands are in memory addresses A, B, C, and D and the result must be stored in memory ar
address X and also the CPU has general purpose registers R1, R2, R3 and R4.
Three-address instruction formats can use each address field to specify either a processor register or a
memory operand.
The program assembly language that evaluates X = (A+B) * (C+D) is shown below, together with
comments that explain the register transfer operation of each instruction.
Two-address instructions formats use each address field can specify either a processor register or
memory word.
The program to evaluate X = (A+B) * (C+D) is as follows
The MOV instruction moves or transfers the operands to and from memory and processor registers.
The first symbol listed in an instruction is assumed be both a source and the destination where the
result of the operation transferred.
One-address instructions use an implied accumulator (AC) register for all data manipulation.
For multiplication and division there is a need for a second register. But for the basic discussion we will
neglect the second register and assume that the AC contains the result of all operations.
The program to evaluate X=(A+B) * (C+D) is
All operations are done between the AC register and a memory operand.
T is the address of a temporary memory location required for storing the intermediate result.
A stack-organized computer does not use an address field for the instructions ADD and MUL.
The PUSH and POP instructions, however, need an address field to specify the operand that
communicates with the stack.
The following program shows how X = (A+B) * (C+D) will be written for a stack-organized computer.
(TOS stands for top of stack).
To evaluate arithmetic expressions in a stack computer, it is necessary to convert the expression into
reverse Polish notation.
The name "zero-address” is given to this type of computer because of the absence of an address field in
the computational instructions.
RISC Instructions:
The instruction set of a typical RISC processor is use only load and store instructions for communicating
between memory and CPU.
All other instructions are executed within the registers of CPU without referring to memory.
LOAD and STORE instructions that have one memory and one register address, and computational type
instructions that have three addresses with all three specifying processor registers.
The following is a program to evaluate X=(A+B)*(C+D)
The load instructions transfer the operands from memory to CPU register.
The add and multiply operations are executed with data in the register without accessing memory.
The result of the computations is then stored memory with a store in instruction.
3. Addressing Modes
The way the operands are chosen during program execution is dependent on the addressing mode of the
instruction.
Computers use addressing mode techniques for the purpose of accommodating one or both of the following
provisions:
o To give programming versatility to the user by providing such facilities as pointers to memory, counters
for loop control, indexing of data, and program relocation.
o To reduce the number of bits in the addressing field of the instruction
Most addressing modes modify the address field of the instruction; there are two modes that need no address
field at all. These are implied and immediate modes.
Implied Mode:
In this mode the operands are specified implicitly in the definition of the instruction.
For example, the instruction "complement accumulator" is an implied-mode instruction because the
operand in the accumulator register is implied in the definition of the instruction.
All register reference instructions that use an accumulator are implied mode instructions.
Zero address in a stack organization computer is implied mode instructions.
Immediate Mode:
In this mode the instruction specifies a register in CPU whose contents give the address of the operand
in memory.
In other words, the selected register contains the address of the operand rather than the operand itself.
The advantage of a register indirect mode instruction is that the address field of the instruction uses few
bits to select a register than would have been required to specify a memory address directly.
This is similar to the register indirect mode except that the register is incremented or decremented after
(or before) its value is used to access memory.
The address field of an instruction is used by the control unit in the CPU to obtain the operand from memory.
Sometimes the value given in the address field is the address of the operand, but sometimes it is just an
address from which the address of the operand is calculated.
The basic two mode of addressing used in CPU are direct and indirect address mode.
In this mode the effective address is equal to the address part of the instruction.
The operand resides in memory and its address is given directly by the address field of the instruction.
In a branch-type instruction the address field specifies the actual branch address.
In this mode the address field of the instruction gives the address where the effective address is stored
in memory.
Control fetches the instruction from memory and uses its address part to access memory again to read
the effective address.
A few addressing modes require that the address field of the instruction be added to the content of a specific
register in the CPU.
The effective address in these modes is obtained from the following computation:
In this mode the content of the program counter is added to the address part of the instruction in order
to obtain the effective address.
In this mode the content of an index register is added to the address part of the instruction to obtain
the effective address.
An index register is a special CPU register that contains an index value.
In this mode the content of a base register is added to the address part of the instruction to obtain the
effective address.
This is similar to the indexed addressing mode except that the register is now called a base register
instead of an index register.
Numerical Example:
To show the differences between the various modes, we will show the effect of the addressing modes on the
instruction defined in Fig. 8-7.
The two-word instruction at address 200 and 201 is a "load to AC" instruction with an address field equal to
500.
The first word of the instruction specifies the operation code and mode, and the second word specifies the
address part.
PC has the value 200 for fetching this instruction. The content of processor register R1 is 400, and the content of
an index register XR is 100.
AC receives the operand after the instruction is executed.
In the direct address mode the effective address is the address part of the instruction 500 and the operand to
be loaded into AC is 500.
In the immediate mode the second word of the instruction is taken as the operand rather than an address, so
500 is loaded into AC.
In the indirect mode the effective address is stored in memory at address 500. Therefore, the effective address
is 800 and the operand is 300.
In the relative mode the effective address is 500 + 202 =702 and the operand is 325. (the value in PC after the
fetch phase and during the execute phase is 202.)
In the index mode the effective address is XR+ 500 = 100 + 500 = 600 and the operand is 900.
In the register mode the operand is in R1 and 400 is loaded into AC.
In the register indirect mode the effective address is 400, equal to the content of R1 and the operand loaded
into AC is 700.
The auto-increment mode is the same as the register indirect mode except that R1 is incremented to 401 after
the execution of the instruction.
The auto-decrement mode decrements R1 to 399 prior to the execution of the instruction. The operand loaded
into AC is now 450.
Table 8-4 lists the values of the effective address and the operand loaded into AC for the nine addressing
modes.
4. Data Transfer and Manipulation:
Data transfer instructions move data from one place in the computer to another without changing the data
content.
The most common transfers are between memory and processor registers, between processor registers and
input or output, and between the processor registers themselves.
Table 8-5 gives a list of eight data transfer instructions used in many computers.
The load instruction has been used mostly to designate a transfer from memory to a processor register, usually
an accumulator.
The store instruction designates a transfer from a processor register into memory.
The move instruction has been used in computers with multiple CPU registers to designate a transfer from one
register to another and also between CPU registers and memory or between two memory words.
The exchange instruction swaps information between two registers or a register and a memory word.
The input and output instructions transfer data among processor registers and input or output terminals.
The push and pop instructions transfer data between processor registers and a memory stack.
Different computers use different mnemonics symbols for differentiate the addressing modes.
As an example, consider the load to accumulator instruction when used with eight different addressing modes.
Table 8-6 shows the recommended assembly language convention and actual transfer accomplished in each
case
Data manipulation instructions perform operations on data and provide the computational capabilities for the
computer.
The data manipulation instructions in a typical computer are usually divided into three basic types:
1. Arithmetic instructions
2. Logical and bit manipulation instructions
3. Shift instructions
1. Arithmetic instructions
The four basic arithmetic operations are addition, subtraction, multiplication and division.
Most computers provide instructions for all four operations.
Some small computers have only addition and possibly subtraction instructions. The multiplication and division
must then be generated by mean software subroutines.
A list of typical arithmetic instructions is given in Table 8-7.
The increment instruction adds 1 to the value stored in a register or memory word.
A number with all 1's, when incremented, produces a number with all 0's.
The decrement instruction subtracts 1 from a value stored in a register or memory word.
A number with all 0's, when decremented, produces number with all 1's.
The add, subtract, multiply, and divide instructions may be use different types of data.
The data type assumed to be in processor register during the execution of these arithmetic operations is defined
by an operation code.
An arithmetic instruction may specify fixed-point or floating-point data, binary or decimal data, single-precision
or double-precision data.
The mnemonics for three add instructions that specify different data types are shown below.
ADDI Add two binary integer numbers
ADDF Add two floating-point numbers
ADDD Add two decimal numbers in BCD
A special carry flip-flop is used to store the carry from an operation.
The instruction "add carry" performs the addition on two operands plus the value of the carry the previous
computation.
Similarly, the "subtract with borrow" instruction subtracts two words and borrow which may have resulted from
a previous subtract operation.
The negate instruction forms the 2's complement number, effectively reversing the sign of an integer when
represented it signed-2's complement form.
3. Shift Instructions:
Shifts are operations in which the bits of a word are moved to the left or right.
The bit shifted in at the end of the word determines the type of shift used.
Shift instructions may specify logical shifts, arithmetic shifts, or rotate-type operations.
In either case the shift may be to the right or to the left.
Table 8-9 lists four types of shift instructions.
5. Program Control:
Program control instructions specify conditions for altering the content of the program counter.
The change in value of the program counter as a result of the execution of a program control instruction causes
a break in the sequence of instruction execution.
This instruction provides control over the flow of program execution and a capability for branching to different
program segments.
Some typical program control instructions are listed in Table 8.10.
The ALU circuit in the CPU have status register for storing the status bit conditions.
Status bits are also called condition-code bits or flag bits.
Figure 8-8 shows block diagram of an 8-bit ALU with a 4-bit status register.
The four status bits are symbolized by C, S, Z, and V. The bits are set or cleared as a result of an
operation performed in the ALU.
o Bit C (carry) is set to 1 if the end carry C8 is 1. It is cleared to 0 if the carry is 0.
o S (sign) is set to 1 if the highest-order bit F7 is 1. It is set to 0 if the bit is 0.
o Bit Z (zero) is set to 1 if the output of the ALU contains all 0's. It is clear to 0 otherwise. In other
words, Z = 1 if the output is zero and Z =0 if the output is not zero.
o Bit V (overflow) is set to 1 if the exclusive-OR of the last two carries equal to 1, and cleared to 0
otherwise.
The above status bits are used in conditional jump and branch instructions.
Subroutine Call and Return:
A subroutine is self contained sequence of instructions that performs a given computational task.
The most common names used are call subroutine, jump to subroutine, branch to subroutine, or
branch and save return address.
A subroutine is executed by performing two operations
(1) The address of the next instruction available in the program counter (the return address) is stored
in a temporary location so the subroutine knows where to return
(2) Control is transferred to the beginning of the subroutine.
The last instruction of every subroutine, commonly called return from subroutine, transfers the return
address from the temporary location in the program counter.
Different computers use a different temporary location for storing the return address.
The most efficient way is to store the return address in a memory stack.
The advantage of using a stack for the return address is that when a succession of subroutines is
called, the sequential return addresses can be pushed into the stack.
A subroutine call is implemented with the following microoperations:
The instruction that returns from the last subroutine is implemented by the microoperations:
Program Interrupt:
Program interrupt refers to the transfer of program control from a currently running program to another service
program as a result of an external or internal generated request.
The interrupt procedure is similar to a subroutine call except for three variations:
o The interrupt is initiated by an internal or external signal.
o Address of the interrupt service program is determined by the hardware.
o An interrupt procedure usually stores all the information rather than storing only PC content.
Types of interrupts:
There are three major types of interrupts that cause a break in the normal execution of a program.
They can be classified as
o External interrupts:
These come from input—output (I/O) devices, from a timing device, from a circuit monitoring
the power supply, or from any other external source.
Ex: I/O device requesting transfer of data, I/O device finished transfer of data, elapsed time of an
event, or power failure.
o Internal interrupts:
These arise from illegal or erroneous use of an instruction or data.
Internal interrupts are also called traps.
Ex: interrupts caused by internal error conditions are register overflow, attempt to divide by zero, an
invalid operation code, stack overflow, and protection violation.
Internal and external interrupts are initiated form signals that occur in hardware of CPU.
o Software interrupts
A software interrupt is initiated by executing an instruction.
Software interrupt is a special call instruction that behaves like an interrupt rather than a subroutine
call.