COA - Unit-2
COA - Unit-2
Dynamic microprogramming:
A more advanced development known as dynamic microprogramming permits a microprogram to
be loaded initially from an auxiliary memory such as a magnetic disk. Control units that use
dynamic microprogramming employ a writable control memory. This type of memory can be
used for writing.
Control Memory:
Control Memory is the storage in the microprogrammed control unit to store the microprogram.
Control Word:
The control variables at any given time can be represented by a control word string of 1 's and 0's
called a control word.
Microoperations:
In computer central processing units, micro-operations (also known as a micro-ops or
μops) are detailed low-level instructions used in some designs to implement complex
machine instructions (sometimes termed macro-instructions in this context).
Micro instruction:
A symbolic microprogram can be translated into its binary equivalent by means of an
assembler.
Each line of the assembly language microprogram defines a symbolic microinstruction.
Each symbolic microinstruction is divided into five fields: label, microoperations, CD,
BR, and AD.
Micro program:
A sequence of microinstructions constitutes a microprogram.
Since alterations of the microprogram are not needed once the control unit is in operation,
the control memory can be a read-only memory (ROM).
ROM words are made permanent during the hardware production of the unit.
The use of a micro program involves placing all control variables in words of ROM for
use by the control unit through successive read operations.
The content of the word in ROM at a given address specifies a microinstruction.
Microcode:
Microinstructions can be saved by employing subroutines that use common sections of
microcode.
For example, the sequence of micro operations needed to generate the effective address of
the operand for an instruction is common to all memory reference instructions.
This sequence could be a subroutine that is called from within many other routines to
execute the effective address computation.
2
UNIT -II
Microprogrammed Control
While the microoperations are being executed, the next address is computed in the next
address generator circuit and then transferred into the control address register to read the
next microinstruction.
Thus a microinstruction contains bits for initiating microoperations in the data processor
part and bits that determine the address sequence for the control memory.
The next address generator is sometimes called a micro-program sequencer, as it
determines the address sequence that is read from control memory.
Typical functions of a micro-program sequencer are incrementing the control address
register by one, loading into the control address register an address from control memory,
transferring an external address, or loading an initial address to start the control
operations.
The control data register holds the present microinstruction while the next address is
computed and read from memory.
The data register is sometimes called a pipeline register.
It allows the execution of the microoperations specified by the control word
simultaneously with the generation of the next microinstruction.
This configuration requires a two-phase clock, with one clock applied to the address
register and the other to the data register.
The main advantage of the micro programmed control is the fact that once the hardware
configuration is established; there should be no need for further hardware or wiring
changes.
If we want to establish a different control sequence for the system, all we need to do is
specify a different set of microinstructions for control memory.
Address Sequencing
Microinstructions are stored in control memory in groups, with each group specifying a
routine.
To appreciate the address sequencing in a micro-program control unit, let us specify the
steps that the control must undergo during the execution of a single computer instruction.
Step-1:
An initial address is loaded into the control address register when power is turned on in
the computer.
This address is usually the address of the first microinstruction that activates the
instruction fetch routine.
The fetch routine may be sequenced by incrementing the control address register through
the rest of its microinstructions.
At the end of the fetch routine, the instruction is in the instruction register of the
computer.
3
UNIT -II
Type your text
Microprogrammed Control
Step-2:
The control memory next must go through the routine that determines the effective
address of the operand.
A machine instruction may have bits that specify various addressing modes, such as
indirect address and index registers.
The effective address computation routine in control memory can be reached through a
branch microinstruction, which is conditioned on the status of the mode bits of the
instruction.
When the effective address computation routine is completed, the address of the operand
is available in the memory address register.
Step-3:
The next step is to generate the microoperations that execute the instruction fetched from
memory.
The microoperation steps to be generated in processor registers depend on the operation
code part of the instruction.
Each instruction has its own micro-program routine stored in a given location of control
memory.
The transformation from the instruction code bits to an address in control memory where
the routine is located is referred to as a mapping process.
A mapping procedure is a rule that transforms the instruction code into a control
memory address.
Step-4:
Once the required routine is reached, the microinstructions that execute the instruction
may be sequenced by incrementing the control address register.
Micro-programs that employ subroutines will require an external register for storing the
return address.
Return addresses cannot be stored in ROM because the unit has no writing capability.
When the execution of the instruction is completed, control must return to the fetch
routine.
This is accomplished by executing an unconditional branch microinstruction to the first
address of the fetch routine.
4
UNIT -II
Microprogrammed Control
Above figure 4.2 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.
The diagram shows four different paths from which the control address register (CAR)
receives the address.
The incrementer increments the content of the control address register by one, to select the
next microinstruction in sequence.
Branching is achieved by specifying the branch address in one of the fields of the
microinstruction.
Conditional branching is obtained by using part of the microinstruction to select a specific
status bit in order to determine its condition.
An external address is transferred into control memory via a mapping logic circuit.
The return address for a subroutine is stored in a special register whose value is then used
when the micro-program wishes to return from the subroutine.
5
UNIT -II
Microprogrammed Control
The branch logic of figure 4.2 provides decision-making capabilities in the control unit.
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 input or output status conditions.
The status bits, together with the field in the microinstruction that specifies a branch
address, control the conditional branch decisions generated in the branch logic.
A 1 output in the multiplexer generates a control signal to transfer the branch address
from the microinstruction into the control address register.
A 0 output in the multiplexer causes the address register to be incremented.
Mapping of an Instruction
A special type of branch exists when a microinstruction specifies a branch to the first
word in control memory where a microprogram routine for an instruction is located.
The status bits for this type of branch are the bits in the operation code part of the
instruction.
For example, a computer with a simple instruction format as shown in figure 4.3 has an
operation code of four bits which can specify up to 16 distinct instructions.
Assume further that the control memory has 128 words, requiring an address of seven
bits.
One simple mapping process that converts the 4-bit operation code to a 7-bit address for
control memory is shown in figure 4.3.
This 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.
If the routine needs more than four microinstructions, it can use addresses 1000000
through 1111111. If it uses fewer than four microinstructions, the unused memory
locations would be available for other routines.
One can extend this concept to a more general mapping rule by using a ROM to specify
the mapping function.
The contents of the mapping ROM give the bits for the control address register.
6
UNIT -II
Microprogrammed Control
In this way the microprogram routine that executes the instruction can be placed in any
desired location in control memory.
The mapping concept provides flexibility for adding instructions for control memory as
the need arises.
7
UNIT -II
Unit 4 – Microprogrammed Control
Microinstruction Format
The microinstruction format for the control memory is shown in figure 4.5. The 20 bits of the
microinstruction are divided into four functional parts as follows:
1. The three fields F1, F2, and F3 specify microoperations for the computer.
The microoperations are subdivided into three fields of three bits each. The three bits in
each field are encoded to specify seven distinct microoperations. This gives a total of 21
microoperations.
2. The CD field selects status bit conditions.
3. The BR field specifies the type of branch to be used.
4. The AD field contains a branch address. The address field is seven bits wide, since the
control memory has 128 = 27 words.
The BR (branch) field consists of two bits. It is used, in conjunction with the address field
AD, to choose the address of the next microinstruction shown in Table 4.2.
8
UNIT -II
Microprogrammed Control
Symbolic Microinstruction.
Each line of the assembly language microprogram defines a symbolic microinstruction.
Each symbolic microinstruction is divided into five fields: label, microoperations, CD,
BR, and AD. The fields specify the following Table 4.3.
9
UNIT -II
Microprogrammed Control
10
UNIT -II
Microprogrammed Control
l0 Input 3 2 1 0
Load
S MU
l1 Logic 1 X 1 SBR
S
T 0
1
Test Increment
MUX 2
L Clock CAR
Select
Control
Memory
Microo AD
ps CD BR
Microprogrammed Control
Boolean Function:
S0 = I0
S1 = I0I1 + I0’T
L = I0’I1T
Typical sequencer operations are: increment, branch or jump, call and return from
subroutine, load an external address, push or pop the stack, and other address sequencing
operations.
With three inputs, the sequencer can provide up to eight address sequencing operations.
Some commercial sequencers have three or four inputs in addition to the T input and thus
provide a wider range of operations.
Intermediate data is stored in the register set during the execution of the instructions. The
microoperations required for executing the instructions are performed by the arithmetic logic unit
whereas the control unit takes care of transfer of information among the registers and guides the
ALU. The control unit services the transfer of information among the registers and instructs the
ALU about which operation is to be performed. The computer instruction set is meant for
providing the specifications for the design of the CPU. The design of the CPU largely, involves
choosing the hardware for implementing the machine instructions.
·
· The need for memory locations arises for storing pointers, counters, return address,
temporary results and partial products. Memory access consumes the most of the time off an
operation in a computer. It is more convenient and more efficient to store these intermediate
values in processor registers.
12
UNIT -II
· A common bus system is employed to contact registers that are included in the CPU in a
large number. Communications between registers is not only for direct data transfer but also for
performing various micro-operations. A bus organization for such CPU register shown in Figure
3.2, is connected to two multiplexers (MUX) to form two buses A and B. The selected lines in
each multiplexers select one register of the input data for the particular bus.
·
Control Word
13
UNIT -II
Encoding of register selection fields
Symbolic Designation
Microoperation SELA SELB SELD OPR Control Word
14
UNIT -II
Type your text
Stack organization:
A stack is a storage device that stores information in such a manner that the item stored
last is the first item retrieved.
The stack in digital computers is essentially a memory unit with an address register that
can count only. The register that holds the address for the stack is called a stack pointer
(SP) because its value always points at the top item in the stack.
The physical registers of a stack are always available for reading or writing. It is the
content of the word that is inserted or deleted.
Register stack:
15
UNIT -II
To remove the top item, the stack is popped by reading the memory word at address 3 and
decrementing the content of SP. Item B is now on top of the stack since SP holds address
2.
To insert a 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 are incremented by 1, the result is 0 since 111111 + 1 = 1000000 in binary, but
SP can accommodate only the six least significant bits.
Similarly, when 000000 is decremented by 1, the result is 111111. The one-bit register
FULL is set to 1 when the stack is full, and the one-bit register EMTY is set to 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:
If the stack is not full (FULL =0), a new item is inserted with a push operation. The push
operation consists of the following sequences 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 into the top of the stack.
SP holds the address of the top of the stack and that M[SP] denotes the memory word
specified by the address presently available in SP.
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 set to 1. This condition is reached if the
top item prior to the last push was in 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. If an
item is written in the stack, obviously the stack cannot be empty, so 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 sequences of microoperations:
16
UNIT -II
The top item is read from the stack into DR. The stack pointer is then decremented. If its
value reaches zero, the stack is empty, so EMTY is set to 1.
Memory Stack.
Figure 5.2: Computer memory with program, data, and stack segments
17
UNIT -II Type your text
The address registers AR points at an array of data which is used during the execute phase
to read an operand.
The stack pointer SP points at the top of the stack which is used to push or pop items into
or from the stack.
The three registers are connected to a common address bus, and either one can provide an
address for memory.
As shown in Figure 5.2, 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.
We assume that the items in the stack communicate with a data register DR.
PUSH
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 the stack.
POP
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 incremented to point at the next item in the stack.
The two microoperations needed for either the push or pop are (1) an access to memory
through SP, and (2) updating SP.
Which of the two microoperations is done first and whether SP is updated by
incrementing or decrementing depends on the organization of the stack.
In figure. 5.2 the stack grows by decreasing the memory address. The stack may be
constructed to grow by increasing the memory also.
The advantage of a memory stack is that the CPU can refer to it without having to specify
an address, since the address is always available and automatically updated in the stack
pointer.
Instruction formats:
Insruction fields:
18
UNIT -II
The three most common CPU organizations:
19
UNIT -II
ADDRESSING MODES :
* Specifies a rule for interpreting or modifying the address field of the instruction (before the operand is
actually referenced)
20
UNIT -II
21
UNIT -II
ADDRESSING MODES - EXAMPLES
Address Memory
200 Load to AC Mode
PC = 200 201 Address = 500
202 Next instruction
R1 = 400
399 450
XR = 100
400 700
AC
500 800
600 900
Addressing Effective Content
Mode Address of AC
Direct address 500 /* AC (500) */ 800 702 325
Immediate operand - /* AC 500 */ 500
Indirect address 800 /* AC ((500)) */ 300
Relative address 702 /* AC (PC+500) */ 325 800 300
Indexed address 600 /* AC (XR+500) */ 900
Register - /* AC R1 */ 400
Register indirect 400 /* AC (R1) */ 700
Autoincrement 400 /* AC (R1)+ */ 700
Autodecrement 399 /* AC -(R) */ 450
22
UNIT -II
Data Transfer Instructions with Different Addressing Modes
23
UNIT -II Type your text
DATA MANIPULATION INSTRUCTIONS
Three Basic Types: Arithmetic instructions
Logical and bit manipulation instructions
Shift instructions
Arithmetic Instructions
Name Mnemonic
Increment INC
Decrement DEC
Add ADD
Subtract SUB
Multiply MUL
Divide DIV
Add with Carry ADDC
Subtract with Borrow SUBB
Negate(2’s Complement) NEG
24
UNIT -II
Type your text
3. Bit Z (zero) is set to 1 if the output of the ALU contains all 0’s. it is cleared to 0
otherwise. In other words, Z = 1 if the output is zero and Z = 0 if the output is not
zero.
4. Bit V (overflow) is set to 1 if the exclusives-OR of the last two carries is equal to
1, and cleared to 0 otherwise. This is the condition for an overflow when negative
numbers are in 2’s complement. For the 8-bit ALU, V = 1 if the output is greater
than + 127 or less than -128.
The status bits can be checked after an ALU operation to determine certain relationships
that exist between the vales of A and B.
If bit V is set after the addition of two signed numbers, it indicates an overflow condition.
If Z is set after an exclusive-OR operation, it indicates that A = B.
A single bit in A can be checked to determine if it is 0 or 1 by masking all bits except the
bit in question and then checking the Z status bit.
CMP and TST instructions do not retain their results of operations(- and AND, respectively).
They only set or clear certain Flags.
25
UNIT -II Type your text
CONDITIONAL BRANCH INSTRUCTIONS
Mnemonic Branch condition Tested condition
BZ Branch if zero Z=1
BNZ Branch if not zero Z=0
BC Branch if carry C=1
BNC Branch if no carry C=0
BP Branch if plus S=0
BM Branch if minus S=1
BV Branch if overflow V=1
BNV Branch if no overflow V=0
Unsigned compare conditions (A - B)
BHI Branch if higher A> B
BHE Branch if higher or equal A B
BLO Branch if lower A< B
BLOE Branch if lower or equal A B
BE Branch if equal A= B
BNE Branch if not equal A B
Signed compare conditions (A - B)
BGT Branch if greater than A> B
BGE Branch if greater or equal A B
BLT Branch if less than A< B
BLE Branch if less or equal A B
BE Branch if equal A= B
BNE Branch if not equal A B
26
Type your text
UNIT -II
PROGRAM INTERRUPT:
The concept of program interrupt is used to handle a variety of problems that arise out of
normal program sequence.
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. Control
returns to the original program after the service program is executed.
After a program has been interrupted and the service routine been executed, the CPU must
return to exactly the same state that it was when the interrupt occurred.
Only if this happens will the interrupted program be able to resume exactly as if nothing had
happened.
The state of the CPU at the end of the execute cycle (when the interrupt is recognized) is
determined from:
The interrupt facility allows the running program to proceed until the input or output device
sets its ready flag. Whenever a flag is set to 1, the computer completes the execution of the
instruction in progress and then acknowledges the interrupt.
The result of this action is that the retune address is stared in location 0. The instruction in
location 1 is then performed; this initiates a service routine for the input or output transfer.
The service routine can be stored in location 1.
The service routine must have instructions to perform the following tasks:
27
UNIT -II
Type your text
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:
1. External interrupts
2. Internal interrupts
3. Software interrupts
1) External interrupts:
External interrupts come from input-output (I/0) devices, from a timing device, from a circuit
monitoring the power supply, or from any other external source.
Examples that cause external interrupts are I/0 device requesting transfer of data, I/o device
finished transfer of data, elapsed time of an event, or power failure. Timeout interrupt may
result from a program that is in an endless loop and thus exceeded its time allocation.
Power failure interrupt may have as its service routine a program that transfers the complete
state of the CPU into a nondestructive memory in the few milliseconds before power ceases.
External interrupts are asynchronous. External interrupts depend on external conditions that
are independent of the program being executed at the time.
2) Internal interrupts:
Internal interrupts arise from illegal or erroneous use of an instruction or data. Internal
interrupts are also called traps.
Examples of interrupts caused by internal error conditions are register overflow, attempt to
divide by zero, an invalid operation code, stack overflow, and protection violation. These
error conditions usually occur as a result of a premature termination of the instruction
execution. The service program that processes the internal interrupt determines the corrective
measure to be taken.
Internal interrupts are synchronous with the program. . If the program is rerun, the internal
interrupts will occur in the same place each time.
3) Software interrupts:
A software interrupt is a special call instruction that behaves like an interrupt rather than a
subroutine call. It can be used by the programmer to initiate an interrupt procedure at any
desired point in the program.
The most common use of software interrupt is associated with a supervisor call instruction.
This instruction provides means for switching from a CPU user mode to the supervisor mode.
Certain operations in the computer may be assigned to the supervisor mode only, as for
example, a complex input or output transfer procedure. A program written by a user must run
in the user mode.
When an input or output transfer is required, the supervisor mode is requested by means of a
supervisor call instruction. This instruction causes a software interrupt that stores the old CPU
state and brings in a new PSW that belongs to the supervisor mode.
The calling program must pass information to the operating system in order to specify the
particular task requested.
28
UNIT -II
Reverse Polish Notation (RPN) with appropriate example.
The postfix RPN notation, referred to as Reverse Polish Notation (RPN), places the
operator after the operands.
The following examples demonstrate the three representations:
A+B Infix notation
+AB Prefix or Polish notation
AB+ Postfix or reverse Polish notation
The reverse Polish notation is in a form suitable for stack manipulation.
The expression
A * B + C * D is written in reverse Polish notation as
AB*CD*+
The conversion from infix notation to reverse Polish notation must take into consideration
the operational hierarchy adopted for infix notation.
This hierarchy dictates that we first perform all arithmetic inside inner parentheses, then
inside outer parentheses, and do multiplication and division operations before addition
and subtraction operations.
REFERENCE :
1. COMPUTER SYSTEM ARCHITECTURE , MORRIS M. MANO, 3RD EDITION, PRENTICE HALL
INDIA.
29
UNIT -II