COA Lecture Notes
COA Lecture Notes
(AUTONOMOUS)
MCA DEPARTMENT
LECTURE NOTES
Computer Organization and Architecture
UNIT-1
A Boolean function can be transformed from an algebraic expression into a logic diagram
composed of AND, OR, and inverter gates. The logic diagram for F is shown in Fig. (b). There is an
inverter for input y to generate its complement y'. There is an AND gate for the term y'z, and an OR
gate is used to combine the two terms. In a logic diagram, the variables of the function are taken to
be the inputs of the circuit, and the variable symbol of the function is taken as the output of the
circuit. The purpose of Boolean algebra is to facilitate the analysis and design of digital circuits. It
provides a convenient tool to:
1. Express in algebraic form a truth table relationship between binary variables.
2. Express in algebraic form the input-output relationship of logic diagrams.
3. Find simpler circuits for the same function.
A Boolean function specified by a truth table can be expressed algebraically in many
different ways. By manipulating a Boolean expression according to Boolean algebra rules, one may
The purpose of Boolean algebra is to analysis and design of digital circuits, it provides a convenient
tool to
A Boolean function specified by a truth table can be expressed algebraically in many
different ways. By manipulating a Boolean expression according to Boolean algebra rules, one may
obtain a simpler expression that will require fewer gates. To see how this is done, we must first study
the manipulative capabilities of Boolean algebra.
1.2.3 DeMorgan's theorem
DeMorgan' s theorem is very important in dealing with NOR and NAND gates. It states that a
NOR gate that performs the (x + y)' function is equivalent to the function x'y'. Similarly, a NAND
function can be expressed by either (xy)' or (x' + y'). For this reason the NOR and NAND gates have
two distinct graphic symbols, as shown in Figs. 1-4 and 1-5. Instead of representing a NOR gate with
an OR graphic symbol followed by a circle, we can represent it by an AND graphic symbol preceded
by circles in all inputs. The invert-AND symbol for the NOR gate follows from DeMorgan's theorem
and from the convention that small circles denote complementation. Similarly, the NAND gate has
two distinct symbols, as shown in Fig. 1-5.
The maps for functions of two, three, and four variables are shown in Fig. 1-7. The number of
squares in a map of n variables is 2". The 2" minterms are listed by an equivalent decimal number for
easy reference. The minterm numbers are assigned in an orderly arrangement such that adjacent
squares represent minterms that differ by only one variable. The variable names are listed across both
sides of the diagonal line in the corner of the map. The O's and 1' s marked along each row and each
column designate the value of the variables.
The simplified algebraic expression for the function is the OR of the two terms: F = BC + AC'
four-variable map. F(A, B, C, D) =∑ (0, 1, 2, 6, 8, 9, 10)
The Logic diagram for the Sum-of–Products and Product-of-Sums is shown in the following
diagram.
A combinational circuit can be described by a truth table showing the binary relationship
between the n input variables and the m output variables. The truth table lists the corresponding
output binary values for each of the 2" input combinations. A combinational circuit can also be
specified with m Boolean functions, one for each output variable. Each output function is expressed
in terms of the n input variables.
The design of combinational circuits starts from the verbal outline of the problem and ends in
a logic circuit diagram. The procedure involves the following steps:
1.4.1 Half-Adder
The most basic digital arithmetic circuit is the addition of two binary digits. A combinational circuit
that performs the arithmetic addition of two bits is called a half-adder. One that performs the addition
of three bits (two significant bits and a previous carry) is called a full-adder. The name of the former
stems from the fact that two half-adders are needed to implement a full-adder. The input variables of
a half-adder are called the augend and addend bits. The output variables the sum and carry. It is
necessary to specify two output variables because the sum of 1 + 1 is binary 10, which has two
digits. We assign symbols x and y to the two input variables, and S (for sum) and C (for carry) to the
two output variables. The truth table for the half-adder is shown in Fig. l-16(a). The C output is 0
unless both inputs are I. The S output represents the least significant bit of the sum. The Boolean
functions for the two outputs can be obtained directly from the truth table:
S = x'y + xy' = x y
C = xy
The logic diagram is shown in Fig. l-16(b). It consists of an exclusive-OR gate and an AND gate.
1.4.2 Full-Adder
A full-adder is a combinational circuit that forms the arithmetic sum of three input bits. It
consists of three inputs and two outputs. Two of the input variables, denoted by x and y, represent
the two significant bits to be added. The third input, z, represents the carry from the previous lower
significant position. Two outputs are necessary because the arithmetic sum of three binary digits
ranges in value from 0 to 3, and binary 2 or 3 needs two digits. The two outputs are designated by the
symbols S (for sum) and C (for carry). The binary variable S gives the value of the least significant
bit of the sum. The binary variable C gives the output carry. The truth table of the full-adder is
shown in the following Table.
The eight rows under the input variables designate all possible combinations that the binary
variables may have. The value of the output variables are determined from the arithmetic sum of the
input bits. When all input bits are 0, the output is 0. The S output is equal to 1 when only one input is
equal to 1 or when all three inputs are equal to I. The C output has a carry of 1 if two or three inputs
are equal to I.
The logic diagram of the full-adder is drawn in the above figure. Note that the fulladder
circuit consists of two half-adders and an OR gate. Realizing that x'y + xy' = xa1y and including the
expression for output S, we obtain the two Boolean expressions for the full-adder:
S=x y z
C = xy + (x y)z
1.5 Flip-Flops
The digital circuits considered thus far have been combinational, where the outputs at any
given time are entirely dependent on the inputs that are present at that time. Although every digital
system is likely to have a combinational circuit, most systems encountered in practice also include
storage elements, which require that the system be described in terms of sequential circuits. The most
common type of sequential circuit is the synchronous type.
Synchronization is achieved by a timing device called a clock pulse generator that produces a
periodic train of clock pulses. The storage elements employed in clocked sequential circuits are
called flip-flops. A flip-flop is a binary cell capable of storing one bit of information. It has two
The operation of the SR flip-flop is as follows. If there is no signal at the clock input C, the
output of the circuit cannot change irrespective of the values at inputs S and R. Only when the clock
signal changes from 0 to 1 can the output be affected according to the values in inputs S and R. If S =
1 and R = 0 when C changes from 0 to 1, output Q is set to 1. If S = 0 and R = 1 when C changes
from 0 to 1, output Q is cleared to 0. If both S and R are 0 during the clock transition, the output does
not change. When both 5 and R are equal to 1, the output is unpredictable and may go to either 0 or
1, depending on internal timing delays that occur within the circuit.
The characteristic table shown above summarizes the operation of the SR flip-flop in tabular
formThe S and R columns give the binary values of the two inputs. Q(t) is the binary state of the Q
output at a given time (referred to as present state). Q(t + 1) is the binary state of the Q output after
the occurrence of a clock transition (referred to as next state).
1.5.2. D Flip-Flop
The D (data) flip-flop is a slight modification of the SR flip-flop. An SR flip-flop is
converted to a D flip-flop by inserting an inverter between S and R and assigning the symbol D to
the single input. The D input is sampled during the occurrence of a clock transition from 0 to 1. If D
= 1, the output of the flip-flop goes to the 1 state, but if D = 0, the output of the flip-flop goes to the 0
state. The graphic symbol and characteristic table of the D flip-flop are shown in Fig. 1-20. From the
Although a D flip-flop has the advantage of having only one input (excluding C), it has the
disadvantage that its characteristic table does not have a "no change" condition Q(t + 1) = Q(t). The
"no change" condition can be accomplished either by disabling the clock signal or by feeding the
output back into the input, so that clock pulses keep the state of the flip-flop unchanged.
1.5.3 JK- Flip-Flop
A JK flip-flop is a refinement of the SR flip-flop in that the indeterminate condition of the SR
type is defined in the JK type. Inputs J and K behave like inputs S and R to set and clear the flip-flop,
respectively. When inputs J and K are both equal to 1, a clock transition switches the outputs of the
flip-flop to their complement state. The graphic symbol and characteristic table of the JK flip-flop
are shown in following figure. The J input is equivalent to the S (set) input of the SR flip-flop, and
the K input is equivalent to the R (clear) input. Instead of the indeterminate condition, the JK flip-
flop has a complement condition Q(t + 1) = Q'(t) when both J and K are equal to 1.
1.5.4 T-Flip-Flop
Another type of flip-flop found in textbooks is the T (toggle) flip-flop. This flip-flop, shown
in Fig. 1-22, is obtained from a JK type when inputs J and K are connected to provide a single input
designated by T. The T flip-floptherefore has only two conditions. When T = 0 (J = K = 0) a clock
transition does not change the state of the flip-flop. When T = 1 (J = K = 1) a clock transition
complements the state of the flip-flop. These conditions can be expressed by a characteristic
equation:
The combinational circuit block receives binary signals from external inputs and from the
outputs of flip-flops. The outputs of the combinational circuit go to external outputs and to inputs of
flip-flops. The gates in the combinational circuit determine the binary value to be stored in the flip-
flops after each clock transition. The outputs of flip-flops, in turn, are applied to the combinational
circuit inputs and determine the circuit's behavior. This process demonstrates that the external
outputs of a sequential circuit are functions of both external inputs and the present state of the flip-
flops. Moreover, the next state of flip-flops is also a function of their present state and external
inputs. Thus a sequential circuit is specified by a time sequence of external inputs, external outputs,
and internal flip-flop binary states.
An example of a sequential circuit is shown in Figure
DIGITAL COMPONENTS
1.7 Integrated Circuits
Digital circuits are constructed with integrated circuits. An integrated circuit (abbreviated IC)
is a small silicon semiconductor crystal called chip containing the electronic components for the
digital gates. The various gates are in interconnected inside the chip to form the required circuit. The
chip is mounted on a ceramic or plastic container, and connections are welded by thin gold wines to
external pins to form the integrated circuit. The number of pins may range from 14 in a small IC
package to 100 or more in a larger package. Each IC has a numeric designation printed on the
surface of the package for identification.
As the technology of ICs has improved, the number of gates that can be put in a single chip
has increased considerably.
Small-Scale integration (SSI) devices contain several independent gates in a single package. The
inputs and outputs of the gates are connected directly to the pins in the package. The number of gates
is usually less than 10 and is limited by the number of pins available in the IC.
Medium-scale integration (MSI) devices have a complexity of approximately 10 to 200 gates in a
single package. They usually perform specific elementary digital functions such as decoders, adders,
and registers.
Commercial decoders include one or more enable inputs to control the operation of the
circuit. The decoder of the above Figure has one enable input, E. The decoder is enabled when E is
equal to 1 and disabled when E is equal to 0. The operation of the decoder can be clarified using the
truth table listed in the following Table. When the enable input E is equal to 0, all the outputs are
equal to 0 regardless of the values of the other three data inputs. The three x's in the table designate
don't-care conditions. When the enable input is equal to 1, the decoder operates in a normal fashion.
For each possible input combination, there are seven outputs that are equal to 0 and only one that is
equal to 1. The output variable whose value is equal to 1 represents the octal number equivalent of
the binary number that is available in the input data lines.
1.9 Encoders
An encoder is a digital circuit that performs the inverse operation of a decoder. An encoder
has 2" (or less) input lines and n output lines. The output lines generate the binary code
corresponding to the input value. An example of an encoder is the octal-to-binary encoder, whose
truth table is given in the following Table. It has eight inputs, one for each of the octal digits, and
three outputs that generate the corresponding binary number. It is assumed that only one input has a
value of 1 at any given time; otherwise, the circuit has no meaning.
The encoder can be implemented with OR gates whose inputs are determined directly from
the truth table. Output A0 = 1 if the input octal digit is 1 or 3 or 5 or 7. Similar conditions apply for
the other two outputs. These conditions can be expressed by the following Boolean functions:
A0= D1 + D3+D5+D7
A1 = D2 + D3 + D6 + D7
A2 = D4 + D5 + D6 + D7
The encoder can be implemented with three OR gates.
1.10 Multiplexers
A multiplexer is a combinational circuit that receives binary information from one of 2n input
data lines and directs it to a single output line. The selection of a particular input data line for the
output is determined by a set of selection inputs. A 2n-to-1 multiplexer has 2n input data lines and n
input selection lines whose bit combinations determine which input data are selected for the output.
A4-to-1-line multiplexer is shown in the following Figure. Each of the four data inputs I0 through I1
is applied to one input of an AND gate.
The two selection inputs S1 and S0 are decoded to select a particular AND gate. The outputs
of the AND gates are applied to a single OR gate to provide the single output. To demonstrate the
circuit operation, consider the case when S1S0 = 10. The AND gate associated with input I1 has two
of its inputs equal to 1. The third input of the gate is connected to I2. The other three AND gates have
at least one input equal to 0, which makes their outputs equal to 0. The OR gate output is now equal
to the value of I2, thus providing a path from the selected input to the output.
The 4-to-1 line multiplexer of Figure has six inputs and one output. A truth table describing
the circuit needs 64 rows since six input variables can have 26 binary combinations. A more
convenient way to describe the operation of multiplexers is by means of a function table. The
function table for the multiplexer is shown in the following Table. The table demonstrates the
relationship between the four data inputs and the single output as a function of the selection inputs S1
and S0.When the selection inputs are equal to 00, output Y is equal to input I0. When the selection
inputs are equal to 01, input11 has a path to output Y, and similarly for the other two combinations.
The multiplexer is also called a data selector, since it selects one of many data inputs and steers the
binary information to the output.
The AND gates and inverters in the multiplexer resemble a decoder circuit, and indeed they
decode the input selection lines. In general, a 2"-to-1line multiplexer is constructed from an n-to-2"
decoder by adding to it 2" input lines, one from each data input. The size of the multiplexer is
specified by the number 2" of its data inputs and the single output. It is then implied that it also
contains n input selection lines. The multiplexer is often abbreviated as MUX. As in decoders,
multiplexers may have an enable input to control the operation of the unit. When the enable input is
in the inactive state, the outputs are disabled, and when it is in the active state, the circuit functions as
a normal multiplexer. The enable input is useful for expanding two or more multiplexers to a
multiplexer with a larger number of inputs. In some cases two or more multiplexers are enclosed
within a single integrated circuit package. The selection and the enable inputs in multiple-unit
construction are usually common to all multiplexers.
1.11 Registers
A register is a group of flip-flops with each flip-flop capable of storing one bit of
information. An n-bit register has a group of n flip-flops and is capable of storing any binary
information of n bits. In addition to the flip-flops, a register may have combinational gates that
perform certain data-processing tasks. In its broadest definition, a register consists of a group of flip-
flops and gates that effect their transition. The flip-flops hold the binary information and the gates
control when and how new information is transferred into the register.
The simplest register is one that consists only of flip-flops, with no external gates. The
following figure shows such a register constructed with four D flip-flops. The common clock input
triggers all flip-flops on the rising edge of each pulse, and the binary data available at the four inputs
are transferred into the 4-bit register. The four outputs can be sampled at any time to obtain the
binary information stored in the register. The clear input goes to a special terminal in each flip-flop.
When this input goes to 0, all flip-flops are reset asynchronously. The clear input is useful for
clearing the register to all 0's prior to its clocked operation. The clear input must be maintained at
logic 1 during normal clocked operation. Note that the clock signal enables the D input but that the
clear input is independent of the clock. The transfer of new information into a register is referred to
as loading the register.
If all the bits of the register are loaded simultaneously with a commonclock pulse transition,
we say that the loading is done in parallel. A clock transition applied to the C inputs of the register of
Figure will load all four inputs I0 through I3 in parallel. In this configuration, the clock must be
inhibited from the circuit if the content of the register must be left unchanged.
1.11.1 Register with Parallel Load
Most digital systems have a master clock generator that supplies a continuous train of clock
pulses. The clock pulses are applied to all flip-flops and registers in the system. The master clock
acts like a pump that supplies a constant beat to all parts of the system. A separate control signal
must be used to decide which specific clock pulse will have an effect on a particular register. A 4-bit
register with a load control input that is directed through gates and into the D inputs is shown in the
folowing Figure.
The C inputs receive clock pulses at all times. The buffer gate in the dock input reduces the
power requirement. With each clock pulse, the D input determines the next state of the output. To
leave the output unchanged, it is necessary to make the D input equal to the present value of the
output. Note that the clock pulses are applied to the C inputs at all times. The load input determines
whether the next pulse will accept new information or leave the information in the register intact.
Shift registers are often used to interface digital systems situated remotely from each other.
For example, suppose that it is necessary to transmit ann-bit quantity between two points. If the
distance between the source and the destination is too far, it will be expensive to use n lines to
transmit the n bits in parallel. It may be more economical to use a single line and transmit the
information serially one bit at a time. The transmitter loads the n-bit data inparallel into a shift
register and then transmits the data from the serial output line. The receiver accepts the data serially
The steps that must be taken for the purpose of transferring a new word to be stored into memory are
as follows:
1. Apply the binary address of the desired word into the address lines.
2. Apply the data bits that must be stored in memory into the data input lines.
3. Activate the write input.
The memory unit will then take the bits presently available in the input data lines and store them in
the word specified by the address lines. The steps that must be taken for the purpose of transferring a
stored word out of memory are as follows:
1. Apply the binary address of the desired word into the address lines.
2. Activate the read input.
ROMs find a wide range of applications in the design of digital systems. Basically, a ROM
generates an input---output relation specified by a truth table. As such, it can implement any
combinational circuit with k inputs and n outputs. When employed in a computer system as a
memory unit, the ROM is used for storing fixed programs that are not to be altered and for tables of
constants that are not subject to change. ROM is also employed in the design of control units for
digital computers. As such, they are used to store coded information that represents the sequence of
internal control variables needed for enabling the various operations in the computer. A control unit
that utilizes a ROM to store binary control information is called a microprogrammed control unit.
2. Programmable read-only memory : For small quantities it is more economical to use a second
type of ROM called a programmable read-only memory or PROM. When ordered. PROM
units contain all the fuses intact, giving all 1' s in the bits of the stored words. The fuses in the
PROM are blown by application of current pulses through the output terminals for each address.
A blown fuse defines a binary 0 state, and an intact fuse gives a binary 1 state. This allows users
to program PROMs in their own laboratories to achieve the desired relationship between input
addresses and stored words. Special instruments called PROM programmers are available
commercially to facilitate this procedure. In any case, all procedures for programming ROMs are
hardware procedures even though the word "programming" is used. The hardware procedure for
programming ROMs or PROMs is irreversible, and once programmed, the fixed pattern is
permanent and cannot be altered. Once a bit pattern has been established, the unit must be
discarded if the bit pattern is to be changed.
3. Erasable PROM or EPROM. : A third type of ROM available is called erasable PROM or
EPROM. The EPROM can be restructured to the initial value even though its fuses have been
blown previously. When the EPROM is placed under a special ultraviolet light for a given period
of time, the shortwave radiation discharges the internal gates that serve as fuses. After erasure,
the EPROM returns to its initial state and can be reprogrammed to a new set of words. Certain
PROMs can be erased with electrical signals instead of ultraviolet light. These PROMs are called
electrically erasable PROM or EEPROM.
Decimal Representation
Binary Number System is the most natural system for a computer, but the people are
accustomed to the decimal system. One way to solve this conflict is to convert all input decimal
numbers into binary numbers, let the computer perform all the operations in binary and convert the
result into decimal. It is also possible for the computer to perform all arithmetic operations directly
with decimal numbers provided they are placed in the registers in a coded form.
It is important to understand the difference between the conversion of decimal numbers into
binary and the binary coding of decimal numbers. For example when converted into binary number,
the decimal number 99 is represented as 1100011. But when represented in BCD it is
1001 1001
Few decimal numbers and their representation in BCD are as follows
Alphanumeric Representation
Many applications of digital computers require handling of data that consists of not only of numbers
but also letters and special characters. The standard alphanumeric binary code is ASCII (American
Standard Code for Information Interchange) which uses 7 bits to code 128 characters.
Complements
Complements are used in digital computers for simplifying the subtraction operation and for logical
manipulation. There are two types of complements for each base r system: the r's complement and
the (r - l)'s complement.
9' s complement ,10's complement
l's complement ,2's complement
When the value of the base r is substituted in the name, the two types are referred to as the 2's and 1's
complement for binary numbers and the 10's and 9's complement for decimal numbers.
(r - l)'s Complement
Given a number N in base r having n digits, the (r - 1)'s complement of N is defined as
Fixed-Point Representation
Positive integers, including zero, can be represented as unsigned numbers. However, to
represent negative integers, we need a notation for negative values. In ordinary arithmetic, a negative
number is indicated by a minus sign and a positive number by a plus sign. Because of hardware
limitations, computers must represent everything with 1's and 0's, including the sign of a number. As
a consequence, it is customary to represent the sign with a bit placed in the leftmost position of the
number. The convention is to make the sign bit equal to 0 for positive and to 1 for negative. In
addition to the sign, a number may have a binary (or decimal) point. The position of the binary point
is needed to represent fractions, integers, or mixed integer-fraction numbers. The representation of
the binary point in a register is complicated by the fact that it is characterized by a position in the
register. There are two ways of specifying the position of the binary point in a register: by giving it a
fixed position or by employing a floating-point representation.
The fixed-point method assumes that the binary point is always fixed in one position. The two
positions most widely used are
(1) a binary point in the extreme left of the register to make the stored number a fraction, and
(2) a binary point in the extreme right of the register to make the stored number an integer.
In either case, the binary point is not actually present, but its presence is assumed from the
fact that the number stored in the register is treated as a fraction or as an integer. The floating-point
representation uses a second register to store a number that designates the position of the decimal
point in the first register. Floating-point representation is discussed further in the next section.
Integer Representation
When an integer binary number is positive the sign is represented with 0, when the number is
negative the sign is represented by 1 but the rest of the number is represented in one of three possible
ways:
Signed Magnitude representation of negative number consists of the magnitude and negative
number. In the other two representations, the negative number is represented in either 1’s
complement or 2’s complement of its positive value.
For example,
+ 14 is represented in the 8 bit register as 00001110
There are three different ways to represent -14
Arithmetic Addition
Addition of two numbers in signed magnitude system follows the rules of ordinary arithmetic. For
example
(+32) + (- 45) = - ( 45 -32 ) = - 13
This process requires comparison of signs and magnitudes and then performing addition or
subtraction. In Signed 2’s complement method, no comparison and no subtraction requires only
addition and complementation.
In each of the above four cases, the operation performed is only addition. Any carry out of the sign
bit position is discarded and negative results are automatically in 2’s complement form.
Arithmetic Subtraction
Subtraction of two signed binary numbers is as follows: Take the 2’s complement of subtrahend and
add it to the minuend, a carry out of the sign bit position is discarded. Therefore computers need only
one common circuit to handle both types of operations.
If two carries are applied to EX-OR gate, an over flow can be detected, when it gives 1 as output.
Floating Point Representation
A Floating Point representation of a number has two parts, the first part represents a signed
fied point number called Mantissa. The second part designates the position of the decimal point and
is called as an Exponent. The fixed point mantissa may be fraction or integer. For example the
decimal number +6132.789 is represented in floating point with a fraction and an exponent as
follows:
Mantissa Exponent
+0.6132789 +04
The value of the exponent indicates that the actual position of the decimal point if four
positions to the right of the indicated decimal point in the fraction. This representation is equivalent
to the scientific notation: 0.6132789 X 10+4
8421 Codes
2421 Codes
5211 Codes
Excess-3 Codes
Gray Codes
In the above list, the first three i.e. 8421, 2421 and 5211 are Weighted codes while the other two are
non-weighted binary codes.
0 0 0000
1 1 0001
2 10 0010
3 11 0011
4 100 0100
5 101 0101
6 110 0110
7 111 0111
8 1000 1000
9 1001 1001
As per the above expression all the decimal numbers written in the 4 Bit binary code in the form of
8421 and this is called as 8421 Code and also as Binary coded decimal BCD.
As this is a straight code, any Decimal number can be expressed easily because the weights of the
positions are straight for easy conversion into this 8421 code.
There are other forms of codes which are not so popular but rather confusing. They are 2421 code,
5211 code, reflective code, sequential code, non- weighted coded, excess-3 code and Grey code.
They are having their own importance for some of the exclusive applications and may be useful for
some of the typical applications.
2421 Code
This code also a 4 bit application code where the binary weights carry 2, 4, 2, 1 from left to right.
DECIMAL BINARY
2421 CODE
NUMBER NUMBER
0 0 0000
DECIMAL BINARY
2421 CODE
NUMBER NUMBER
1 1 0001
2 10 0010
3 11 0011
4 100 0100
5 101 1011
6 110 1100
7 111 1101
8 1000 1110
9 1001 1111
Excess-3 Code
As mentioned above, some of the codes will not follow the binary weights, Excee-3 code is an
example of it and it is an important 4 bit code. The excess – 3 code of a decimal number is achieved
by adding the number 3 to the 8421 code.
For example to convert 15 to an excess-3 code, first 3 to be added to each digit as shown below.
BACK TO TOP
0 0000 0000
1 0001 0001
2 0010 0011
3 0011 0010
4 0100 0110
5 0101 0111
6 0110 0101
7 0111 0100
8 1000 1100
9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
EBCDIC Code
EBCDIC stands for Extended Binary Coded Decimal Interchange Code. IBM invented this
code to extend the Binary Coded Decimal which existed at that time. All the IBM computers and
peripherals use this code. It is an 8-bit code and therefore can accommodate 256 characters. Below
are given some characters of EBCDIC code to get familiar with it.
A parity bit is an extra bit included in binary message to make total number of 1’s either
odd or even. Parity word denotes number of 1’s in a binary string. There are two parity system -
even and odd. In even parity system 1 is appended to binary string it there is an odd number of 1’s
in string otherwise 0 is appended to make total even number of 1’s.
In odd parity system, 1 is appended to binary string if there is even a number of 1’s to make
an odd number of 1’s. The receiver knows that whether sender is an odd parity generator or even
parity generator. Suppose if sender is an odd parity generator then there must be an odd number of
1’s in received binary string. If an error occurs to a single bit that is either bit is changed to 1 to 0
or O to 1, received binary bit will have an even number of 1’s which will indicate an error.
The limitation of this method is that only error in a single bit would be identified.
Message (XYZ) P(Odd) P(Even)
000 1 0
001 0 1
010 0 1
011 1 0
100 0 1
101 1 0
110 1 0
111 0 1
Instruction code
A Program, as we all know, is a set of instructions that specify the operations, operands, and the
sequence by which processing has to occur. An instruction code is a group of bits that tells the
computer to perform a specific operation part.
The operation code of an instruction is a group of bits that define operations such as add, subtract,
multiply, shift and compliment. The number of bits required for the operation code depends upon the
total number of operations available on the computer. The operation code must consist of at least n
bits for a given 2^n operations. The operation part of an instruction code specifies the operation to
be performed.
The operation must be performed on the data stored in registers. An instruction code therefore
specifies not only operations to be performed but also the registers where the operands(data) will be
found as well as the registers where the result has to be stored.
Computers with a single processor register is known as Accumulator (AC). The operation is
performed with the memory operand and the content of AC.
Addressing Modes
The operation field of an instruction specifies the operation to be performed. This operation will be
executed on some data which is stored in computer registers or the main memory. The way any
operand is selected during the program execution is dependent on the addressing mode of the
instruction.
1. Immediate Mode
In this mode, the operand is specified in the instruction itself. An immediate mode instruction has an
operand field rather than the address field.
A processor register may hold an instruction, a storage address, or any data (such as bit sequence or
individual characters).
The computer needs processor registers for manipulating data and a register for holding a memory
address. The register holding the memory location is used to calculate the address of the next
instruction after the execution of the current instruction is completed.
Following is the list of some of the most common registers used in a basic computer:
o The Memory unit has a capacity of 4096 words, and each word contains 16 bits.
o The Data Register (DR) contains 16 bits which hold the operand read from the memory
location.
o The Memory Address Register (MAR) contains 12 bits which hold the address for the
memory location.
o The Program Counter (PC) also contains 12 bits which hold the address of the next
instruction to be read from memory after the current instruction is executed.
o The Accumulator (AC) register is a general purpose processing register.
o The instruction read from memory is placed in the Instruction register (IR).
o The Temporary Register (TR) is used for holding the temporary data during the processing.
o The Input Registers (IR) holds the input characters given by the user.
o The Output Registers (OR) holds the output after processing the input data.
Paths must be provided to transfer information from one register to another and between
memory and registers. The number of wires will be excessive if connections are made between the
outputs of each register and the inputs of the other registers. A more efficient scheme for transferring
information in a system with many registers is to use a common bus. We can construct a bus
system using multiplexers or three-state buffer gates. We just have to connect the registers and
memory of the basic computer to a common bus system.
The outputs of seven registers and memory are connected to the common bus. 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. The number along each output shows the decimal equivalent of
the required binary selection. 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 since this is the binary value of
decimal 3.
The lines from the common bus are connected to the inputs of each register and the data
inputs of the memory. The particular register whose LD (load) input is enabled receives the data
from the bus during the next clock pulse transition. The memory receives the contents of the bus
when its write input is activated. The memory places its 16-bit output onto the bus when the read
input is activated and S2S1S0 = 111.
Four registers, DR, AC, IR, and TR, have 16 bits each. Two registers, AR and PC, have 12
bits each since they hold a memory address. When the contents of AR or PC are applied to the 16-bit
common bus, the four most significant bits are set to O's. When AR or PC receive information from
the bus, only the 12 least significant bits are transferred into the register.
The input register INPR and the output register OUTR have 8 bits each and
communicate with the eight least significant bits in the bus. INPR is connected to provide
information to the bus but OUTR can only receive information from the bus. This is because INPR
receives a character from an input device which is then transferred to AC.
The 16 inputs of AC come from an adder and logic circuit. This circuit has three sets of
inputs. One set of 16-bit inputs come from the outputs of AC . They are used to implement register
rnlcrooperations such as complement AC and shift AC . Another set of 16-bit inputs come from the
Computer Instructions
Computer instructions are a set of machine language instructions that a particular processor
understands and executes. A computer performs tasks on the basis of the instruction provided. An
instruction comprises of groups called fields. These fields include:
o The Operation code (Opcode) field which specifies the operation to be performed.
o The Address field which contains the location of the operand, i.e., register or memory
location.
o The Mode field which specifies how the operand will be located.
In Memory-reference instruction, 12 bits of memory is used to specify an address and one bit to
specify the addressing mode 'I'.
The Register-reference instructions are represented by the Opcode 111 with a 0 in the leftmost bit
(bit 15) of the instruction.
Just like the Register-reference instruction, an Input-Output instruction does not need a reference to
memory and is recognized by the operation code 111 with a 1 in the leftmost bit of the instruction.
The remaining 12 bits are used to specify the type of the input-output operation or test performed.
In order to specify the micro operations needed for the execution of each operation, it is necessary
that the function intended to perform be defined precisely. The decoded output Di for i=0,1,2,3,4,5,6
from the operation decoder that belongs to each instruction is included in the following table.
D0T4:DR<-M[AR]
D0T5:AC<-AC/\DR, SC<---0
The control function for this instruction uses the operation decoder D0 since this output of the
decoder is active when the instruction has an AND operation whose binary code value 000. Two
timing signals are needed to execute the instruction. The clock transition associated with timing
signal T4 transfers the operand from memory into DR . The clock transition associated with the next
timing signal T5 transfers to AC the result of the AND logic operation between the contents of DR
and AC. The same clock transition clears SC to 0, transferring control to timing signal T0 to start a
new instruction cycle.
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 Cout is transferred to the E (extended
accumulator) flip-flop. The rnicrooperations needed to execute this instruction are
D1T4:DR←M[AR]
D1T5: AC← AC + DR, E← Cout , SC ← 0
Same Two timing signals, T, and T5, are used again but with operation decoder D1 instead of D0,
which was used for the AND instruction. After the instruction is fetched from memory and decoded,
only one output of the operation decoder will be active, and that output determines the sequence of
microoperations that the control follows during the execution of a memory-reference instruction.
LDA: Load to AC
This instruction transfers the memory word specified by the effective address to AC . The
microoperations needed to execute this instruction are
D2T4: DR← M[AR]
D2T5: AC← DR← 0
STA: Store AC
This instruction stores the content of AC into the memory word specified by the effective address.
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:
This instruction transfers the program to the instruction specified by the effective address.
Remember that PC holds the address of the instruction to be read from memory in the next
instruction cycle. PC is incremented at time T1 to prepare it for the address of the next instruction in
the program sequence. The BUN instruction allows the programmer to specify an instruction out of
sequence and we say that the program branches (or jumps) unconditionally. The instruction is
executed with one microoperation:
D4T4: PC ← AR, SC ← 0
The effective address from AR is transferred through the common bus to PC .Resetting SC to 0
transfers control to T0• The next instruction is then fetched and executed from the memory address
given by the new value in PC .
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. The effective address
plus one is then transferred to PC to serve as the address of the first instruction in the subroutine.
This operation was specified in Table 5-4 with the following register transfer:
The result of this operation is shown in part (b) of the figure. The return address 21 is stored in
memory location 135 and control continues with the subroutine program starting from address 136.
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. 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. When the BUN instruction is executed, the effective address 21 is transferred to PC .
The next instruction cycle finds PC with the value 21, so control continues to execute the instruction
at the return address.
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. This is done with the following sequence
of microoperations:
D6T4: DR<--M[AR]
D6T5: DR<--DR+1
D,T,: M[AR]<--DR, if (DR = 0) then (PC ← PC + 1), SC ← 0
Register – Reference Instructions
Register-reference instructions are recognized by the control when 07 = 1 and I = 0. These
instructions use bits 0 through 11 of the instruction code to specify one of 12 instructions. These 12
bits are available in IR(0-11). They were also transferred to AR during time T2•
The control functions and microoperations for the register-reference instructions are. listed in
the following Table. These instructions are executed with the clock transition associated with timing
variable T3. Each control function needs the Boolean relation D7I'T3, which we designate for
convenience by the symbol r. The control function is distinguished by one of the bits in IR(0-11).
By assigning the symbol B, to bit i of IR, all control functions can be simply denoted by rB;.
For example, the instruction CLA has the hexadecimal code 7800 (see Table 5-2), which
gives the binary equivalent 011I 1000 0000 0000. The first bit is a zero and is equivalent to I'. The
next three bits constitute the operation code and are recognized from decoder output D7. Bit 11 in
IR is I and is recognized from 811. The control function that initiates the rnicrooperation for this
instruction is D7I'T3B11 = rB11. The execution of a register-reference instruction is completed at
time T3. The sequence counter SC is cleared to 0 and the control goes back to fetch the next
instruction with timing signal T0.
In the hardwired organization, the control logic is implemented with gates, flip-flops, decoders,
and other digital circuits. It has the advantage that it can be optimized to produce a fast mode of
operation. In the microprogrammed organization, the control information is stored in a control
memory. The control memory is programmed to initiate the required sequence of microoperations.
A hardwired control, as the name implies, requires changes in the wiring among the various
components if the design has to be modified or changed.
In the microprogrammed control, any required changes or modifications can be done by updating
the microprogram in control memory.
Instruction Cycle
A program residing in the memory unit of a computer consists of a sequence of instructions. These
instructions are executed by the processor by going through a cycle for each instruction.
T0: AR ← PC
T1: IR ← M[AR], PC ← PC + 1
T2: D0, .... , D7 ← Decode IR(12-14), AR ← IR(0-11), I ← IR(15)
Since only AR is connected to the address inputs of memory, it is necessary to transfer the
address from PC to AR during the clock transition associated with timing signal T0. The instruction
read from memory is then placed in the instruction register IR with the clock transition associated
with timing signal T1.
At the same time, PC is incremented by one to prepare it for the address of the next instruction in the
program. At time T2, the operation code in IR is decoded, the indirect bit is transferred to flip-flop I,
and the address part of the instruction is transferred to AR. Note that SC is incremented after each
clock pulse to produce the sequence T0, T1, and T2. Figure above shows how the first two register
transfer statements are implemented in the bus system. To provide the data path for the transfer of
PC to AR we must apply timing signal T0 to achieve the following connection:
1. Place the content of PC onto the bus by making the bus selection inputs
S2S1S0 equal to 010.
2. Transfer the content of the bus to AR by enabling the LD input of AR .
The next clock transition initiates the read and increment operations since T1 = 1. Figure
above duplicates a portion of the bus system and shows how T0 and T1 are connected to the control
inputs of the registers, the memory, and the bus selection inputs. Multiple input OR gates are
included in the diagram because there are other control functions that will initiate similar operations.
If D7 = 0, the operation code must be one of the other seven values 000 through 110, specifying a
memory-reference instruction. Control then inspects the value of the first bit of the instruction,
which is now available in flip-flop I. If D7 = 0 and I = 1, we have a memory reference instruction
with an indirect address.
The three instruction types are subdivided into four separate paths. The selected operation is
activated with the clock transition associated with timing signal T3. This can be symbolized as
follows:
The input register INPR consists of eight bits and holds an alphanumeric input information.
The 1-bit input flag FGI is a control flip-flop. 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.
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. Initially, the input flag FGI is cleared to
0. When a key is struck in the keyboard, an 8-bit alphanumeric code is shifted into INPR and the
input flag FGI is set to 1. As long as the flag is set, the information in INPR cannot be changed by
striking another key. The computer checks the flag bit; if it is 1, the information from INPR is
transferred in parallel into AC and FGI is cleared to 0. Once the flag is cleared, new information can
be shifted into INPR by striking another key.
Program Interrupt
The computer keeps checking the flag bit, and when it finds it set, it initiates an information
transfer. The difference of information flow rate between the computer and that of the input—
output device makes this type of transfer inefficient. An alternative to the programmed controlled
procedure is to let the external device inform the computer when it is ready for the transfer. In the
meantime the computer can be busy with other tasks. This type of transfer uses the interrupt facility.
While the computer is running a program, it does not check the flags. When a flag is set, the
computer is momentarily interrupted from the current program. The computer deviates momentarily
from what it is doing to perform of the input or output transfer. It then returns to the current
program to continue what it was doing before the interrupt.
The interrupt enable flip-flop IEN can be set and cleared with two instructions. When IEN is
cleared to 0 (with the IOF instruction), the flags cannot interrupt the computer. When IEN is set to
(with the ION instruction), the computer can be interrupted. The way that the interrupt is handled
by the computer can be explained by means of the flowchart.
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 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.
Dr. M. Kalpana Devi, Assoc. Professor, SITAMS 76
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES.
(AUTONOMOUS)
MCA DEPARTMENT
LECTURE NOTES
Computer Organization and Architecture
Interrupt cycle
The interrupt cycle is a hardware implementation of a branch and save return address
operation. The return address available in PC is stored in a specific location. This location may be a
processor register, a memory stack, or a specific memory location. An example that shows what
happens during the interrupt cycle is shown in the following Figure.
When an interrupt occurs and R is set to 1 while the control is executing the instruction at
address 255. At this time, the returns 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. This is shown in Figure(a). When control reaches timing signal T0and
finds that R = 1, it proceeds with the interrupt cycle. The content of PC (256) is stored in memory
location 0, PC is set to 1, and R is cleared to 0. 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. This is shown in Figure(b).
Decimal Representation
Binary Number System is the most natural system for a computer, but the people are
accustomed to the decimal system. One way to solve this conflict is to convert all input decimal
numbers into binary numbers, let the computer perform all the operations in binary and convert the
result into decimal. It is also possible for the computer to perform all arithmetic operations directly
with decimal numbers provided they are placed in the registers in a coded form.
It is important to understand the difference between the conversion of decimal numbers into
binary and the binary coding of decimal numbers. For example when converted into binary number,
the decimal number 99 is represented as 1100011. But when represented in BCD it is
1001 1001
Few decimal numbers and their representation in BCD are as follows
Alphanumeric Representation
Many applications of digital computers require handling of data that consists of not only of numbers
but also letters and special characters. The standard alphanumeric binary code is ASCII (American
Standard Code for Information Interchange) which uses 7 bits to code 128 characters.
Complements
Complements are used in digital computers for simplifying the subtraction operation and for logical
manipulation. There are two types of complements for each base r system: the r's complement and
the (r - l)'s complement.
9' s complement ,10's complement
l's complement ,2's complement
When the value of the base r is substituted in the name, the two types are referred to as the 2's and 1's
complement for binary numbers and the 10's and 9's complement for decimal numbers.
(r - l)'s Complement
Given a number N in base r having n digits, the (r - 1)'s complement of N is defined as
Fixed-Point Representation
Positive integers, including zero, can be represented as unsigned numbers. However, to
represent negative integers, we need a notation for negative values. In ordinary arithmetic, a negative
number is indicated by a minus sign and a positive number by a plus sign. Because of hardware
limitations, computers must represent everything with 1's and 0's, including the sign of a number. As
a consequence, it is customary to represent the sign with a bit placed in the leftmost position of the
number. The convention is to make the sign bit equal to 0 for positive and to 1 for negative. In
addition to the sign, a number may have a binary (or decimal) point. The position of the binary point
is needed to represent fractions, integers, or mixed integer-fraction numbers. The representation of
the binary point in a register is complicated by the fact that it is characterized by a position in the
register. There are two ways of specifying the position of the binary point in a register: by giving it a
fixed position or by employing a floating-point representation.
The fixed-point method assumes that the binary point is always fixed in one position. The two
positions most widely used are
(1) a binary point in the extreme left of the register to make the stored number a fraction, and
(2) a binary point in the extreme right of the register to make the stored number an integer.
In either case, the binary point is not actually present, but its presence is assumed from the
fact that the number stored in the register is treated as a fraction or as an integer. The floating-point
representation uses a second register to store a number that designates the position of the decimal
point in the first register. Floating-point representation is discussed further in the next section.
Integer Representation
When an integer binary number is positive the sign is represented with 0, when the number is
negative the sign is represented by 1 but the rest of the number is represented in one of three possible
ways:
Signed Magnitude representation of negative number consists of the magnitude and negative
number. In the other two representations, the negative number is represented in either 1’s
complement or 2’s complement of its positive value.
For example,
+ 14 is represented in the 8 bit register as 00001110
There are three different ways to represent -14
Arithmetic Addition
Addition of two numbers in signed magnitude system follows the rules of ordinary arithmetic. For
example
(+32) + (- 45) = - ( 45 -32 ) = - 13
This process requires comparison of signs and magnitudes and then performing addition or
subtraction. In Signed 2’s complement method, no comparison and no subtraction requires only
addition and complementation.
In each of the above four cases, the operation performed is only addition. Any carry out of the sign
bit position is discarded and negative results are automatically in 2’s complement form.
Arithmetic Subtraction
Subtraction of two signed binary numbers is as follows: Take the 2’s complement of subtrahend and
add it to the minuend, a carry out of the sign bit position is discarded. Therefore computers need only
one common circuit to handle both types of operations.
If two carries are applied to EX-OR gate, an over flow can be detected, when it gives 1 as output.
Floating Point Representation
A Floating Point representation of a number has two parts, the first part represents a signed
fied point number called Mantissa. The second part designates the position of the decimal point and
is called as an Exponent. The fixed point mantissa may be fraction or integer. For example the
decimal number +6132.789 is represented in floating point with a fraction and an exponent as
follows:
Mantissa Exponent
+0.6132789 +04
The value of the exponent indicates that the actual position of the decimal point if four
positions to the right of the indicated decimal point in the fraction. This representation is equivalent
to the scientific notation: 0.6132789 X 10+4
8421 Codes
2421 Codes
5211 Codes
Excess-3 Codes
Gray Codes
In the above list, the first three i.e. 8421, 2421 and 5211 are Weighted codes while the other two are
non-weighted binary codes.
0 0 0000
1 1 0001
2 10 0010
3 11 0011
4 100 0100
5 101 0101
6 110 0110
7 111 0111
8 1000 1000
9 1001 1001
As per the above expression all the decimal numbers written in the 4 Bit binary code in the form of
8421 and this is called as 8421 Code and also as Binary coded decimal BCD.
As this is a straight code, any Decimal number can be expressed easily because the weights of the
positions are straight for easy conversion into this 8421 code.
There are other forms of codes which are not so popular but rather confusing. They are 2421 code,
5211 code, reflective code, sequential code, non- weighted coded, excess-3 code and Grey code.
They are having their own importance for some of the exclusive applications and may be useful for
some of the typical applications.
2421 Code
This code also a 4 bit application code where the binary weights carry 2, 4, 2, 1 from left to right.
DECIMAL BINARY
2421 CODE
NUMBER NUMBER
0 0 0000
DECIMAL BINARY
2421 CODE
NUMBER NUMBER
1 1 0001
2 10 0010
3 11 0011
4 100 0100
5 101 1011
6 110 1100
7 111 1101
8 1000 1110
9 1001 1111
Excess-3 Code
As mentioned above, some of the codes will not follow the binary weights, Excee-3 code is an
example of it and it is an important 4 bit code. The excess – 3 code of a decimal number is achieved
by adding the number 3 to the 8421 code.
For example to convert 15 to an excess-3 code, first 3 to be added to each digit as shown below.
BACK TO TOP
0 0000 0000
1 0001 0001
2 0010 0011
3 0011 0010
4 0100 0110
5 0101 0111
6 0110 0101
7 0111 0100
8 1000 1100
9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
EBCDIC Code
EBCDIC stands for Extended Binary Coded Decimal Interchange Code. IBM invented this
code to extend the Binary Coded Decimal which existed at that time. All the IBM computers and
peripherals use this code. It is an 8-bit code and therefore can accommodate 256 characters. Below
are given some characters of EBCDIC code to get familiar with it.
A parity bit is an extra bit included in binary message to make total number of 1’s either
odd or even. Parity word denotes number of 1’s in a binary string. There are two parity system -
even and odd. In even parity system 1 is appended to binary string it there is an odd number of 1’s
in string otherwise 0 is appended to make total even number of 1’s.
In odd parity system, 1 is appended to binary string if there is even a number of 1’s to make
an odd number of 1’s. The receiver knows that whether sender is an odd parity generator or even
parity generator. Suppose if sender is an odd parity generator then there must be an odd number of
1’s in received binary string. If an error occurs to a single bit that is either bit is changed to 1 to 0
or O to 1, received binary bit will have an even number of 1’s which will indicate an error.
The limitation of this method is that only error in a single bit would be identified.
Message (XYZ) P(Odd) P(Even)
000 1 0
001 0 1
010 0 1
011 1 0
100 0 1
101 1 0
110 1 0
111 0 1
Instruction code
A Program, as we all know, is a set of instructions that specify the operations, operands, and the
sequence by which processing has to occur. An instruction code is a group of bits that tells the
computer to perform a specific operation part.
The operation code of an instruction is a group of bits that define operations such as add, subtract,
multiply, shift and compliment. The number of bits required for the operation code depends upon the
total number of operations available on the computer. The operation code must consist of at least n
bits for a given 2^n operations. The operation part of an instruction code specifies the operation to
be performed.
The operation must be performed on the data stored in registers. An instruction code therefore
specifies not only operations to be performed but also the registers where the operands(data) will be
found as well as the registers where the result has to be stored.
Computers with a single processor register is known as Accumulator (AC). The operation is
performed with the memory operand and the content of AC.
Addressing Modes
The operation field of an instruction specifies the operation to be performed. This operation will be
executed on some data which is stored in computer registers or the main memory. The way any
operand is selected during the program execution is dependent on the addressing mode of the
instruction.
10.Immediate Mode
In this mode, the operand is specified in the instruction itself. An immediate mode instruction has an
operand field rather than the address field.
A processor register may hold an instruction, a storage address, or any data (such as bit sequence or
individual characters).
The computer needs processor registers for manipulating data and a register for holding a memory
address. The register holding the memory location is used to calculate the address of the next
instruction after the execution of the current instruction is completed.
Following is the list of some of the most common registers used in a basic computer:
o The Memory unit has a capacity of 4096 words, and each word contains 16 bits.
o The Data Register (DR) contains 16 bits which hold the operand read from the memory
location.
o The Memory Address Register (MAR) contains 12 bits which hold the address for the
memory location.
o The Program Counter (PC) also contains 12 bits which hold the address of the next
instruction to be read from memory after the current instruction is executed.
o The Accumulator (AC) register is a general purpose processing register.
o The instruction read from memory is placed in the Instruction register (IR).
o The Temporary Register (TR) is used for holding the temporary data during the processing.
o The Input Registers (IR) holds the input characters given by the user.
o The Output Registers (OR) holds the output after processing the input data.
Paths must be provided to transfer information from one register to another and between
memory and registers. The number of wires will be excessive if connections are made between the
outputs of each register and the inputs of the other registers. A more efficient scheme for transferring
information in a system with many registers is to use a common bus. We can construct a bus
system using multiplexers or three-state buffer gates. We just have to connect the registers and
memory of the basic computer to a common bus system.
The outputs of seven registers and memory are connected to the common bus. 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. The number along each output shows the decimal equivalent of
the required binary selection. 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 since this is the binary value of
decimal 3.
The lines from the common bus are connected to the inputs of each register and the data
inputs of the memory. The particular register whose LD (load) input is enabled receives the data
from the bus during the next clock pulse transition. The memory receives the contents of the bus
when its write input is activated. The memory places its 16-bit output onto the bus when the read
input is activated and S2S1S0 = 111.
Four registers, DR, AC, IR, and TR, have 16 bits each. Two registers, AR and PC, have 12
bits each since they hold a memory address. When the contents of AR or PC are applied to the 16-bit
common bus, the four most significant bits are set to O's. When AR or PC receive information from
the bus, only the 12 least significant bits are transferred into the register.
The input register INPR and the output register OUTR have 8 bits each and
communicate with the eight least significant bits in the bus. INPR is connected to provide
information to the bus but OUTR can only receive information from the bus. This is because INPR
receives a character from an input device which is then transferred to AC.
The 16 inputs of AC come from an adder and logic circuit. This circuit has three sets of
inputs. One set of 16-bit inputs come from the outputs of AC . They are used to implement register
rnlcrooperations such as complement AC and shift AC . Another set of 16-bit inputs come from the
Computer Instructions
Computer instructions are a set of machine language instructions that a particular processor
understands and executes. A computer performs tasks on the basis of the instruction provided. An
instruction comprises of groups called fields. These fields include:
o The Operation code (Opcode) field which specifies the operation to be performed.
o The Address field which contains the location of the operand, i.e., register or memory
location.
o The Mode field which specifies how the operand will be located.
In Memory-reference instruction, 12 bits of memory is used to specify an address and one bit to
specify the addressing mode 'I'.
The Register-reference instructions are represented by the Opcode 111 with a 0 in the leftmost bit
(bit 15) of the instruction.
Just like the Register-reference instruction, an Input-Output instruction does not need a reference to
memory and is recognized by the operation code 111 with a 1 in the leftmost bit of the instruction.
The remaining 12 bits are used to specify the type of the input-output operation or test performed.
In order to specify the micro operations needed for the execution of each operation, it is necessary
that the function intended to perform be defined precisely. The decoded output Di for i=0,1,2,3,4,5,6
from the operation decoder that belongs to each instruction is included in the following table.
D0T4:DR<-M[AR]
D0T5:AC<-AC/\DR, SC<---0
The control function for this instruction uses the operation decoder D0 since this output of the
decoder is active when the instruction has an AND operation whose binary code value 000. Two
timing signals are needed to execute the instruction. The clock transition associated with timing
signal T4 transfers the operand from memory into DR . The clock transition associated with the next
timing signal T5 transfers to AC the result of the AND logic operation between the contents of DR
and AC. The same clock transition clears SC to 0, transferring control to timing signal T0 to start a
new instruction cycle.
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 Cout is transferred to the E (extended
accumulator) flip-flop. The rnicrooperations needed to execute this instruction are
D1T4:DR←M[AR]
D1T5: AC← AC + DR, E← Cout , SC ← 0
Same Two timing signals, T, and T5, are used again but with operation decoder D1 instead of D0,
which was used for the AND instruction. After the instruction is fetched from memory and decoded,
only one output of the operation decoder will be active, and that output determines the sequence of
microoperations that the control follows during the execution of a memory-reference instruction.
LDA: Load to AC
This instruction transfers the memory word specified by the effective address to AC . The
microoperations needed to execute this instruction are
D2T4: DR← M[AR]
D2T5: AC← DR← 0
STA: Store AC
This instruction stores the content of AC into the memory word specified by the effective address.
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:
This instruction transfers the program to the instruction specified by the effective address.
Remember that PC holds the address of the instruction to be read from memory in the next
instruction cycle. PC is incremented at time T1 to prepare it for the address of the next instruction in
the program sequence. The BUN instruction allows the programmer to specify an instruction out of
sequence and we say that the program branches (or jumps) unconditionally. The instruction is
executed with one microoperation:
D4T4: PC ← AR, SC ← 0
The effective address from AR is transferred through the common bus to PC .Resetting SC to 0
transfers control to T0• The next instruction is then fetched and executed from the memory address
given by the new value in PC .
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. The effective address
plus one is then transferred to PC to serve as the address of the first instruction in the subroutine.
This operation was specified in Table 5-4 with the following register transfer:
The result of this operation is shown in part (b) of the figure. The return address 21 is stored in
memory location 135 and control continues with the subroutine program starting from address 136.
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. 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. When the BUN instruction is executed, the effective address 21 is transferred to PC .
The next instruction cycle finds PC with the value 21, so control continues to execute the instruction
at the return address.
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. This is done with the following sequence
of microoperations:
D6T4: DR<--M[AR]
D6T5: DR<--DR+1
D,T,: M[AR]<--DR, if (DR = 0) then (PC ← PC + 1), SC ← 0
Register – Reference Instructions
Register-reference instructions are recognized by the control when 07 = 1 and I = 0. These
instructions use bits 0 through 11 of the instruction code to specify one of 12 instructions. These 12
bits are available in IR(0-11). They were also transferred to AR during time T2•
The control functions and microoperations for the register-reference instructions are. listed in
the following Table. These instructions are executed with the clock transition associated with timing
variable T3. Each control function needs the Boolean relation D7I'T3, which we designate for
convenience by the symbol r. The control function is distinguished by one of the bits in IR(0-11).
By assigning the symbol B, to bit i of IR, all control functions can be simply denoted by rB;.
For example, the instruction CLA has the hexadecimal code 7800 (see Table 5-2), which
gives the binary equivalent 011I 1000 0000 0000. The first bit is a zero and is equivalent to I'. The
next three bits constitute the operation code and are recognized from decoder output D7. Bit 11 in
IR is I and is recognized from 811. The control function that initiates the rnicrooperation for this
instruction is D7I'T3B11 = rB11. The execution of a register-reference instruction is completed at
time T3. The sequence counter SC is cleared to 0 and the control goes back to fetch the next
instruction with timing signal T0.
In the hardwired organization, the control logic is implemented with gates, flip-flops, decoders,
and other digital circuits. It has the advantage that it can be optimized to produce a fast mode of
operation. In the microprogrammed organization, the control information is stored in a control
memory. The control memory is programmed to initiate the required sequence of microoperations.
A hardwired control, as the name implies, requires changes in the wiring among the various
components if the design has to be modified or changed.
In the microprogrammed control, any required changes or modifications can be done by updating
the microprogram in control memory.
Instruction Cycle
A program residing in the memory unit of a computer consists of a sequence of instructions. These
instructions are executed by the processor by going through a cycle for each instruction.
T0: AR ← PC
T1: IR ← M[AR], PC ← PC + 1
T2: D0, .... , D7 ← Decode IR(12-14), AR ← IR(0-11), I ← IR(15)
Since only AR is connected to the address inputs of memory, it is necessary to transfer the
address from PC to AR during the clock transition associated with timing signal T0. The instruction
read from memory is then placed in the instruction register IR with the clock transition associated
with timing signal T1.
At the same time, PC is incremented by one to prepare it for the address of the next instruction in the
program. At time T2, the operation code in IR is decoded, the indirect bit is transferred to flip-flop I,
and the address part of the instruction is transferred to AR. Note that SC is incremented after each
clock pulse to produce the sequence T0, T1, and T2. Figure above shows how the first two register
transfer statements are implemented in the bus system. To provide the data path for the transfer of
PC to AR we must apply timing signal T0 to achieve the following connection:
1. Place the content of PC onto the bus by making the bus selection inputs
S2S1S0 equal to 010.
2. Transfer the content of the bus to AR by enabling the LD input of AR .
The next clock transition initiates the read and increment operations since T1 = 1. Figure
above duplicates a portion of the bus system and shows how T0 and T1 are connected to the control
inputs of the registers, the memory, and the bus selection inputs. Multiple input OR gates are
included in the diagram because there are other control functions that will initiate similar operations.
If D7 = 0, the operation code must be one of the other seven values 000 through 110, specifying a
memory-reference instruction. Control then inspects the value of the first bit of the instruction,
which is now available in flip-flop I. If D7 = 0 and I = 1, we have a memory reference instruction
with an indirect address.
The three instruction types are subdivided into four separate paths. The selected operation is
activated with the clock transition associated with timing signal T3. This can be symbolized as
follows:
The input register INPR consists of eight bits and holds an alphanumeric input information.
The 1-bit input flag FGI is a control flip-flop. 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.
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. Initially, the input flag FGI is cleared to
0. When a key is struck in the keyboard, an 8-bit alphanumeric code is shifted into INPR and the
input flag FGI is set to 1. As long as the flag is set, the information in INPR cannot be changed by
striking another key. The computer checks the flag bit; if it is 1, the information from INPR is
transferred in parallel into AC and FGI is cleared to 0. Once the flag is cleared, new information can
be shifted into INPR by striking another key.
Program Interrupt
The computer keeps checking the flag bit, and when it finds it set, it initiates an information
transfer. The difference of information flow rate between the computer and that of the input—
output device makes this type of transfer inefficient. An alternative to the programmed controlled
procedure is to let the external device inform the computer when it is ready for the transfer. In the
meantime the computer can be busy with other tasks. This type of transfer uses the interrupt facility.
While the computer is running a program, it does not check the flags. When a flag is set, the
computer is momentarily interrupted from the current program. The computer deviates momentarily
from what it is doing to perform of the input or output transfer. It then returns to the current
program to continue what it was doing before the interrupt.
The interrupt enable flip-flop IEN can be set and cleared with two instructions. When IEN is
cleared to 0 (with the IOF instruction), the flags cannot interrupt the computer. When IEN is set to
(with the ION instruction), the computer can be interrupted. The way that the interrupt is handled
by the computer can be explained by means of the flowchart.
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 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.
Dr. M. Kalpana Devi, Assoc. Professor, SITAMS 119
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES.
(AUTONOMOUS)
MCA DEPARTMENT
LECTURE NOTES
Computer Organization and Architecture
Interrupt cycle
The interrupt cycle is a hardware implementation of a branch and save return address
operation. The return address available in PC is stored in a specific location. This location may be a
processor register, a memory stack, or a specific memory location. An example that shows what
happens during the interrupt cycle is shown in the following Figure.
When an interrupt occurs and R is set to 1 while the control is executing the instruction at
address 255. At this time, the returns 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. This is shown in Figure(a). When control reaches timing signal T0and
finds that R = 1, it proceeds with the interrupt cycle. The content of PC (256) is stored in memory
location 0, PC is set to 1, and R is cleared to 0. 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. This is shown in Figure(b).
Microprogram control unit: A control unit whose binary control variables are stored in memory is
called a microprogram control unit.
The control word in control memory contains a microinstruction.
The microinstruction specifies one or more micro-operations for the system.
A sequence of microinstructions constitutes a microprogram.
The control unit consists of control memory used to store the microprogram.
Control memory is a permanent i.e., read only memory (ROM).
The general configuration of a micro-programmed control unit organization is shown as
block diagram below.
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.
The microinstruction format for the control memory is shown in below figure.
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:
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.
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.
The first multiplexer selects an address from one of four sources and routes it into
control address register CAR.
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 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
EXAMPLE:
To perform the operation R3 = R1+R2 We have to provide following binary selection
variable to the select inputs.
1. SEL A : 001 -To place the contents of R1 into bus A.
2. SEL B : 010 - to place the contents of R2 into bus B
3. SEL OPR : 10010 – to perform the arithmetic addition A+B
4. SEL REG or SEL D : 011 – to place the result available on output bus in R3.
CONTROL WORD?
The combined value of a binary selection inputs specifies the control word.
It consist of four fields SELA, SELB,and SELD or SELREG contains three bit each and
SELOPR field contains four bits thus the total bits in the control word are 13-bits.
Control Word For Operation R2 = R1+r3
1. Stack Organization:
Stack: A stack is a storage device that stores information in such a manner that the
item stored last is the first item retrieved.
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:
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.
PC is used during the fetch phase to read an instruction.
AR is used during the exec phase to read an operand.
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
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.
Instruction Formats:
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:
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
Zero Address Instructions:
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).
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.
The following table shows the recommended assembly language convention and actual
transfer accomplished in each case
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.
RISC Characteristics:
Relatively few instructions
Relatively few addressing modes
Memory access limited to load and store instructions
All operations done within the registers of the CPU
Fixed-length, easily decoded instruction format
Single-cycle instruction execution
Hardwired rather than microprogrammed control
A relatively large number of registers in the processor unit
Efficient instruction pipeline
CISC Characteristics:
A large number of instructions--typically from 100 to 250 instructions.
Some instructions that perform specialized tasks and are used infrequently.
A large variety of addressing modes—typically from 5 to 20 differ modes.
Variable-length instruction formats
Instructions that manipulate operands in memory
Microprogram control unit: A control unit whose binary control variables are stored in memory is
called a microprogram control unit.
The control word in control memory contains a microinstruction.
The microinstruction specifies one or more micro-operations for the system.
A sequence of microinstructions constitutes a microprogram.
The control unit consists of control memory used to store the microprogram.
Control memory is a permanent i.e., read only memory (ROM).
The general configuration of a micro-programmed control unit organization is shown as
block diagram below.
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.
The microinstruction format for the control memory is shown in below figure.
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:
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.
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.
The first multiplexer selects an address from one of four sources and routes it into
control address register CAR.
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 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
EXAMPLE:
To perform the operation R3 = R1+R2 We have to provide following binary selection
variable to the select inputs.
1. SEL A : 001 -To place the contents of R1 into bus A.
2. SEL B : 010 - to place the contents of R2 into bus B
3. SEL OPR : 10010 – to perform the arithmetic addition A+B
4. SEL REG or SEL D : 011 – to place the result available on output bus in R3.
CONTROL WORD?
The combined value of a binary selection inputs specifies the control word.
It consist of four fields SELA, SELB,and SELD or SELREG contains three bit each and
SELOPR field contains four bits thus the total bits in the control word are 13-bits.
Control Word For Operation R2 = R1+r3
2. Stack Organization:
Stack: A stack is a storage device that stores information in such a manner that the
item stored last is the first item retrieved.
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:
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.
PC is used during the fetch phase to read an instruction.
AR is used during the exec phase to read an operand.
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
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.
Instruction Formats:
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:
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
Zero Address Instructions:
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).
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.
The following table shows the recommended assembly language convention and actual
transfer accomplished in each case
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.
RISC Characteristics:
Relatively few instructions
Relatively few addressing modes
Memory access limited to load and store instructions
All operations done within the registers of the CPU
Fixed-length, easily decoded instruction format
Single-cycle instruction execution
Hardwired rather than microprogrammed control
A relatively large number of registers in the processor unit
Efficient instruction pipeline
CISC Characteristics:
A large number of instructions--typically from 100 to 250 instructions.
Some instructions that perform specialized tasks and are used infrequently.
A large variety of addressing modes—typically from 5 to 20 differ modes.
Variable-length instruction formats
Instructions that manipulate operands in memory
With the above structure a READ or WRITE may involve an entire memory word or it may
involve only a byte.
Register:
This is a part of Central Processor Unit, so they reside inside the CPU.
The information from main memory is brought to CPU and keep the information in register.
Due to space and cost constraints, we have got a limited number of registers in a CPU.
These are basically faster devices.
Cache Memory:
Cache memory is a storage device placed in between CPU and main memory.
These are semiconductor memories.
These are basically fast memory device, faster than main memory.
We can not have a big volume of cache memory due to its higher cost and some constraints
of the CPU.
Due to higher cost we can not replace the whole main memory by faster memory.
Generally, the most recently used information is kept in the cache memory.
Memory chips are usually organized in the form of an array of cells, in which each cell is
capable of storing one bit of information.
A row of cells constitutes a memory word, and the cells of a row are connected to a common
line referred to as the word line, and this line is driven by the address decoder on the chip.
The cells in each column are connected to a sense/write circuit by two lines known as bit
lines.
The sense/write circuits are connected to the data input/output lines of the chip.
During a READ operation, the Sense/Write circuits sense, or read, the information stored in
the cells selected by a word line and transmit this information to the output lines.
During a write operation, they receive input information and store it in the cells of the
selected word.
A memory cell is capable of storing 1-bit of information. A number of memory cells are
organized in the form of a matrix to form the memory chip. One such internal organization of
memory chip is shown in the Figure.
Each row of cells constitutes a memory word, and all cell of a row are connected to a
common line which is referred as word line.
An address decoder is used to drive the word line.
At a particular instant, one word line is enabled depending on the address present in the
address bus.
The cells in each column are connected by two lines. These are known as bit lines.
These bit lines are connected to data input line and data output line through a Sense/ Write
circuit.
During a Read operation, the Sense/Write circuit sense, or read the information stored in the
cells selected by a word line and transmit this information to the output data line.
During a write operation, the sense/write circuit receive information and store it in the cells of
the selected word
The data input and data output line of each Sense/Write circuit are connected to a single
bidirectional data line in order to reduce the pin required.
For 16 words, we need an address bus of size 4. In addition to address and data lines, two
control lines, R/W and CS, are provided.
The line is to used to specify the required operation about read or write.
The CS (Chip Select) line is required to select a given chip in a multi chip memory system.
The following figure shows such an organization of a memory chip consisting of 16 words of
8 bits each, which is usually referred to as a 16 x 8 organization.
The data input and the data output of each Sense/Write circuit are connected to a single bi-
directional data line in order to reduce the number of pins required.
Depending on the technology used to construct a RAM, there are two types of RAM –
1. SRAM: Static Random Access Memory.
2. DRAM: Dynamic Random Access Memory.
Static RAM (SRAM):
In an SRAM, binary values are stored using traditional flip-flop constructed with the help of
transistors.
A static RAM will hold its data as long as power is supplied to it.
A typical SRAM constructed with transistors is shown in the figure.
For the write operation, a voltage signal is applied to the bit line, a high voltage represents 1
and a low voltage represents 0.
A signal is then applied to the address line, which will turn on the transistor T, allowing a
charge to be transferred to the capacitor.
For the read operation, when a signal is applied to the address line, the transistor T turns on
and the charge stored on the capacitor is fed out onto the bit line.
The cells are organized in the form of a square array such that the high-and lower-order 8 bits
of the 16-bit address constitute the row and column addresses of a cell, respectively.
In order to reduce the number of pins needed for external connections, the row and column
address are multiplexed on 8 pins.
To access a cell, the row address is applied first.
It is loaded into the row address latch in response to a single pulse on the Row Address
Strobe (RAS) input.
This selects a row of cells.
Now, the column address is applied to the address pins and is loaded into the column address
latch under the control of the Column Address Strobe (CAS) input and this address selects
the appropriate sense/write circuit.
If the R/W signal indicates a Read operation, the output of the selected circuit is transferred
to the data output. Do.
For a write operation, the data on the DI line is used to overwrite the cell selected.
Synchronous DRAM
Most recent developments in memory technology has resulted in DRAMs whose operation is
directly synchronized with a clock signal. Such memories known as Synchronous DRAMs.
Cell array is same as Asynchronous DRAM.
ROM Cell
Cache Memory
Analysis of large number of programs has shown that a number of instructions are executed
repeatedly.
This may be in the form of a simple loops, nested loops, or a few procedures that repeatedly
call each other.
It is observed that many instructions in each of a few localized areas of the program are
repeatedly executed, while the remainder of the program is accessed relatively less.
This phenomenon is referred to as locality of reference.
Now, if it can be arranged to have the active segments of a program in a fast memory, then
the total execution time can be significantly reduced.
It is the fact that CPU is a faster device and memory is a relatively slower device. Memory
access is the main bottleneck for the performance efficiency.
If a faster memory device can be inserted between main memory and CPU, the efficiency can
be increased.
The faster memory that is inserted between CPU and Main Memory is termed as Cache
memory.
The memory control circuitry is designed to take advantage of the property of locality of
reference.
Some assumptions are made while designing the memory control circuitry:
1. The CPU does not need to know explicitly about the existence of the cache.
2. The CPU simply makes Read and Write request. The nature of these two
operations are same whether cache is present or not.
3. The address generated by the CPU always refer to location of main memory.
4. The memory access control circuitry determines whether or not the requested
word currently exists in the cache.
When a Read request is received from the CPU, the contents of a block of memory words
containing the location specified are transferred into the cache.
When any of the locations in this block is referenced by the program, its contents are read
directly from the cache.
The cache memory can store a number of such blocks at any given time.
Mapping Functions
The mapping functions are used to map a particular block of main memory to a particular
block of cache.
This mapping function is used to transfer the block from main memory to cache memory.
Three different mapping functions are available:
1. Direct mapping:
2. Associative mapping:
3. Set-associative mapping:
Direct Mapping Technique:
The simplest way of associating main memory blocks with cache block is the direct mapping
technique.
In this technique, block k of main memory maps into block k modulo m of the cache, where
m is the total number of blocks in cache.
In this example, the value of m is 128.
In direct mapping technique, one particular block of main memory can be transferred to a
particular block of cache which is derived by the modulo function.
Thus, whenever one of the main memory blocks 0, 128, 256,… is loaded in the cache, it is
stored in cache block 0. Blocks 1, 129, 257,… are stored in cache block 1, and so on.
Since more than one main memory block is mapped onto a given cache block position,
contention may arise for that position.
This situation may occurs even when the cache is not full.
Contention is resolved by allowing the new block to overwrite the currently resident block.
So the replacement algorithm is trivial. The detail operation of direct mapping technique is as
follows:
In the associative mapping, any block of main memory can go to any block of cache, so it has
got the complete flexibility and we have to use proper replacement policy to replace a block
from cache if the currently accessed block of main memory is not present in cache.
It might not be practical to use this complete flexibility of associative mapping technique due
to searching overhead, because the TAG field of main memory address has to be compared
with the TAG field of all the cache block.
In this example, there are 128 blocks in cache and the size of TAG is 11 bits.
Set-Associative Mapping Technique:
A combination of the direct- and associative mapping techniques can be used.
Blocks of the cache are grouped into sets, and the mapping allows a block of main memory to
reside in any block of a specific set.
Therefore, the flexibility of associative mapping is reduced from full freedom to a set of
specific blocks.
Replacement Algorithms
When a new block must be brought into the cache and all the positions that it may occupy are
full, a decision must be made as to which of the old blocks is to be overwritten.
In general, a policy is required to keep the block in cache when they are likely to be
referenced in near future.
However, it is not easy to determine directly which of the block in the cache are about to be
referenced.
The property of locality of reference gives some clue to design good replacement policy.
Least Recently Used (LRU) Replacement policy:
When a block is to be overwritten, it is a good decision to overwrite the one that has gone for
longest time without being referenced.
This is defined as the least recently used (LRU) block.
For Example:
Consider a specific cache with a four-block set.
It is required to track the LRU block of this four-block set.
A 2-bit counter may be used for each block.
When a hit occurs, that is, when a read request is received for a word that is in the cache, the
counter of the block that is referenced is set to 0.
All counters which values originally lower than the referenced one are incremented by 1 and
all other counters remain unchanged.
When a miss occurs, that is, when a read request is received for a word and the word is not
present in the cache, we have to bring the block to cache.
There are two possibilities
In case of a miss: If the set is not full, the counter associated with the new
block loaded from the main memory is set to 0, and the values of all other
counters are incremented by 1.
If the set is full and a miss occurs, the block with the counter value 3 is
removed , and the new block is put in its place.
The counter value is set to zero. The other three block counters are incremented by 1.
It is easy to verify that the counter values of occupied blocks are always distinct.
Also it is trivial that highest counter value indicates least recently used block.
Interestingly enough, this simple algorithm has been found to be very effective in practice.
Other than set bits, tag bits there is a control bits Valid Bit and Dirty Bit provided for each
block.
Valid bit indicates whether the block contains valid data or not.
Dirty bit indicates whether the block has been modified during its cache residency.
Valid bits all set to 0, when power is initially applied to the system or when main memory is
loaded with new programs and data from the disk.
Transfers from the disk to main memory is carried out by DMA mechanism.
The valid bit of a particular cache block is set to 1,the first time this block is loaded from the
main memory.
Performance Considerations
Two key factors in the commercial success of a computer are performance and cost; the best
possible performance at the lowest cost is the objective.
The challenge in considering design alternatives is to improve the performance without
increasing the cost.
A common measure of success is the price/performance ratio
Virtual Memory
Paging is a method of writing and reading data from a secondary storage(Drive) for
use in primary storage(RAM). When a computer runs out of RAM, the operating system (OS)
will move pages of memory over to the computer’s hard disk to free up RAM for other
processes. This ensures that the operating system will never run out of memory and crash.
Too much reliance on memory paging can impair performance, however, because RAM
Demand paging also allows us to accommodate more process in the main memory,
since we are not going to load the whole process in the main memory. Pages will be brought
into the main memory as and when it is required. This concept leads us to an important
consequence – It is possible for a process to be larger than the size of main memory. So,
while developing a new process, it is not required to look for the main memory available in
the machine. Because, the process will be divided into pages and pages will be brought to
memory on demand. Because a process executes only in main memory, so the main memory
is referred to as real memory or physical memory. A programmer or user perceives a much
larger memory that is allocated on the disk. This memory is referred to as virtual memory.
The program enjoys a huge virtual memory space to develop his or her program or
software. The execution of a program is the job of operating system and the underlying
hardware. To improve the performance some special hardware is added to the system. This
hardware unit is known as Memory Management Unit (MMU). In paging system, we make
a page table for the process. Page table helps us to find the physical address from virtual
address. The virtual address space is used to develop a process. The special hardware unit ,
called Memory Management Unit (MMU) translates virtual address to physical address.
When the desired data is in the main memory, the CPU can work with these data. If the data
are not in the main memory, the MMU causes the operating system to bring into the memory
from the disk.
Address Translation
The basic mechanism for reading a word from memory involves the translation of a
virtual or logical address, consisting of page number and offset, into a physical address,
consisting of frame number and offset, using a page table. There is one page table for each
process. But each process can occupy huge amount of virtual memory. But the virtual
memory of a process cannot go beyond a certain limit which is restricted by the underlying
hardware of the MMU. One of such component may be the size of the virtual address
register. The sizes of pages are relatively small and so the size of page table increases as the
size of process increases. Therefore, size of page table could be unacceptably high. To
overcome this problem, most virtual memory scheme store page table in virtual memory
rather than in real memory. When a process is running, at least a part of its page table must be
in main memory, including the page table entry of the currently executing page.
Each virtual address generated by the processor is interpreted as virtual page number (high
order list) followed by an offset (lower order bits) that specifies the location of a particular
word within a page. Information about the main memory location of each page kept in a page
table.
Given a virtual address, the MMU looks in the TLB for the reference page. If the page
table entry for this page is found in the TLB, the physical address is obtained immediately. If
there is a miss in the TLB, then the required entry is obtained from the page table in the main
memory and the TLB is updated. When a program generates an access request to a page that
is not in the main memory, a page fault is said to have occurred. The whole page must be
brought from the disk into the memory before access can proceed. When it detects a page
fault, the MMU asks the operating system to intervene by raising an exception. (interrupt).
Processing of active task is interrupted, and control is transferred to the operating system.
The operating system then copies the requested page from the disk into the main memory and
returns control to the interrupted task. Because a long delay occurs due to a page transfer
takes place, the operating system may suspend execution of the task that caused the page fault
and begin execution of another task whose page are in the main memory.