MCS-202 Computer Organization
MCS-202 Computer Organization
MCS-202 Computer Organization
2.0 INTRODUCTION
In the first Unit of this Block, you have learnt the concepts relating to different
architectures of a Computer System. It also explains the process of execution of an
instruction highlighting the use of various components of a Computer system. This
Unit explains about how the data is represented in a computer system.
The Unit first defines the concepts of number systems in brief, which is followed by
discussion on conversion of numbers of different number systems. An important
concept of signed complement notation, which is used for arithmetic operations on
binary numbers, has been explained in this Unit. This is followed by discussion on the
fixed point and floating point numbers, which are used to represent the numerical data
in computer systems. This Unit also explains the error detection and correction codes
and introduces you to basics of computer arithmetic operations.
2.1 OBJECTIVES
At the end of the unit you will be able to:
27
Introduction to Digital A computer performs three basic operation on data, viz. data input, processing and
Circuits
data output. The data input and information output, in general, is presented in text,
graphics, audio or other human recognizable form. Therefore, all human readable
characters, graphics, audio and video should be coded using bits such that computer is
able to interpret them. The most common code to represents characters into computer
are ASCII and UNICODE. Pictures and graphs can be represented using pixel (picture
elements), digital sound and video are represented by coding the frames in digital
formats. Since graphics, digital audio and digital video, which are stored on storage
devices as files, are very large in size, therefore, a large number of storage formats
that use data compression techniques are used for represent digital information. Some
of these concepts are explained in Unit 8.
The numeric data is used for computation in computer. However, as computer is an
electronic device, it can only process binary data. Thus, in general, numeric data is to
be converted to binary for computation. Computer uses fixed point and floating point
representation for representing numeric data. Data in computer is stored in random
access memory (RAM) and is required to be transferred in or out of the RAM for the
purpose of processing, therefore, an error detection mechanism may be employed to
identify and correct simple errors while transfer of binary data. The subsequent
sections of the Unit explains the character representation, representation of binary
numbers and error detection mechanism.
28
new standard that could represent almost all the characters of all the languages was Data Representation
developed. This is called the UNICODE.
Unicode
Unicode is a standard for character representation, which provides a unique code also
called code point, for every character of almost all the languages of the world. The set
of all the codes is called code space. The code space is divided into 17 continuous
sequences of codes called code planes, with each code plane can represent 216 codes.
Thus, Unicode values ranges from U+000016 to U+10FFFF16. Here U+ represents the
Unicode followed by the hexadecimal value of a code point. The code planes of the
Unicode being U+0000016 to U+0FFFF16; U+1000016 to U+1FFFF16; U+2000016 to
U+2FFFF16; … , U+F000016 to U+FFFFF16; and U+10000016 to U+10FFFF16. You can
learn about more details on Unicode from the further readings. Also read the
hexadecimal number system given in the next section to learn about the hexadecimal
values given above.
One of the major advantages of using Unicode is that it helps in seamless digital data
transfer among the applications that use this character formatting, thus, not causing
any compatibility problem.
Unicode code points may consist of about 24 binary digits, however, all of these code
points may not be required for a given set of data. In addition, a digital system
requires the data in the units of bytes. Thus, a number of encodings has been designed
to represent Unicode code points in a digital format. Two of these popular encodings -
Unicode Transformation Formats are UTF-8 and UTF-16. UTF-8 uses 1 to 4 bytes to
represent the code points of Unicode. Most of the 1 byte UTF-8 code points are
compatible to ASCII. UTF-16 represents code points as one or two 16-bit code units.
The standard ISO 10646 represents various Unicode coding formats.
In general, if you are working with web pages having mostly English language, UTF-
8 may be a good choice of character representation. However, if you are creating a
multi-lingual web page, it may be a good idea to use UTF-16.
Indian Standard Code for information interchange (ISCII)
The ISCII is and ASCII compatible code consisting of eight-bits. The code for values
0 to 127 in ISCII is similar to ASCII; however, for the values 128 to 225 it represents
the characters of Indian scripts. IS 13194:1991 BIS standard defines the details of
ISCII. However, with the popularity of Unicode, its use has now been limited.
Binary Numbers: A binary number system has a base 2 and consists of only two
digits 0 and 1, which are also called the bits. For example, 10012 represent a binary
number with four binary digits. The subscript 2 represents that the number 1001 has a
base 2 or in other words is a binary number.
29
Introduction to Digital Note: The subscript shown in the numbers represents the base of the number. In case a
Circuits
subscript is not given then please assume it as per the context of discussion.
Conversion of binary number to Decimal equivalent:
A binary number is converted to its decimal equivalent by multiplying each binary
digit by its place value. For example, a seven digit binary number 10010012 can be
converted to decimal equivalent value as follows:
Binary Digits of Number 1 0 0 1 0 0 1
The place value 26 25 24 23 22 21 20
=64 =32 =16 =8 =4 =2 =1
Binary digit × Place value 1×64 0×32 0×16 1×8 0×4 0×2 1×1
Computed values 64 0 0 8 0 0 1
Sum of the computed values 64+0+0+8+0+0+1 = 73 in Decimal
You may now try converting few more numbers. Try 0010001, which will be
16+1=17; 1111111 will be 64+32+16+8+4+2+1=127. So a 7 bit binary number can
contain decimal values from 0 to 127.
Octal Numbers: An Octal number system has a base of 8, therefore, it has eight
digits, which are 0,1,2,3,4,5,6,7. For example, 765432108 is an octal number.
Conversion of Octal number to Decimal equivalent:
An Octal number is converted to its decimal equivalent by multiplying each octal digit
by its place value. For example, an octal number 54328 can be converted to decimal
equivalent value as follows:
Octal Digits of Number 5 4 3 2
The place value 83 82 81 80
=512 =64 =8 =1
Octal digit × Place value 5×512 4×64 3×8 2×1
Computed values 2560 256 24 2
Sum of the computed values 2560+256+24+2=284210
30
For Factional part: Repetitively multiply the fraction by 2 and maintain the list of Data Representation
integer value that is obtained till fraction becomes 0. Collect all the integer values.
The following example explains the process of Decimal to binary conversion.
Example 1: Convert the decimal number 22.25 to binary number.
Solution:
For Integer part: Repetitively divide the For Factional part: Repetitively
quotient of integer part by 2 keeping multiply the fraction by 2 and
remainder separate till quotient is 0. maintain the list of integer value that
Integer value of example: 22 is obtained till fraction becomes 0.
Fraction value of example:.25
Integer After Division by 2 Direction Fraction After Direction
Part of Reading Part multiplication of
the by 2 Reading
Result the
Quotient Remainder Result Integer Result
part
22 11 0 .25 0.50 0
11 5 1 .50 1.00 1
2 1 0
1 0 1
0 STOP Ans:
10110
Verification
Place values 64 32 16 8 4 2 1
N=39 1
New N=7 1 1
New N=3 1 1 1
New N=1 1 1 1 1
Step 4 0 1 0 0 1 1 1
Place values 64 32 16 8 4 2 1
N=20 1
New N=4 1 1
Step 4 0 0 1 0 1 0 0
The logic as presented here can be extended to the fractional part, however, it is
recommended that you may follow the repeated multiplication method as explained
earlier for the fractions.
Conversion of Binary number to Octal Number
The base of a binary number is 2 and the base of octal number is 8. Interestingly,
23=8. Thus, if you simply group three binary digits, the equivalent value may form
the octal digit. However, you may be wondering how to group binary numbers. This is
explained with the help of following example.
Example 3: Convert the binary 11001101.001112 into equivalent Octal number.
Process: The process is to group three binary digits. The grouping before the binary
point is done from right to left and after the binary point from left tonright. Each of
the group then is converted to equivalent octal digit. The following table shows this
conversion process.
Binary Number - 1 1 0 0 1 1 0 1 . 0 0 1 1 1 -
Grouping Directions .
Grouped (- replaced by 0 1 1 0 0 1 1 0 1 . 0 0 1 1 1 0
0)
Binary place values 4 2 1 4 2 1 4 2 1 . 4 2 1 4 2 1
Equivalent Octal Digit 0+2+1=3 0+0+1=1 4+0+1=5 . 0+0+1=1 4+2+0=6
Octal Number 3 1 5 . 1 6
Therefore, 11001101.001112 is equivalent to 315.168
32
Conversion of Binary number to Hexadecimal Number Data Representation
The base of a binary number is 2 and the base of hexadecimal number is 16. You may
notice that 24=16. Therefore, conversion of binary to hexadecimal notation may
require grouping of 4 binary digits. This is explained with the help of following
example.
Example 4: Convert the binary 11001101.001112 into equivalent hexadecimal
number.
Process: The process is almost similar to binary number to octal number conversion
expect now four binary digits are combined as given in the following table.
Binary Number 1 1 0 0 1 1 0 1 . 0 0 1 1 1 - - -
Grouping Direction .
Grouped 1 1 0 0 1 1 0 1 . 0 0 1 1 1 0 0 0
Binary place values 8 4 2 1 8 4 2 1 . 8 4 2 1 8 4 2 1
Hexadecimal digit 8+4+0+0=12 8+4+0+1=13 . 0+0+2+1=3 8+0+0+0=8
Hexadecimal 12 is C 13 is D . 3 8
33
Introduction to Digital Please note the following points in the Table 1 given above.
Circuits
The Binary coded decimal (BCD) is the representation of each decimal digit
to a sequence of 4 bits. For example, a decimal number 12 in BCD is 0001
0010. This representation is used in several calculators for performing
computation.
It may be noted that BCD is not binary equivalent value. For example, the
BCD value of decimal 49 is 0100 1001 but its binary equivalent value is 0011
0001.
Please also note that binary coded hexadecimal values are equivalent to binary
value of a number. For example, decimal value 63 in hexadecimal binary
notation is 0011 1111, which is same as its binary value.
The conversion of decimal to octal and hexadecimal may be performed in the same
way as done using repeated division or multiplication of binary. The process is exactly
same except, in decimal number to octal or hexadecimal number conversion division
is done by 8 or 16 respectively.
Check Your Progress 1
1) Perform the following conversions:
i) 11100.011012 to Octal and Hexadecimal
ii) 11011010102 to Octal and Hexadecimal
.........................................................................................................................................
.........................................................................................................................................
.........................................................................................................................................
34
Data Representation
2.5 NEGATIVE NUMBER REPRESENTATION
USING COMPLEMENTS
You have gone through the details of binary representation of character data and the
number systems. In general, you use positive and negative integers and real numbers
for computation. How these numbers can be represented in binary? This section
describes how positive and negative numbers can be represented in binary for
performing arithmetic operations.
In general, Integer numbers can be represented using the sign and magnitude of the
number, whereas real numbers may be represented using a sign, decimal point and
magnitude of integral and fractional part. Real numbers can also be represented using
a scientific exponential notation. This section explains how integers can be
represented as binary numbers in a computer system.
Integer representation in binary:
An integer is represented in binary using fixed number of binary digits. One of the
simplest representations for representing integer would be - to represent the sign using
a bit; and magnitude may be represented by the remaining bits. Fortunately, the value
of sign can be either positive or negative, therefore, it can easily be represented in
binary. The + sign can be represented using 0 and – sign can be represented using 1.
For example, a decimal number 73 has a sign + (bit value 0) and magnitude 73 (binary
equivalent 1001001). The following table shows some of the numbers using this Sign-
magnitude Representation:
35
Introduction to Digital Is there any better representation? Yes, an interesting representation that uses
Circuits
complement of a number to represent negative numbers has been designed. What is a
complement of a number?
Complement notation: A complement, by definition, is a number that makes a given
number complete. For the decimal numbers, this completeness can be defined with
respect to the highest value of the digit, i.e. 9 or the next higher value, i.e. 10. These
are called 9’s and 10’s complement respectively for the decimal numbers.
For example, for a decimal digit 3, the 9’s complement would be 9-3 =6 and 10’s
complement would be 10-3=7.
In general, for a number with base B two types of complements are defined –(B-1)’s
complement and B’s complement. For example, for decimal system base value B is10.
Therefore, for decimal numbers two complements, viz. 9’s and 10’s complements, are
defined. Thus, for binary system where base is 2, the two complements, viz. 1’s
complement and 2’s complement, are defined. The following example illustrates the
steps of finding 9’s and 10’s complement for decimal numbers.
Example 5: Compute the 9’s complement and 10’s complement for a four digit
decimal number 1095, 8567 and 0560.
Solution: Following table shows the process:
Complement Operation The Number
Number 1 0 9 5
9’s Complement
Subtract each digit from 9 8 9 0 4
Add 1 in the 9’s complement - - - 1
10’s Complement
It results in 10’s complement 8 9 0 5
Number 8 5 6 7
9’s Complement
Subtract each digit from 9 1 4 3 2
Add 1 in the 9’s complement - - - 1
10’s Complement
It results in 10’s complement 1 4 3 3
Number 0 5 6 0
9’s Complement
Subtract each digit from 9 9 4 3 9
Add 1 in the 9’s complement - - - 1
10’s Complement
It results in 10’s complement 9 4 4 0
An interesting observation from the Table 4 is that 1’s complement can be obtained
simply by changing 1 to 0 and 0 to 1. For obtaining 2’s complement leave all the
trailing zeros and the first 1 intact and after that complement the remaining bits. For
example, for an eight bit binary number 10101100, the complement can be done as
follows:
Number 1 0 1 0 1 1 0 0
1’s Complement change every bit from 0 to 1 OR 1 to 0 0 1 0 1 0 0 1 1
Number 1 0 1 0 1 1 0 0
For 2’s complement leave the trailing 0’s till first 1 1 0 0
then complement remaining bits(change 0 to 1 or 1 to 0) 0 1 0 1 0
2’s Complement of the Number 0 1 0 1 0 1 0 0
Solution: The table 6 shows the values in signed 1's complement notation of length 8
bits (S is the sign bit). Please note that even in signed 1's complement notation there
are two representations for 0. The number range for 1's complement for this 8 bit
representation is -127 to -0 and +0 to +127. So it can represent 28-1 (as two
representation of 0) =255 numbers.
Number Process S 7 bits
Sign is 0 (positive) and 7 bit magnitude is
+73 0 1 0 0 1 0 0 1
same as binary equivalent value of 73
Take 1's complement of all the 8 bits
-73 1 0 1 1 0 1 1 0
(including sign bit) to obtain -73
+39 Follow same process as stated for +73 0 0 1 0 0 1 1 1
-39 Follow same process as stated for -73 1 1 0 1 1 0 0 0
+127 Follow same process as stated for +73 0 1 1 1 1 1 1 1
-127 Follow same process as stated for -73 1 0 0 0 0 0 0 0
0 Follow same process as stated for +73 0 0 0 0 0 0 0 0
-0 Follow same process as stated for -73 1 1 1 1 1 1 1 1
Solution: The table 7 shows the values in signed 2's complement notation of length 8
bits (S is the sign bit). Please note that in signed 2's complement notation there is a
unique representations for 0, therefore, -128 can also be represented. Thus, the range
of the number that can be represented using signed 2's complement notation is -128 to
+127. Thus, a total of 256 numbers can be represented using signed 2's complement
notation.
Number Process S 7 bits
Sign is 0 (positive) and 7 bit magnitude is
+73 0 1 0 0 1 0 0 1
same as binary equivalent value of 73
Take 2's complement of the number
-73 1 0 1 1 0 1 1 1
(including sign bit) to obtain -73
+39 Follow same process as stated for +73 0 0 1 0 0 1 1 1
-39 Follow same process as stated for -73 1 1 0 1 1 0 0 1
+127 Follow same process as stated for +73 0 1 1 1 1 1 1 1
-127 Follow same process as stated for -73 1 0 0 0 0 0 0 1
0 Follow same process as stated for +73 0 0 0 0 0 0 0 0
-0 Follow same process as stated for -73 0 0 0 0 0 0 0 0
-128 -127-1 is = -128 1 0 0 0 0 0 0 0
Example 9: Add the decimal numbers 75 and -80 using signed magnitude notation,
assuming the 8-bit length of the notations.
Solution: The numbers are (The left most bit is the Sign bit):
Num
Signed Magnitude Signed 1's Complement Signed 2's Complement
ber
+75 0 1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 1 1
+80 0 1 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 0 0 0
-80 1 1 0 1 0 0 0 0 1 0 1 0 1 1 1 1 1 0 1 1 0 0 0 0
Table 10: 8-bit addition using Signed magnitude notation having overflow
The addition of 7 bit magnitude has resulted in 8 bit output, which cannot be stored in
this notation as this notation has a length of 8 bits with 1 sign bit. The last bit will be
lost and you will obtain an incorrect result -27. This problem has occurred as the size
of the number is fixed. This is called the overflow. You may please note that the
actual addition of the 75 and 80 is 155, which is beyond the range of 8 bit signed
magnitude representation, which is -127 to +127. This is why you should be careful
while selecting the integral data types in a programming languages. For example, in
case you have selected small unsigned integer of byte size for a variable, then you can
store a only the number values in the range 0 to 255 in that variable.
Addition using signed-1's complement notation:
In signed 1's complement notation the addition process is simpler than signed-
magnitude representation. An interesting fact is that in this notation you do not have to
check the sign, just add the numbers, why? This is due to the fact that complement of
a number as defined makes it complete, the binary digits are complement of each
other and even the sign bits are complement. Therefore, the process of addition of two
signed 1's complement notation just requires addition of the two numbers, irrespective
of the sign. The process of addition in signed 1's complement representation will
require the following steps:
Step 1: Just add the numbers, irrespective of sign.
Step 2: Now check the following conditions:
Carry in to Carry out of
Comments
the Sign Bit the Sign bit
No No Result is fine
Yes Yes Add 1 to result and it is fine
No Yes Overflow, incorrect result
Yes No Overflow, incorrect result
Table 11: The conditions of 1's complement notation, while addition
The following example demonstrates the process of addition .
Example 11: Add the decimal numbers 75 and -80 using signed 1's complement
notation, assuming the 8-bit length of the notations.
Solution: The numbers are (The left most bit is the Sign bit). The Table 8 shows the
values of +75 and -80 in signed 1's complement notation.
42
(iii) +69-59 Data Representation
Carry out
Number Signed 2's Complement Notation
(9th bit)
Carry
from Carry in to
previous yes Sign bit No No No yes No yes -
bit yes
addition
Carry
for 1 1 1 1 -
addition
+69 0 1 0 0 0 1 0 1
-59 1 1 0 0 0 1 0 1
Addition
of bits 1+0+1 1+1 0+0 0+0 1+0+0 1+1 1+0+0 1+1
given =10 =10 =0 =0 =1 =10 =1 =10
above
Result 1 0 0 0 0 1 0 1 0
There is a carry in to the sign bit (1) and there is a carry out of the sign bit (1).
Therefore, as per Table 14, there is NO overflow and the result is correct and equal to
+10. Discard the carry out bit (the 9th bit). Verify the result yourself.
Table 18: Addition of smaller negative number and bigger positive numbers. No
overflow is possible.
(iv) +69+59
Carry
out
Number Signed 2's Complement Notation
(9th
bit)
Carry Carry
from in to
previous No Sign yes yes yes yes yes yes -
bit bit
addition yes
Carry
for - 1 1 1 1 1 1 1 -
addition
+69 0 1 0 0 0 1 0 1
+59 0 0 1 1 1 0 1 1
Addition
of bits 1+0+0 1+1+0 1+0+1 1+0+1 1+0+1 1+1+0 1+0+1 1+1
given =1 =10 =10 =10 =10 =10 =10 =10
above
Result - 1 0 0 0 0 0 0 0
There is a carry in to the sign bit (1) but there is NO carry out of the sign bit.
Therefore, as per Table 14, there is an overflow and the result is incorrect. Verify the
result yourself. Overflow has occurred as the addition of the two numbers is +128,
which is out of the range of numbers that can be represented using 8-bit signed 2's
complement notation.
Table 19: Addition of two positive numbers.
It may be noted that for the signed 2’s complement notation, which is using 8 bits
representation, is -128 to +127, which can be checked from table 16 and table 19.
Overflow formally is defined as the situation where the result of operation on two or
more numbers, each of size n digits, exceeds the size n.
43
Introduction to Digital Overflow may cause even your correct programs to output incorrect results, therefore,
Circuits
is a very risky error. One of the ways of avoiding overflow in programs is to select
appropriate data types and verifying the results range.
Arithmetic Subtraction: In general, a computer system uses the signed 2's
complement notation, which simplifies the process of addition and subtraction as well
as has a single representation for 0. You can perform subtraction by just taking the 2's
complement of the number that is to be subtracted, and thereafter just adding the two
numbers just like it has been shown in this section.
Multiplication and division: Multiplication and division operations using signed 2's
complement notations are not straight forward. One of the simplest approach to
multiply two signed 2’s complement numbers is by multiplying the positive numbers
and then adjusting the result based on the sign. However, this approach is time
consuming as well as not used for implementation of multiplication operation. There
are a number of algorithms for performing multiplication and division. One such
algorithm is the Booth’s algorithm. A detailed discussion on these topics is beyond the
scope of this course.
In several arithmetic computations binary representation of decimal number is used
for performing arithmetic operations. The next subsection briefly explains this
representation.
+125 in Binary:
S 7-bit magnitude
- 64 32 16 8 4 2 1
0 1 1 1 1 1 0 1
Why is this representation needed? In several computing devices the computations are
performed on binary coded decimals directly, without conversion to binary. One such
device was old calculator. You may refer to further readings for more details on BCD
arithmetic.
Check Your Progress 2
1) Write the BCD for the following decimal numbers:
i) -23456
ii) 17.89
iii) 299
.........................................................................................................................................
.........................................................................................................................................
44
......................................................................................................................................... Data Representation
.........................................................................................................................................
2) Compute the 1’s and 2’s complement of the following binary numbers. Also
find the decimal equivalent of the number.
i) 1110 0010
ii) 0111 1110
iii) 0000 0000
.........................................................................................................................................
.........................................................................................................................................
.........................................................................................................................................
……………………………………………………………………………………….
3) Add the following decimal numbers by converting them to 8-bit signed 2’s
complement notation.
i) +56 and – 56
ii) +65 and –75
iii) +121 and +8
Identify, if there is overflow.
.........................................................................................................................................
……………….. ..............................................................................................................
…….................................................................................................................................
…………………………………………………………………………………………
Bit Positions
1 2 to 9 10 to 32
from the left 45
Introduction to Digital (a) Basic details
Length of
Circuits 1 bit 8 bits 23 bits
Field
Stores the fractional
To store the Sign
Purpose To store the Exponent Significand of the
bit
Number
The Sign bit is The exponent is The Significand is
Comment for the stored in biased form stored as a normalized
Significand with a bias of 127 binary number
Exponent (8 bits) so Significand values (23 The Number
possible values 0 to 255. Bits) Represented
A bias of 127 is Assume that Significand
assumed. Let the be M, which is 23 bit
exponent be exp long
For Exponent value (exp) All the bits of M are The number is ±0
0 zeros. depending on the sign bit.
For Exponent value (exp) All bits of M are zeros The number is ±∞
255 depending on the sign bit
It does NOT represent a
M is NOT zero. valid Number
(b) Single Precision 32-bit IEEE-754 Standard
Table 20: IEEE 754 Floating Point 32-bit Number Representation
The three terms in Table 20 are fractional Significand, bias and normalized. They are
explained below:
fractional Significand: Floating point number assumes that the position of binary point
is prior to the Significand, therefore, Significand is a fraction (Refer to example 15).
Bias: It is an interesting way to store signed numbers without using any sign bit. It
stores the number by adding a value in the exponent. For example, a 4 bit binary
number can store values 0000 to 1111, i.e. values 0 to 15. A bias of 8 will allow
values -8 to +7 to be stored in this range by adding the bias. In other words exponent
value -8 will be coded as (-8+8) 0, -7 will be coded as (-7+8) 1, and so on till +7,
which will be coded as (+7+8) 15. But, why is biasing used for exponent? The basic
reason here is that biased numbers simplify the floating point arithmetic. This is
explained later with the help of an example.
Normalized: A fraction is called normalized if it starts with a bit value 1 and not with
bit value 0. For example, the values .1001, .1111, .1000, .1010 are normalized, but the
values .0100, .0001, .0010, .0011 are not normalized.
The following example explains the process of converting a decimal real number to a
floating point number representation using IEEE-754 standard (32-bit representation).
You may solve similar problems using double precision representation also, where
only the size of exponent (and bias) and significand is different.
Example 15: Represent the number -29.25 using IEEE 754 (32 bit) representation as
shown in Table 20.
46
Solution: Data Representation
Example 16: A number using IEEE 754 (32 bit) is given below, what is the
equivalent decimal value.
S exp of length 8 bits Significand of length 23 bits (M)
1 1000 1001 111 1000 0000 0000 0000 0000
Solution:
The number is represented as: ±1.M ×2exp-127
The sign bit states it is a negative number
M is 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Exp is 1 0 0 0 1 0 0 1 = 137 in decimal.
The number is -1.11110000000000000000000×2137-127
= -1.11110000000000000000000×210
= -11111000000.0000000000000
= -11111000000
= -1984 in decimal
In floating point numbers a term precision is very important. What is precision? The
precision defines the correctness of representation. For example, suppose you just use
2 decimal digits in a fractional decimal numbers, then you can represent the numbers
0.10, 0.11, 0.99 etc precisely. The number 0.985 may be either truncated to 0.98 or
rounded off to 0.99. This introduces an error in number, which is due to the fact that
the size of Significand is limited. For scientific computations such errors may lead to
failure. Therefore, IEEE-754 defines many different precision of numbers, few such
popular precisions are single precession IEEE-754 number, which is a 32-bit
representation, explained above; IEEE-754 double precision number, which is a 64
47
Introduction to Digital bit representation with 1 sign bit, 11 bit exponent and 52 bit Significand; and IEEE-
Circuits
754 quadruple precision number, which is a 128 bit representation with 1 sign bit, 15
bit exponent and 112 bit Significand. It may be noted that in programming languages
you use data types float and double, which corresponds to the IEEE-754 single and
double representation respectively.
Finally, what is the range of the numbers that can be represented using the IEEE-754
representation? As stated in Table 20, the minimum exponent value for a normalized
number is 1 and maximum is 254. Therefore, the minimum (negative) number will be:
S exp of length 8 bits Significand of length 23 bits (M)
1 0000 0001 000 0000 0000 0000 0000 0000
This will be equal to ±1.M ×2exp-127
= -1.000 0000 0000 0000 0000 0000×21-127
= -1×2-126
The maximum (positive) number will be:
S exp of length 8 bits Significand of length 23 bits (M)
1 1111 1110 111 1111 1111 1111 1111 1111
This will be equal to ±1.M ×2exp-127
= +1.111 1111 1111 1111 1111 1111×2254-127
= +(1.111 1111 1111 1111 1111 1111
+0.000 0000 0000 0000 0000 0001
-0.000 0000 0000 0000 0000 0001) ×2127
= +(10. 000 0000 0000 0000 0000 0000
-0.000 0000 0000 0000 0000 0001) ×2127
= +(2-1×2-23) ×2127
You may please note that IEEE-754 has a representation for 0 and infinite.
Arithmetic Using Floating Point Numbers:
As you have noticed that addition and subtraction using 2’s complement notation was
direct, but addition and subtraction of floating point number requires several steps.
These steps are explained with the help of the following example.
Example 17: Add the following floating point numbers
Equivalent Numbers IEEE 754 32 bit representation
Decimal Binary S exp Significand (M)
-7 -1.11×2129-127 1 1000 0001 110 0000 0000 0000 0000
= -1.11×22
= - 111.0
+24 +1.1×2131-127 0 1000 0011 100 0000 0000 0000 0000
= +1.1×24
= +11000.0
Solution:
Step 1: Find the difference in exponents of the numbers
1000 0011 - 1000 0001 = 0000 0010 = 2 in decimal
Step 2: Align the Significand of the smaller number by denormalizing it
Step 4: Select the sign and exponent of the bigger number as sign and exponent of the
result and Normalize the Significand by adjusting the exponent
The result is shown below. Please note that in this case, there is no need to
normalize the result as it is already normalized.
It may be noted that parity bit can detect errors in case 1 bit is in error. In case 2 bits
are in error, then it will fail to detect the error.
Hamming Error-Correcting Code: The Hamming code was conceptualized by
Richard Hamming at Bell Laboratories. This code is used to identify and correct the
error in 1 bit. Thus, unlike parity bit, which just identifies the existence of error, this
code also identifies the bit that is in error. The idea of Hamming’s code is to divide
the data bits into a number of groups; and using the parity bit to identify, which
groups are in error; and based on the groups in error, identify the bit which has caused
the error. Thus, the grouping process has to be very special, which is explained below:
How to Group data bits? Before grouping, you may assume the placement of data and
parity bits using the following considerations.
A bit position that is exact power of 2 will be used for storing parity bit. For example,
20=1, that is 1st bit position will be used to store parity bit, likewise 21=2, 22=4, and
23=8, i.e. 2nd , 4th and 8th bit positions will also be used to store parity bit. Thus, you
have now 7 bit data and 4 parity bits, so a total of 11 bit positions. (p indicates parity
bit and d indicates data bit)
Bit Position 12 11 10 9 8 7 6 5 4 3 2 1
Stores d8 d7 d6 d5 p4 d4 d3 d2 p3 d1 p2 p1
For grouping the data bit
number is used to identify
the parity bit to which data
should be member of
Bit position 12 (8+4) 8 4 - -
contains (d8)
Bit position 11 (8+2+1) 8 - 2 1
contains (d7)
Bit position 10(8+2) 8 - 2 -
contains (d6)
Bit position 9(8+1) 8 - - 1
contains (d5)
Bit position 8 contains p4
(p4)
Bit position 7(4+2+1) - 4 2 1
contains (d4)
Bit position 6(4+2) - 4 2 -
51
Introduction to Digital contains (d3)
Circuits
Bit position 5(4+1) - 4 - 1
contains (d2)
Bit position 4 contains p3
(p3)
Bit position 3(2+1) - - 2 1
contains (d1)
Bit position 2 contains p2
(p2)
Bit position 1 contains p1
(p1)
Table 22: Placement of data and parity bits for Hamming's error detection and
correction code
Groups for parity bits: The groups are made for each on the basis of bit positions, on
the basis of above Table. A bit position, which includes a parity bit position is
included in the group of that parity bit. For example, the bit at bit position 12 will be
included in group of parity bit p4 and p3; similarly, bit position 7 will be included in
group of parity bit p3, p2 and p1. But why these grouping? You may please note that
each data bit is part of unique combination of groups, so if it is in error, it will cause
errors in all those groups to which it is a part of. Thus, by identifying all the groups,
which has parity mismatch, will identify the bit which is in error. The following table
shows these groups for 8 bit data.
Group for Bit positions and data bit
Parity bits
p4 Bit position 12 data bit d8, Bit position 11 data bit d7, Bit position 10
data bit d6 and Bit position 9 data bit d5
p3 Bit position 12 data bit d8, Bit position 7 data bit d4, Bit position 6
data bit d3 and Bit position 5 data bit d2
p2 Bit position 11 data bit d7, Bit position 10 data bit d6, Bit position
7data bit d4, Bit position 6 data bit d3 and Bit position 3data bit d1
p1 Bit position 11 data bit d7, Bit position 9 data bit d5, Bit position
7data bit d4, Bit position 5 data bit d2 and Bit position 3data bit d1
Therefore, the parity bits will be generated using the following data bits:
Parity bit Compute Odd parity of Data bits
p4 d8, d7, d6 and d5
p3 d8, d4, d3 and d2
p2 d7, d6, d4, d3 and d1
p1 d7, d5, d4, d2 and d1
So, how the data bit in error be recognised? It is illustrated with the help of following
example
Example 20: 8-bit data 1010 1001 is sent from a source to a destination. The data is
received at the destination as 1000 1001 having error in only one bit. How does this
error be detected and corrected by Hamming’s error detection and correction code?
Solution:
Step 1: Place the bits as shown in Table 22 and generate parity bits at the source, for
example, the odd parity bit p4 is computed using d8, d7, d6 and d5 (shown as shaded
cells in the following table). Their values are 1, 0, 1, 0 as shown in the table, as there
are only two bits containing 1, therefore, the odd parity value for p4 is 1. Likewise
compute the other parity bits as shown in Table 23.
Step 2: Data and the associated parity bits in the sequence as shown below are sent to
the destination, where once again parity bits are computed for the received data.
Step 3: Compare the source parity bits and destination parity bits as shown in Table
23. Please note when two parity bit match, a 0 is put in the compare word else a 1 is
put. The magnitude of comparison word, indicates the bit position that is in error.
52
Step 4: If there is an error, then the data at bit position that is in error is Data Representation
complemented.
Step 5: The data is used at the destination after omitting the parity bits.
Bit Position 12 11 10 9 8 7 6 5 4 3 2 1
Stores d8 d7 d6 d5 p4 d4 d3 d2 p3 d1 p2 p1
Data Bits 1 0 1 0 1 0 0 1
Compute Odd parity bit 1
p4 using d8, d7, d6 and
d5
Compute Odd parity bit 1
p3 using d8, d4, d3 and
d2
Compute Odd parity bit 0
p2 using d7, d6, d4, d3
and d1
Compute Odd parity bit 1
p1 using d7, d5, d4, d2
and d1
Data and Parity bits at 1 0 1 0 1 1 0 0 1 1 0 1
Source
Data is sent to the destination, where data is received with 1 bit in error (given),
therefore all the source parity bits are received without any error
Data received at 1 0 0 0 1 1 0 0 1 1 0 1
destination including
parity bits
Step 2: Compute the parity bits using the data received at the destination
Data Bits Received 1 0 0 0 1 0 0 1
Compute Odd parity bit 0
p4 using d8, d7, d6 and
d5
Compute Odd parity bit 1
p3 using d8, d4, d3 and
d2
Compute Odd parity bit 1
p2 using d7, d6, d4, d3
and d1
Compute Odd parity bit 1
p1 using d7, d5, d4, d2
and d1
Step 3: Compare the source parity bits and destination parity bits.
Source Parity bits 1 1 0 1
Destination Parity bits 0 1 1 1
Parity Comparison word 1 0 1 0
(0 if source and
destination parity match
else 1)
The comparison word is 1010 = 10 in decimal, i.e. bit position 10 is in error. The error
in this bit can be corrected by complementing the bit position 10.
Corrected Data 1 0 1 0 1 0 0 1
Table 23: Example of Hamming's error detection and correction code
It may be noted in Table 23 that the value of comparison word 0000 would mean that
there is no error in transmission of data. In addition, the values 1000, 0100, 0010 and
0001 would mean that one bit error has occurred in the transmission of source parity
53
Introduction to Digital bits p4, p3, p2 and p1 respectively. Thus, no change would be needed in the received
Circuits
data bits at the destination in such cases.
It may please be noted that Hamming's code presented in this section can detect and
correct errors in a single bit ONLY. It will not work, in case two or more bits are in
error. One final question is about the size of the code needed to correct single bit
error. The size will be dependent on the size of data. A simple rule is that the size of
code and the data should be less than the possible bit positions that can be flagged by
the comparison word. If the data to be transmitted is of size D bits and P is the number
of parity bits needed for the given Hamming's code, then size of the code is the
smallest value of P, which satisfies that following equation:
D + P < 2P
For example, for a D=4 bits, the value of P would be 3 as:
4 + 3 < 23 as 7<8
and for a D=8 bits, the value of P would be 4 as:
8 + 4 < 24 as 12<16
Check Your Progress 3
1) Represent the following numbers using the IEEE-754 32bit standard:
i) 39.125
ii) –0.0000110002
2) Compute the Odd and Even parity bits for the following data:
i) 0111110
ii) 0110000
iii) 1110111
iv) 1001100
.........................................................................................................................................
.........................................................................................................................................
3) A 4 bit data 1011 is received at the destination as 1111, assuming single bit is in
error, illustrate how Hamming's single error correction code will detect and
correct the error
.........................................................................................................................................
.........................................................................................................................................
.........................................................................................................................................
2.7 SUMMARY
This Unit has introduced you to the basic aspects of data representation. It introduces
the character representing including ASCII and Unicode. In addition, the Unit
explains number conversion and fixed point representation of binary number. The
Unit also highlights the arithmetic operations. This was followed by a detailed
discussion on the floating point numbers. Though only IEEE 754 32-bit single
precision numbers are explained, however, the logic discussed is applicable to double
precision numbers too. The Unit finally introduces you to error detection code -parity
bit and error detection and correction code. You must practice the data conversions
and these codes as they would be useful, when you deal with binary numbers.
54
You should refer to the further readings for more detailed information on these topics. Data Representation
You are advised to take the help of further readings, Massive Open Online Courses
(MOOCs), and other online resources as Computer Science is a dynamic area.
2.8 SOLUTIONS/ANSWERS
Binary Number 0 0 0 1 1 1 0 0 . 0 1 1 0 1 0 0 0
Grouping Directions .
Grouped 0 0 0 1 1 0 . 0 1 1 1 0 0
1 0 0 0
Binary place values 8 4 2 1 8 4 2 1 . 8 4 2 1 8 4 2 1
Equivalent 0+0+0+1=1 8+4+0+0=C . 0+4+2+0=6 8+0+0+0=8
Hexadecimal Digit
Hexadecimal Number 1 C . 6 8
Binary Number 0 0 1 1 0 1 1 0 1 0 1 0
Grouping Directions
Grouped 0 0 1 1 0 1 1 0 1 0 1 0
Binary place values 8 4 2 1 8 4 2 1 8 4 2 1
Equivalent Hexadecimal Digit 0+0+2+1=3 0+4+2+0=6 8+0+2+0=A
Hexadecimal Number 3 6 A
2) i) 11910 to binary
The place 26 25 24 23 22 21 20
value =64 =32 =16 =8 =4 =2 =1
N = 119 119-64=55; 55-32=23; 23-16=7; 7-4=3; 3-2=1; 1-1=0
Equivalent Binary 1 1 1 0 1 1 1
ii) 19.12510
The place 24 23 22 21 20 . 2-1 2-2 2-3
55
Introduction to Digital value =16 =8 =4 =2 =1 =0.5 =0.25 =0.125
Circuits
N = 19.125 19-16=3; 3-2=1; 1-1=0; and 2-3 =0.125
Equivalent Binary 1 0 0 1 1 . 0 0 1
iii) 32510
The place 28 27 26 25 24 23 22 21 20
value =256 =128 =64 =32 =16 =8 =4 =2 =1
N = 325 325-256=69-64=5; 5-4=1; 1-1=0
Equivalent Binary 1 0 1 0 0 0 1 0 1
3 i) 11910
The place 26 25 24 23 22 21 20
value =64 =32 =16 =8 =4 =2 =1
Equivalent Binary 1 1 1 0 1 1 1
Equivalent Octal 1 6 7
Equivalent Hexadecimal 7 7
ii) 19.12510
The place 24 23 22 21 20 . 2-1 2-2 2-3
value =16 =8 =4 =2 =1 =0.5 =0.25 =0.125
Equivalent Binary 1 0 0 1 1 . 0 0 1
Equivalent Octal 2 3 . 1
Equivalent Hexadecimal 1 3 . 0010=2
iii) 32510
The place 28 27 26 25 24 23 22 21 20
value =256 =128 =64 =32 =16 =8 =4 =2 =1
Equivalent Binary 1 0 1 0 0 0 1 0 1
Equivalent Octal 5 0 5
Equivalent Hexadecimal 1 4 5
ii) 17.89
Sign Digit 1 7 . 8 9
1100 0001 0111 . 1000 1001
iii) 299
Sign Digit 2 9 9
1100 0010 1001 1001
2)
Deci The Number Signed 1's Complement Signed 2's Complement
56
mal Data Representation
-30 1 1 1 0 0 0 1 0 0 0 0 1 1 1 0 1 0 0 0 1 1 1 1 0
+126 0 1 1 1 1 1 1 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0
3) i) +56 and – 56
Carry
out
Number Signed 2's Complement Notation
(9th
bit)
Carry for
1 1 1 1 1 -
addition
+56 0 0 1 1 1 0 0 0
-56 1 1 0 0 1 0 0 0
Addition of
1+0+1 1+0+1 1+1+0 1+1+0 1+1 0+0 0+0 0+0
bits given
=10 =10 =10 =10 =10 =0 =0 =0
above
Result 1 0 0 0 0 0 0 0 0
There is a carry in to the sign bit (1) and there is a carry out of the sign bit (1).
Therefore, as per Table 14, there is NO overflow and the result is correct and equal to
0. Discard the carry out bit (the 9th bit). Verify the result yourself.
ii) +65 and –75
Carry out
Number Signed 2's Complement Notation
(9th bit)
Carry for
1 -
addition
+65 0 1 0 0 0 0 0 1
-75 1 0 1 1 0 1 0 1
Addition of
0+1 1+0 0+1 0+1 0+0 0+1 1+0+0 1+1
bits given
=1 =1 =1 =1 =0 =1 =1 =10
above
Result 1 1 1 1 0 1 1 0
There is No carry in to the sign bit and there is No carry out of the sign bit. Therefore,
as per Table 14, there is NO overflow and the result is correct and equal to -10.
Verify the result yourself.
iii) +121 and +8
Carry
out
Number Signed 2's Complement Notation
(9th
bit)
Carry for
1 1 1 1 -
addition
+121 0 1 1 1 1 0 0 1
+8 0 0 0 0 1 0 0 0
Addition of bits 1+0+0 1+1+0 1+1+0 1+1+0 1+1 0+0 0+0 0+1
given above =1 =10 =10 =10 =10 =0 =0 =1
Result 1 0 0 0 0 0 0 1
There is a carry in to the sign bit (1) and there is NO carry out of the sign bit.
Therefore, as per Table 14, there is OVERFLOW and the result is incorrect.
ii) –0.0000110002
Sign bit = 1 as number is negative
The number is of the format ±1.M ×2exp-127,
1.1000×2-5
exp = -5+127=122
S exp of length 8 bits Significand of length 23 bits
(value 122) (value 1.1000) Represented as 1.1000
0 0111 1010 100 0000 0000 0000 0000 0000
2)
The Number Even Parity Odd Parity
0111110 1 0
0110000 0 1
1110111 0 1
1001100 1 0
58
Bit Position 7 6 5 4 3 2 1 Data Representation
Stores d4 d3 d2 p3 d1 p2 p1
For grouping the data bit number is used to identify
the parity bit to which data should be member of
Bit position 7(4+2+1) contains (d4) 4 2 1
Bit position 6(4+2) contains (d3) 4 2 -
Bit position 5(4+1) contains (d2) 4 - 1
Bit position 4 contains (p3) p3
Bit position 3(2+1) contains (d1) - 2 1
Bit position 2 contains (p2) p2
Bit position 1 contains (p1) p1
Bit Position 7 6 5 4 3 2 1
Stores d4 d3 d2 p3 d1 p2 p1
Data Bits 1 0 1 1
Compute Odd parity bit p3 using d4, d3 and d2 1
Compute Odd parity bit p2 using d4, d3 and d1 1
Compute Odd parity bit p1 using d4, d2 and d1 0
Data and Parity bits at Source 1 0 1 1 1 1 0
Data received at destination including parity bits 1 1 1 1 1 1 0
Data Bits Received 1 1 1 1
Compute Odd parity bit p3 using d4, d3 and d2 0
Compute Odd parity bit p2 using d4, d3 and d1 0
Compute Odd parity bit p1 using d4, d2 and d1 0
Source Parity bits 1 1 0
Destination Parity bits 0 0 0
Parity Comparison word (0 if source and 1 1 0
destination parity match else 1)
Location 6 is in error, which is decimal equivalent 1 0 1 1
of 110 the comparison word. So Corrected Data
59
Introduction to Digital
Circuits
UNIT 3 LOGIC CIRCUITS - AN
INTRODUCTION
Structure Page Nos.
3.0 Introduction
3.1 Objectives
3.2 Logic Gates
3.3 Boolean Algebra
3.4 Logic Circuits
3.5 Combinational Circuits
3.5.1 Canonical and Standard Forms of an Boolean expression.
3.5.2 Minimization of Gates
3.6 Design of Combinational Circuits
3.7 Examples of Logic Combinational Circuits
3.7.1 Adders
3.7.2 Decoders
3.7.3 Multiplexer
3.7.4 Encoder
3.7.5 Programmable Logic Array
3.7.6 Read Only Memory ROM
3.8 Summary
3.9 Solutions/ Answers
3.0 INTRODUCTION
3.1 OBJECTIVES
In the next few sections, we explain how these simple logic gates can be used
to construct logic circuits. The next section explains the mathematics of logic
circuits.
61
Introduction to Digital
Circuits 3.3 BOOLEAN ALGEBRA
Boolean algebra was designed by George Boole in the 19th century. It presents
mathematical foundation for performing various functions on binary variables.
Please recall that binary variables can have only two values 0 or 1. The value 0
by convention is taken as False and 1 as True. Please also refer to Figure 3.1,
which shows the truth table for various gates. These truth tables can also be
represented using the Boolean function. Figure 3.2 shows the Boolean
algebraic representation of logic gates of Figure 3.1.
Boolean
Gate Explanation
Representation
It can be represented using two Boolean functions, one for each output,
viz. Carry and Sum, as:
C = I1 . I2 and
S = I1 ⊕ I2 (Please refer to Fig. 3.1 & Fig 3.2)
The Boolean algebra is used to simplify logic circuits that are made of logic
gates. However, before we demonstrate this process of simplification, first you
may go through the basic rules of Boolean algebra. Figure 3.3 shows these
rules. Please note that some of the rules are shown with proof using truth table.
You can make truth table yourself for the cases for which the proof is not
shown.
62
Principles of Logic
Circuits I
Input Identities
(i) I I+0=I I+1=1 I.0=0 I.1=I
0 0+0= 0 0+1=1 0.0=0 0.1= 0
1 1+0= 1 1+1=1 1.0=0 1.1= 1
Input Identities
I I+I=I I + I′ = 1 I.I=I I . I′ = 0
(ii)
0 0+0= 0 0+1=1 0.0= 0 0.1=0
1 1+1= 1 1+0=1 1.1= 1 1.0=0
(Please note 0′= 1 and 1′ = 0)
(iii) The rules (given without proof)
I1+I2=I2+I1 ;
I 1 . I2 = I2 . I1 ;
I1+(I2+I3)=(I1+I2)+I3 ;
I1.(I2.I3)=(I1.I2).I3
(iv) The rules (given without proof)
I1. (I2+I3) = (I1. I2 + I1.I3) ;
I1+I2.I3=(I1+I2) . (I1+I3)
(v) Demorgan’s Laws:
(I1+I2)′ = I1′.I2′
(I1.I2) ′ = I1′ +I2′
(Very important laws for algebraic simplification.)
(vi) Complement of complement of a number is the Number itself
I I′ (I′) ′
0 1 0 so (I′)′ = I
1 0 1
Figure 3.3: The Rules of Boolean algebra
All the rules and identities as given in Figure 3.3 can be used for simplification
of Boolean function. This is explained with the help of following example.
Example: Simplify the Boolean function:
F = ((A′+B′)′ + (A.B) ′)′
Solution:
F = ((A′+B′)′ + (A.B)′)′
F = ((A′+B′)′)′ . ((A.B)′)′ (Using Demorgan’s Law)
= (A′+B′) . (A.B) Using Rule (vi)
= (A.B) . (A′+B′) Reversing the terms - Rule (iii)
= ((A.B).A′) + ((A.B) . B′) Using Rule (vi) taking (A.B) as I1
= ((A.A′).B) + (A.(B.B′) Using Rule (iii)
= 0.B + A.0 Using Rule (ii)
= 0+0 Using Rule (i)
=0
F=0
63
Introduction to Digital You can check the above using the following Truth Table
Circuits
(A′+B′)′
A B A′ B′ (A′+B′) (A.B) (A′+B′)′ (A.B)′ ((A′+B′)′+(A.B)′)′
+ (A.B)′
0 0 1 1 1 0 0 1 1 0
0 1 1 0 1 0 0 1 1 0
1 0 0 1 1 0 0 1 1 0
1 1 0 0 0 1 1 0 1 0
Inputs Output
A B C F= A.B+C
0 0 0 F=0.0+0=0
0 0 1 F=0.0+1=1
0 1 0 F=0.1+0=0
0 1 1 F=0.1+1=1
1 0 0 F=1.0+0=0
1 0 1 F=1.0+1=1
1 1 0 F=1.1+0=1
1 1 1 F=1.1+1=1
(a) Truth Table
A A.B
B A.B+C
C
C
Input Output F
64
While fabricating these logic circuits, it is expected that fewer gate types are used; Principles of Logic
Circuits I
however, these gate types should be able to create all kinds of circuits. Therefore,
functionally complete set of gates, which are a set of gates by which any Boolean
function may be implemented, are used to fabricate the logic circuits. Examples of
functionally complete sets are: [AND, OR, NOT]; [NOR]; [NAND] etc. NAND gate,
also called universal gate, is a special gate and can be used for fabrication of all kinds
of circuits. You may refer to further readings for more details on Universal gates.
Check Your Progress 1
1) What is a logic gate? What is the meaning of term Universal gate?
.........................................................................................................................................
.........................................................................................................................................
……………………………………………………………………………………….
The output of the combinational circuit changes instantaneously with respect of input,
though some delay is introduced due to transfer of signal from the circuit. This delay
is dependent on the depth which is computed as number of gates in the longest path
from input to output. For example, the depth of the combinational circuit of Figure 3.5
is 2.
65
Introduction to Digital
Circuits
A A.B
B ((A.B) + (A′+B))
A′ A′+B
B
66
Principles of Logic
n=2 ⇒ 2n=22=4. The possible minterms for two variables are shown in the Circuits I
Figure 3.6.
Variables
Minterm
A B
0 0 A′B′ m0
0 1 A′B m1
1 0 AB′ m2
1 1 AB m3
Figure 3.6: Minterms for two variables
A function can be represented as a sum of minterms, for example a function F
in two variables using minterms A′B + AB can be represented as:
F(A,B)= A′B + AB
which can be represented as:
F(A,B) = ∑ (1,3)
(Please note that A′B is minterm m1 or 1 and AB is minterm m3 or 3,
Example: Represent the function, whose SOP form is given below into an equivalent
function in POS form.
F(A,B) = A′.B + A.B or F(A,B) = ∑ (1,3) or the truth table representation is:
67
Introduction to Digital A B F(A,B)
Circuits
0 0 0
0 1 1
1 0 0
1 1 1
Solution:
The complement of this function in SOP form is represented as (the minterms that has
0 as function output).
(F′(A,B))′ = (A′.B′+A.B′)′
F(A,B) = (A′.B′)′+(A.B′)′
= ((A′)′+(B′)′).(A′+(B′)′)
= (A+B) . (A′+B)
Form table you can determine that function in POS form is:
F(A,B) = ∏ (0,2) as the terms are M0 and M2
Thus, you can see:
F(A,B) = ∑ (1,3) = ∏ (0,2)
(SOP form) (POS form)
With this background of minterm and maxterm, you now are ready to perform the
process of grouping of minterms, which will result in minimization of gates needed
for a digital circuit. This is discussed in the next section.
3.5.2 Minimization of Gates
The simplification of Boolean expression is useful for the design of a good
combinational circuit. There are several methods of doing so, however in this unit
only the following two methods are discussed in details.
Algebraic Simplification
Karnaugh Maps
Algebraic Simplification
The following example explains the process of algebra simplification
Example : Simplify the function: F(A,B,C) = ∑ (0,1,4,5,6,7)
Solution: Expanding the Minterms of the functions as:
The truth table for the function and the equivalent expression is:
68
Principles of Logic
Circuits I
A B C F(A,B,C) = ∑ (0,1,4,5,6,7) B′+A.B
0 0 0 1 1
0 0 1 1 1
0 1 0 0 0
0 1 1 0 0
1 0 0 1 1
1 0 1 1 1
1 1 0 1 1
1 1 1 1 1
Thus, the logic circuit for the simplified equation F(A,B,C) = AB+B′
A
A.B
AB+B′
B
B′
Figure 3.8: Simplified logic function using algebraic Simplifications
The logic diagram of the simplified expression is drawn using one NOT, OR and
AND gate each.
The algebraic simplification becomes cumbersome because it is not clear which
simplification should be applied next. The Karnaugh map is a simplified process of
design of logic circuit using graphical approach. This is discussed next.
Karnaugh Maps
Karnaugh map is graphical way of representing and simplifying a Boolean function.
They are useful for design of circuits involving 2 to 6 variables. The following is the
process for simplification of logic circuit using Karnaugh map (K map).
Step 1: Create a Rectangular K-map and Assign binary and decimal equivalent values
to each cell
Create a rectangular grid of variables in a function. Figure 3.9 shows the map
of two, three and four variables. A map of 2 variables consists of a grid 22 = 4
elements or cells, while a map of 3 variables has 23 = 8 cells and 4 variables
has 24 =16 cells. Please note that the number of cells are same as the
maximum possible number of minterms for those number of variables.
Each cell corresponds to a set of variable values, shown on the top or left of
the K-map. For example, the values 00, 01, 11, 10 are written on the top of the
cells of K-maps of 3 and 4 variables. These represent the values of the
variables. For example, for the 3-variable k-map values written on BC side for
the first cell 00 indicate B=0 and C=0. Please note that variable values are
assigned such that any two adjacent cells (horizontal or vertical) differ only in
one variable. For example, cell values 01 and 11 differ in 1 bit only, so are the
values 11 and 10. The decimal equivalent values are shown inside the cells.
For example, for a 3-varaible K map cell having A=1 and BC=11, which is
ABC as 111 is 7. Please note that the sequence of the number is not sequential
in 3 variable and 4 variable K maps. This is because of the condition of
change in only one variable between two adjacent cells. The decimal
equivalent of minterm varaible values are marked inside the cells. For
example, decimal equivalent (or minterm equivalent) number placed in the
cell having ABCD values as 1111 in the 4 variable k-map is 15.
69
Introduction to Digital Please note that bottom row is adjacent to top row; and last column is
Circuits
adjacent to first column as they differ in only one variable respectively.
CD
B AB 00 01 11 10
A 0 1 BC
00 0 1 3 2
0 0 1 A 00 01 11 10
0 0 1 3 2 01 4 5 7 6
1 2 3
1 4 5 7 6 11 12 13 15 14
10 8 9 11 10
Decimal A B C D F
0 0 0 0 0 1
1 0 0 0 1 0
2 0 0 1 0 1
3 0 0 1 1 0
4 0 1 0 0 0
5 0 1 0 1 0
6 0 1 1 0 0
7 0 1 1 1 0
8 1 0 0 0 1
9 1 0 0 1 1
10 1 0 1 0 1
11 1 0 1 1 1
12 1 1 0 0 0
13 1 1 0 1 0
14 1 1 1 0 0
15 1 1 1 1 1
CD 00 01 11 10
AB
00 1 0 1 3
1 2 (i) Adjacency 1: Four Corners
4 5 7 6
(cells Numbered 0, 2, 8, 10)
01
12 13 (ii) Adjacency 2: The bottom Row
11 1 15 14
(cells Numbered 8, 9, 11, 10)
8 9 11
10 1 1 1 1 10
(iii) Adjacency 3: Cell 11 and Cell 15
(b) Karnaugh’s map
Figure 3.10: Truth table & K-Map of Function F = (0, 2, 8, 9, 10, 11, 15)
70
Principles of Logic
The three adjacencies of the K-map are shown in the Figure 3.10. You can write the
Circuits I
Boolean expression for each adjacency.
1) The adjacency 1 of four corners (cells Numbered 0, 2, 8, 10) can be written
algebrically as:
A′.B′.C′.D′ + A′.B′.C.D′ + A.B′.C′.D′ + A.B′.C.D′
= A′.B′.D′ .(C′+C) + A.B′.D′.(C′+C)
= A′.B′.D′ + A.B′.D′ (as C′+C=1)
= (A′+A).B′.D′
= B′.D′ (as A′+A=1)
Please note that an adjacency of 8/4/2 reduces the variables by 3/2/1 respectively.
A direct way of doing so is to identify the variables values of the adjacent cells which
does not change, e.g. for this adjacency cell variable ABCD are 0000, 0010, 1000 and
1010. Thus the variable values of B and D does not change in all these 4 cells. In
addition, since B and D have zero values among all these four cells, therefore, the
expression is B′D′.
2) The four 1’s in the bottom row (cells Numbered 8, 9, 11, 10)
The values of variable AB does not change and is 10 for the entire row, therefore, the
expression for this adjacency would be A.B′
Example: Use K-map to find the simplified Boolean function for the function
F(A,B,C,D) = ∑ (0,2,8,9,10,11,15) in POS form.
Solution: The truth table is shown in previous example. It can be used to draw K-map
for 0 values, which will be for the complement of the function, i.e. F′(A,B,C,D), as:
CD 00 01 11 10
AB
0 1 3 2
00
0 0
4 5 7 6
01
0 0 0 0
12 13 15 14
11
0 0 0
8 9 11 10
10
K-map for F′
71
Introduction to Digital
Circuits
Four Adjacencies:
(i) Cells (1,3,5,7) : A′ and D does not change, so the term is A′.D
(ii) 2nd Row (cells 4,5,7,6) : A′ B does not change A′.B
(iii) Cells 4,5,12,13 : B and C′ does not change B.C′
(iv) Cells 6 & 14 : B,C,D′ does not change B.C.D′
In certain digital design situations, some of the input combination has no significance,
for example, while designing the circuit for BCD, the output for the input
combinations 0000 (digit 0) to 1001 (decimal digit 9) are needed. For the rest of input
1010 to 1111, the output does not matter. Such K-maps are designed using DONOT
CARE condition. The output for DONOT CARE input combinations is marked
as X in the K-map. The cells marked X can be used for determining the
maximal dependencies, but need not be covered as the case is for all 1’s
output. A detailed discussion on this is beyond the scope of this unit.
What will happen if you went to design circuits for more than 6 variables? With the
increase in number of variables K-Maps become more cumbersome and are not
suitable. Other methods have been designed to do so, which are beyond the scope of
this course.
Check Your Progress 2
1) Draw the truth table for the following Boolean functions:
(i) F(A,B,C) = A′.B.C′+A.B.C+A.B.C′+B.C+A.C
(ii) F(A,B,C) = (A+B) . (A′+C′) . (C′+B′)
…………………………………………………………………………………………
…………………………………………………………………………………………
2 Simplify the following using algebraic simplification. And draw the logic
diagram for the function so obtained
(i) F(A,B) = (A′.B′+B′)′
(ii) F(A,B) = (A.B+A′.B′)′
…………………………………………………………………………………………
…………………………………………………………………………………………
3) Simplify the following Boolean functions in SOP and POS forms using K-
Maps. Draw the logic diagram for the resultant function.
F (A,B,C,D) = (0,2,5,7,12,13,15)
…………………………………………………………………………………………
…………………………………………………………………………………………
72
Principles of Logic
3.6 DESIGN OF COMBINATIONAL CIRCUITS Circuits I
The digital circuits, are constructed with NAND or NOR gates instead of AND–OR–
NOT gates as they are Universal Gates. Therefore, any digital circuit can be
implemented using these gates. To prove this point in the following diagram AND,
OR and NOT gates are implemented using NAND and NOR gates. This is shown in
figure 3.11 to 3.13 below.
NOT Operation:
A F=A′ A F=A′
A A
A A F A A F
0 0 1 0 0 1
1 1 0 1 1 0
Figure 3.11: NOT Operation using NAND or NOR gates
AND Operation:
Performing AND using NAND gates can be achieved by first performing the NAND
or the input followed by inverting the output as shown in Figure 3.12
F = A .B
= ((A.B)′)′
F = (A NAND B) ′
A
(A.B)′ (A.B)
B
Figure 3.12: Logic circuit of AND Operation using NAND gates
AND operation can also be implemented using NOR gates. The following Boolean
expression identifies that first NOR gates are used to invert the A and B input
followed by taking NOR of A′ with B′
F = A.B
F = ((A.B)′)′
= (A′+B′)′
= A′ NOR B′
A A′
(A′+B′)′≡A.B
B
B′
73
Introduction to Digital OR Operation:
Circuits
OR operation can be performed using NAND gate. Please refer to following Boolean
expressions:
F = A+B
= ((A+B)′)′
F = (A′.B′)′ A′ NAND B′
A A′
(A′.B′)′
B
B′
Figure 3.14: Logic circuit of OR Operation using NAND gates
F=(A+B)
F= ((A+B)′)′.
F = (A NOR B)′
A (A+B)′ (A+B)
B
BC
00 01 11 10
A
0 1 5 2
0
1 1 1
4 5 7 6
1
1
F(A,B,C) = A′B′+BC
The AND – OR gate logic circuit for this is:
B
A′B′+BC
C
A′
B′
Figure 3.16 Logic Circuit Using AND-OR gate
74
For NAND gate logic circuit Principles of Logic
Circuits I
F(A,B,C) = (A′B′+BC)
= ((A′.B′)′)′+((B.C)′)′
= ((A′. B′)′.(B.C)′)′ ( Use of Demorgan's law)
= ((A′ NAND B′).(B NAND C))′
= (A′ NAND B′) NAND (B NAND C)
Thus, the circuit can be made simply by replacing two levels AND-OR circuit by
NAND gates:
B
C (A′B′+BC)
A′
B′
3.7.1 Adders
Addition is one of the most common arithmetic operations. In this section two
different kinds of addition circuits are designed. The first of the two circuit adds two
binary digits and is called a half adder, while the second adds three bits-two addend
and one carry bit, and is called a full adder.
Half Adder:
Let us assume that a half adder circuit is adding two bits a and b to produce one sum
bit (s) and one carry bit (c). The following truth table shows this operation. Please
note one adding a =1 and b=1 you get a carry as 1 and sum bit as 0 as shown in truth
table. The K-maps for the addition is shown in figure 3.18.
75
Introduction to Digital a b c s
Circuits
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 0
(a) Truth table
s c
b b
0 1 0 1
a a
0 0 1
0 11 0
2 3 2 3
1 1 1 1
(b) K- map for sum bit (c) K-map for carry bit
Figure 3.18: Truth table and K-maps for half adder
The Boolean expression for them from the k-maps are:
s = a′b+ab′ and
c = a.b
The logic circuit for the half adder is based on the Boolean expressions are given are
shown in Figure 3.19.
a′ a′b
b
s = a′b+ab′
a
a
a ab′
a′
b′
b b
b′
a
c = ab
b
Figure 3.19: The half adder circuit-input addend bits a, b; output sum bit (s) and
carry bit (c)
Full Adder:
Full adder is a circuit that adder 3 bits, viz. 2 addend bits and one carry bit. The truth
table for full adder is shown in Figure 3.20. Please note that in figure 3.20, cin is carry
in bit and cout is carry out bit.
76
Principles of Logic
Input Output Circuits I
Decimal a b cin Carry Sum
equivalent out (cout) (s)
0 0 0 0 0 0
1 0 0 1 0 1
2 0 1 0 0 1
3 0 1 1 1 0
4 1 0 0 0 1
5 1 0 1 1 0
6 1 1 0 1 0
7 1 1 1 1 1
Figure 3.20: The Truth Table for Full Adder
Please note that in the truth table, when a = 1, b = 1 and cin =1 , than the output is 11 ,
which means sum bit (s) is 1 and carry out bit is also 1. The K-map for these are also
shown in Figure 3.21
cin cout
0 1 cin
ab 0 1
00 0
11 ab
0 1
2 3
00
01 1 2 3
6 7
01 1
11 1 6
4 5
11 1 17
10 1 4 5
10 1
a′
b′
cin
a′
b
cin′
a
b
cin
a
b′
cin′ (a) Sum bit
77
Introduction to Digital
Circuits
a
b
b
cin
a
cin
(b) Carry Out bit
Figure 3.22: Full Adder
Full adder and half adder only perform bit addition of two operands without or
with carry bit respectively. However, binary numbers have several bits e.g.
integers can be 4 byte long. How will they be added? This is performed by
creating a sequence of full adders, where carry out bit of the lower bit addition
is fed as carry in bit of next higher bit addition, as shown in figure 3.23.
a0 b0 a1 b1 a2 b2 a3 b3
s0 s1 s2 s3
a1b1
00 01 11 10
c0
0 1 3 2
0
1
4 5 7 6
1
1 1 1
Figure 3.24: K-map for c1 output of Full adder (bit 1)
There are three adjacencies in the K-map of Figure 3.24. The resultant Boolean
function for c1 would be:
c1 = a1.b1+c0.a1+c0.b1
c1 = a1b1+c0.(a1+b1) (Taking c0 common)
c1 = a1.b1+a0.b0.(a1+b1) (Replacing c0 by its equivalent)
Logic circuits can be designed for prediction of carry bits c0, c1, etc. and
resultant circuits can be implemented along with full adder circuits. You can
observe that Boolean expression for higher order carry bits like c2, c3 etc. will
become more complex, which results in complex logic circuits. Thus, look
ahead carry bit adders may be implemented for addition of binary numbers of
size 4-8 bits.
Adder-Subtractor Circuit
Adder subtractor circuit is an interesting design, in which a same circuit is used
for addition as well as subtraction. This example shows how with some
additional logic, you may be able to perform additional operations. ALU is a
fine example of extension of such logic. Figure 3.25 shows the circuit of 4 bit
adder-subtractor circuit by using full adders.
s3 s2 s1 s0
Carry in
sign bit
0/1
a3 a2 a1 a0
b3 b2 b1 b0
79
Introduction to Digital
Circuits
You may please note that the mode bit controls the b input. The following
Figure shows the details of operation.
Mode bit = 0 Mode bit = 1
Input b Inputs the bits of Input b Input value after
b input XOR with taking XOR of
mode bit value input b and mode
(0) bit
0 0 XOR 0 = 0 0 0 XOR 1 = 1
1 1 XOR 0 = 1 1 1 XOR 1 = 0
Thus, when mode bit is 0, the input to Thus, when mode bit is 1, the input to
full adder is the value of input b. adder is the value of 1′s complement
of b
cin = 0 as mode bit = 0 so the circuit cin = 1, so the addition is r = a+b′+1
adds input a and input b.
or r= a+2′s complement of b
r = a – b ; subtraction of a and b
Figure 3.26: Use of Mode bit to control b input in Adder subtractor circuit
Please also note that in 2’s complement notation the last bit is treated as sign
bit. The overflow condition is checked by finding if the carry into the sign bit
and carry out of sign bit are same or not same. In case carry in to the sign bit is
not the same as carry out of the sign bit, then overflow is set to 1 (by XOR
gate) else overflow is set to 0 (No overflow).
3.7.2 Decoders
Decoder, as the name suggests, decodes the input to one of the output line.
Figure 3.27 shows the truth table and logic circuit of a 2 × 4 decoder.
Truth table
Input Output
a b c d e f
0 0 1 0 0 0
0 1 0 1 0 0
1 0 0 0 1 0
1 1 0 0 0 1
The Boolean functions for various output values are
c = a′ b′
d = a′ b
e = a b′ a′
f=a b c
00
b′
a′ d
b 01
a a e
b′ 10
b a f
11
Figure 3.27: 2 × 4 decoder
80
Principles of Logic
A decoder line would be selected if it has an output 1. In general, decoder is a Circuits I
very useful circuit for selecting lines and forms the basis of Random Access
Memory.
Please note that numbers of output for 2 bit decoder are 22 = 4; hence the name
2 × 4 decoder. Similarly, the number of output for a 3 bit input would be 23 = 8
and it is called 3 × 8 decoder.
3.7.3 Multiplexer
A multiplayer allows sharing of a line by multiple inputs. It may be very useful
for serialization of data bits over a single output line. The design of a
multiplexer is however, different from other combinational circuits as it is the
selection lines which control the selection of input line. The following is the
truth table of a 4 × 1 multiplexer. A 4 × 1 multiplexer selects one of the 4 input
lines to be transmitted over a single output. Out of these 4 lines, which will be
selected, will be determined by 2 selection lines. How many selection lines
will be required for 8 × 1 multiplexer? Since 23 = 8, so 3 selection lines would
be required for 8 × 1 multiplexer.
Input
Selection Lines Input Output
s1 s0
0 0 I0 I0
0 1 I1 I1
1 0 I2 I2
1 1 I3 I3
Please note the values of output can be Ii , where the value of subscript i can
vary from 0 to 3.
I0
0
s1
I1
1
s0 Output
I2 I0/I1/I2/I3
2
I3
3
81
Introduction to Digital Input Output
Circuits
I0 I1 I2 I3 O1 O0
1 0 0 0 0 0
0 1 0 0 0 1
0 0 1 0 1 0
0 0 0 1 1 1
Figure 3.29: Truth Table of 4 × 2 encoder
The simple expression for various output can be
O1 = I2 + I3
and O0 = I0 + I1 Thus, the simple circuit for this encoder is
I0
O0
I1
I2
O1
I3
Figure 3.30 Logic Diagram of a simple encoder
82
Principles of Logic
3.7.6 Read-only-Memory (ROM) Circuits I
ROM is an example of use of Programmable Logic Devices (PLD). It stores the
binary information using a combinational circuit. The RAM follows the simple
sequence. Figure 3.32 shows a ROM of size 4 × 2, which has 4 lines of 2 bits each.
Please note the use of 2 × 4 decoder. Also note that wherever the line will be
connected an output will appear. These connections are embedded within the
hardware. Thus the information of ROM is not lost even after the power failure..
A 1 A0
00
A1 01
2×4
A0 Decoder 10
11
O1 O0
3.8 SUMMARY
This Unit introduces you to some of the basic concepts relating to computer logic. The
Unit first introduces the concept of logic gates, the most fundamental unit of logic
circuits. The Unit then explains the process of making simple logic circuits, including
combinational circuit. The mathematical foundation of the logic circuit design, the
Boolean algebra is also introduced. The Karnaugh's map was used to design simpler
circuit. The Unit also explains the desing of different kinds of adders circuit,
highlghting , how complex circuit can be desingned using K-map. Finally, the Unit
explains some of the most fundamental combinational circuits like decoder,
multiplexer, encodes, PLA's etc. It may be noted that the objective of this Unit is not
to make you a computer hardware designer, but to introduce you to some of the basic
concepts of circuit design.
You can refer to latest trends of design and development including VHDL (a hardware
design language) in the further readings.
3. 9 SOLUTIONS/ANSWERS
3) F = ((A′+B) ′+(A.B′)′)′
= ((A′+B) ′)′ . ((A.B′)′)' (by Demorgan's Law)
= (A′+B) . (A.B′) (as (a')' = a)
= ((A′+B).A).( (A′+B).B')
= ((A'.A)+(B.A)).((A'.B')+B.B'))
= ((0+A.B).(A'.B' +0)
= (A.B.A'.B')=0
A' (A'+B)'
A F
(A.B')'
B'
B F
3) Simplify the following boolean functions in SOP and POS forms using K-Maps.
Draw the logic diagram for the resultant function.
F (A,B,C,D) = (0,2,5,7,12,13,15)
CD 00 01 11 10
AB
0 1 3 2
00 1 1
4 5 7 6
01 1 1
12 13
11 1 1 1 15 14
8 9 11 10
10
Three adjacencies
i) Cells 0 and 2: The variables does not change A' B' D'
ii) Cells 12 and 13; The variable does not change A B C'
iii) Cells 5,7,13,15; two variables does not change B D
The expression is F=A'.B'.D' + A.B.C' + B.D
Check Your Progress 3
1) The Truth table:
Decimal A B C D F
0 0 0 0 0 0
1 0 0 0 1 0
2 0 0 1 0 0
3 0 0 1 1 0
4 0 1 0 0 0
5 0 1 0 1 0
6 0 1 1 0 0
7 0 1 1 1 1
8 1 0 0 0 0
9 1 0 0 1 0
10 1 0 1 0 0
11 1 0 1 1 0
12 1 1 0 0 0
13 1 1 0 1 0
14 1 1 1 0 1
15 1 1 1 1 1
86
The K-map for the Truth table: Principles of Logic
Circuits I
CD 00 01 11 10
AB
0 1 3 2
00
4 5 7 6
01 1
12 13 15 14
11 1 1
8 9 11 10
10
(ii)
A
B
C F
B
C
D
3) (i) Input a is 1010 and input b is 1100 and mode bit is 0
Bit wise addition will be as follows:
a 1 0 1 0
b 1 1 0 0
c 0 0 0 0
sum bit 0 1 1 0
carry out of sign bit 1
carry in to sign bit NOT equal to carry out of sign bit,
OVERFLOW
(ii) Input a is 0010 and input b is 0100 and mode bit is 1
Bit wise addition will be as follows:
a 1 0 1 0
b (1's complement) 0 0 1 1
c 0 1 1 1
sum bit 1 1 1 0
carry out of sign bit 0
carry in to sign bit IS EQUAL to carry out of sign bit,
NO OVERFLOW
87
Introduction to Digital 4) PLA’s can be fabricated as a chip that can be customised as per the need of the
Circuits
SOP logic.
5) A half adder adds two addend bits, whereas a full adder adds the two addends
and previous carry bit, therefore, one half adder will be needed to add two
addend bits, and second half adder will be needed to sum the sum of first half
adder and previous carry bit. The output carry will be set, if any of the two half
adder produce the carry out. The following block diagram shows this
construction:
Carry in bit
Sum bit
A
Half Half
Adder Sum bit Adder
B
Carry out
88
Principles of Logic
UNIT 4 LOGIC CIRCUITS – SEQUENTIAL Circuits II
CIRCUITS
4.0 INTRODUCTION
The first Unit of this Block explained the basic structure and process of instruction
execution. Unit 2 provided a detailed description of data representation and Unit 3
presented the concepts of basic functional unit of a computer, viz. the logic gates and
combinational circuits. In this unit, you will be introduced to one of the most
fundamental circuit that can store one bit of data called flip flops. The unit also
explains how flip-flops and additional logic circuit can be used to make registers,
counters, sequential circuits etc. Finally, the Unit also introduces you to simple design
of a sequential circuit.
4.1 OBJECTIVES
After going through this unit you will be able to:
89
Introduction to Digital Figure 4.1 highlights that a sequential circuit may involve combinational circuits
Circuits
(which were discussed in Unit 3) the flip-flops (which are discussed in this unit) and a
system clock, which is a useful timing device of a computer system.
The sequential circuits are time dependent. The present state of a combinational
circuit is identified by the present output of flip-flop. This output may change over a
passage of time and can also be used as one of the input. This change in state can
occur either in synchronous or asynchronous manner with respect to system clock.
Synchronous circuits use flip-flops and their state can change only at discrete
intervals. Asynchronous sequential circuits are regarded as combinational circuit with
feedback path. Such circuits may unstable at times, when the propagation delays of
output to input are small. Thus, complex asynchronous circuits are difficult to design.
Clock Pulse and sequential circuits
A sequential circuit uses clock pulse generator, which gives continuous clock pulse to
synchronize change in the state of the circuit. Figure 4.2 shows the form of a clock
pulse.
Clock pulse
Figure 4.2: Clock signals of clock pulse generator
A clock pulse can have two states, viz. 0 or 1, which are also called disabled or active
state. Flip-flops are allowed to change their states, in general, with the rising or falling
edge of the clock pulse, so as to make stable changes in states of the flip-flops.
90
Principles of Logic
Circuits II
4.3.1 Latches
A basic latch can be constructed using either two NOR or two NAND gates. Figure
4.3 (a) shows logic diagram for S-R latch using NOR gates. This latch has two inputs
viz. S and R for Set and Reset respectively; and one output Q. Please note Q′ output is
complement of the output Q. This flip flop exhibits two states called SET state (when
the flip-flop output Q is1, that is Q′=0) and RESET state or clear state (Q=0; Q′=1).
R a Q
S R Q Q′ Comment
0 0 0/1 0/1 No Change in State
0 1 0 1 Reset State
1 0 1 0 Set State
S b Q′ 1 1 - Undefined Input
Let us examine the latch in more details. Assume that initially latch is in clear state,
i.e. Q=0 and Q′=1; also assume that both S and R input are 0. The states of the latch
will be as follows (refer to the NOR gate truth table given above):
Gate ‘a’
Input R Q′ :: 0 1 ⇒ Output (Q) 0
Gate ‘b’ Output of latch stays in CLEAR state
Input S Q :: 0 0 ⇒ Output (Q′) 1
91
Introduction to Digital (ii) Reset the latch:
Circuits
Now assume that input S remains at 0 and input R is changed to 1, also
assume that at this time the latch is in Set state (Q = 1 & Q′ = 0), then the
output of Gate ‘a’ will change as
Gate ‘a’
R Q′:: 1 0 ⇒ Q will become 0.
Gate ‘b’ Latch is in Reset state.
S Q :: 0 0 ⇒ Q′ will become 1
Once again, when S and R both input will become 0, latch will remain in
RESET state.
A basic S-R latch, in general, changes state at any time, which may result in
asynchronous changes in Q output, which can make system unstable.
Therefore, latches are constructed with controlled input using clock. This is
explained next.
SR latch with Clock
The following diagram shows an SR latch which changes its data only with the
occurrence of a clock pulse.
R
a Q
Clock
b Q′
S
SR latch
(a) Logic Diagram
S R Present State Qt Next State/Qt+1 Comments
Clock(c) before the clock after occurrence
pulse of clock pulse.
0 Any Any 0/1 0/1 No change in state
1 0 0 0/1 0/1 No change in state
1 0 1 0/1 0 Reset the latch
1 1 0 0/1 1 Set the flip-flop
1 1 1 0/1 - Not defined.
(b) Characteristic Table
92
D Latch Principles of Logic
Circuits II
The D (data) latch is modification of RS latch. D latch only uses one input named D, it
stores the value of D in the latch, e.g. if the D input is 1, then the next state of latch
will also be 1. Figure 4.4 shows the clocked D latch.
D
(a) Logic Diagram I (b) Characteristic Table
4.3.2 Flip-Flops
Latches suffer from the problem due to frequent changes of output, e.g. the output of
latch may change depending on the value of R and S input, which may change from 1
to 0 or vice-versa during a single clock pulse. Therefore, they are less suitable for
sequential circuits. Flip-flops add more circuitry in latches so that changes in states
occur during the rising or falling edge of clock pulse (these are called edge triggered
flip-flop). R-S latch with clock can be used with additional circuits to make R-S flip-
flop. The flip-flops can also be represented using a block diagram. Figure 4.6 shows
the block diagram of basic flip-flops. Please note that in the block diagram the arrow
head in front of the clock signal represents that the flip-flop will respond to input
during the leading or rising edge (when transition from 0 to 1 takes place) of the clock
S Q Q
D
Clock
R Q′ Clock Q′
J Q
T Q
Clock
K Clock Q′
Q′
93
Introduction to Digital JK flip is almost identical to SR flip-flop, except the last combination of J = 1 and K
Circuits
= 1 is used to complement the current state of the flip-flop. T-flip-flop is obtained by
joining the J and K input, thus, it shows just two input values. When T = 0, there is no
change of state and at T = 1, the current state is complemented. The following figure
shows the characteristics table for the basic flip-flops shown in Figure 4.7
SR Flip-flop JK Flip-Flop
S R Qt+1 Comments J K Qt+1 Comments
0 0 Qt No Change in state 0 0 Qt No Change in state
0 1 0 Clear state 0 1 0 Clear state
1 0 1 Set state 1 0 1 Set state
1 1 - Not Defined 1 1 Q′t Complement of Qt
D Flip-flop T Flip-flop
D Qt+1 Comments T Qt+1 Comments
0 0 Clear State 0 Qt No Change in state
1 1 Set State 1 Q′t Complement of Qt
Figure 4.7: Characteristic Table for flip-flops
Qt Qt+1 J K Qt Qt+1 S R
0 0 0 X 0 0 0 X
0 1 1 X 0 1 1 0
1 0 X 1 1 0 0 1
1 1 X 0 1 1 X 0
Qt Qt+1 D Qt Qt+1 T
0 0 0 0 0 0
0 1 1 0 1 1
1 0 0 1 0 1
1 1 1 1 1 0
94
a) The state transition from Qt = 0 to Qt+1= 0 Principles of Logic
Circuits II
(i) As both Qt and Qt+1 are 0 it means that there is no change in the state of
flip flop, which can be achieved by J=0, K=0;
(ii) Using the input, J=0, K=1, the flip flop can be RESET, i.e. Qt+1 = 0.
b) The state transition from Qt = 0 to Qt+1 = 1
(a) Using the input, J=1, K=0, the flip flop is SET, i.e. Qt+1 = 1
(b) Using the input, J=1, K=1, the flip flop is complemented from Qt having a
value 0 to Qt+1 = 1
c) State transition from Qt = 1 to Qt+1 = 0
(a) Using the input, J=0, K=1, flip flop is RESET, i.e. Qt+1 = 0
(b) Using the input, J=1, K=1, the flip flop is complemented from Qt having a
value 1 to Qt+1 = 0
The excitation table has been derived for J-K flip-flop as above. You may draw the
excitation table for all other flip-flops using the same method.
Check Your Progress 1
1. What is a sequential circuit? How are sequential circuits different from
combinational circuits?
.........................................................................................................................................
…………………………………………………………………………………………
…………………………………………………………………………………………
2. What is a latch? How is different from a flip-flop?
.........................................................................................................................................
…………………………………………………………………………………………
…………………………………………………………………………………………
3. What is an excitation table? Draw the excitation table for SR, D and T flip-
flops.
.........................................................................................................................................
…………………………………………………………………………………………
95
Introduction to Digital
Circuits
4.3.4 Master-Slave Flip-Flop
The master slave flip-flop is constructed using two or more latches. Figure 4.9 shows
how two S-R flip-flops can be used to construct a master-slave flip-flop.
Q
S S Q
Master Slave
R R Q′
Q′
Clock
Figure 4.9: Master – Slave flip- flop
You may please note that you can construct a master-slave flip-flop using D or JK
flip-flop also. This flip-flop consists of master which changes state when clock pulse
occurs. The slave flip flop goes to the state of master flip-flop when the clock signal is
0. (Refer to figure 4.9) This is explained below:
The flip-flop operates is two steps:
(i) When a clock pulse input is 1: As this time the Master flip-flop, based on the
value of S and R, goes to Set or Clear state as the case may be. At this time the
slave flip-flop cannot change its state as it receives the inverse of clock pulse.
Thus, on the occurrence of clock pulse ‘Master’ flip-flop goes to the next state
(Qt+1), whereas the output from slave flip-flop is the present state (Qt).
(ii) When the clock pulse input is 0: In this time the input to Master flip-flop will not
have any effect on the Master flip-flop output, which has been put in the next
state (Qt+1) in the previous step. However, now this Qt+1 output of master flip-flop
will be applied on the slave flip, which will result in transition of state of slave
flip flop to Qt+1. Thus, on completion of a clock cycle master and slave flip-flops
both will be in Qt+1. Please note that for slave flip flop only following transitions
are possible:
Q Q′ S R Q Q′
1 0 1 0 1 0 (Set)
0 1 0 1 0 1 (Reset)
No Change
in output No Change
in output
Positive …
Transition Negative Transition
(a) Positive edge-triggering (b) Negative edge triggering
Figure 4.10: Clock Pulse Signal
96
Principles of Logic
Circuits II
The following figure shows the block diagram of edge triggered D flip-flop.
D Q D Q
Clock Q′ O Clock Q′
97
State
Introduction to Digital Z=1 Z=1 Z=1
Circuits 00 01 10 11
Z=0 Z=0 Z=0 Z=0 Z=1
This circuit uses two bits to store the state, therefore, requires two flip-flops. The state
of the circuit changes to next state, when Z=1, else it stays in the same state. Thus, in
this sequential circuit, you require 2 flip-flops and one control signal Z. But, what
would be other input and output to this sequential circuit. Well! The other input will
be the current states of flip-flops which will govern the next states of flip-flops.
Next, you may take D flip-flop to design the circuit then a Rough design of the circuit
would be:
D Q
x X
Q′
Z
Dy Q
Y
Q′
In order to design the logic circuit, which generates the signal Dx and Dy, let us first
draw a truth table for flip-flop’s X and Y. This truth table is shown in the following
table:
Present States of Next State of
Required value of Dx for transition of
Flip-Flops Flip-Flops
X and Dy for the transition of Y
Flip-flops Input Flip-flops
Qt of Qt of Qt+1 of Qt+1 of
Z Dx Dy
X Y X Y
0 0 0 0 0 0 0 0
1 0 0 1 0 1 0 1
2 0 1 0 0 1 0 1
3 0 1 1 1 0 1 0
4 1 0 0 1 0 1 0
5 1 0 1 1 1 1 1
6 1 1 0 1 1 1 1
7 1 1 1 0 0 0 0
Interestingly, it is the Dx and Dy input that should be generated from the present state
and Z input, so that the Next state (Qt+1) of the flip-flops can be derived from the
present state of the flip-flop (Qt). Thus, for the design of counter circuit, you can draw
K-map for the design of Dx and Dy with input Qt (X), Qt (Y) and Z. TheK-maps for Dx
and Dy can be drawn as:
98
Principles of Logic
Circuits II
Dx Dy
Z Z
Qt (x)Qt(y) 0 1 Qt (x)Qt(y) 0 1
0 1 0 1
00 00 1
2 3 2 3
01
1 01 1
6 7
6 7
11 1
11 1
4 5
4 5
10 1 1 10 1
D Q
X
Q′
D Q
Y
Q′
Z
Figure 4.12: 2-bit counter
99
Introduction to Digital
Circuits 4.5 EXAMPLES OF SEQUENTIAL CIRCUITS
Let us now explain the basic function of some of the useful examples of sequential
circuits like registers, counters etc.
4.5.1 Registers
Registers are the basic storage unit of a computer. Since register temporarily
stores certain values, therefore, it requires flip-flops. The size of registers is
computed using number of bits it stores. One bit storage requires, at least, one
flip-flop. Thus, in general, an n bit register would use n flip-flops. Two
common operations on register are:
To load all bits of a register simultaneously or parallel load.
Shifting of bits, of register, towards left or right
Figure 4.13 shows a parallel load register..
I3 I2 I1 I0
Q Q Q Q
D3 D2 D1 D0
bit 3 bit 2 bit 1 bit 0
Clock
Signal
Clear
Signal
O3 O2 O1 O0
Shift register: Shift operation is very special operation for a computer ALU. A
shift register is capable of shifting the content of a register either to left or to
the right by one bit at a time. The following figure shows a right shift register,
however, you can construct a left shift register in a similar manner.
100
Principles of Logic
Circuits II
Input D3 D2 D1 D0
bit 3 bit 2 bit 1 bit 0
Shift enable
Clear Input
O3 O2 O1 O0
Figure 4.14: 4-bit Right Shift Register
I O3 O2 O1 O0
Before Shift 1 1 0 0 1
After Shift 1 1 1 0 0
A single registers can be included with the facility of left shift, right shift and
parallel load. Such a register is called bi-directional shift register with parallel
load. You may create its block diagram as an exercise.
101
Introduction to Digital
Circuits
Logical 1
Q Q
T T T
bit 0 bit 1 bit 2
Clock
O0 O1 O2
102
Principles of Logic
Q Circuits II
Q Q
Logical 1 T T T
bit 0 bit 1 bit 2
Clock Signal
O0 O1 O2
Read/Write′ (R/W′)
(a) Block Diagram
103
Introduction to Digital
Circuits
Select
Output
a K Q c
Input
b J Q
Read/Write′ (R/W′ )
The write operation as shown in the table above changes the content of
memory cell to the value of Input (I), or in other words memory cell has been
written into by the value of input (I).
104
Principles of Logic
Bit Bit Circuits II
1 0
Address of the
word 00 S
1 0
Input of
address Address of the
selection word 01 S
A2 × 4 Decoder
(2 lines)
1 0
Address of the
word 10 S
1 0
Address of the
word 11 S
1 0
Read/Write'
Bit Bit
1 0
Output
Figure 4.18: Two-dimensional Array based 4 2 RAM
The RAM has 4 words, which are decoded by the address decoder. Please note
as there are 4 words or lines, therefore, you require 2×4 decoder. This logic
can be extended, e.g. a RAM of size 1024×8, would require 10×1024 decoder
as 210 = 1024. So it will have 10 address lines which will decide which word of
the RAM array is to be selected.
For this implementation, the number of bits stored in each word would be 2
only, that is why every memory line will have 2 cells. Please note that for a
word size of 2 bits, the RAM array would require 2 input and 2 output lines.
For this memory array, in case an address 01 is given as input of address
selection bits, it will activate the Select input of cells of address 01 for read or
105
Introduction to Digital write operation. Please note that current RAM chip design is not a 2
Circuits
dimensional design as shown in Figure 4.18. It may follow a different more
optimal organization, discussion on which is beyond the scope of this unit.
Check Your Progress 3
1) What are the differences between synchronous & asynchronous counters?
.........................................................................................................................................
.........................................................................................................................................
.........................................................................................................................................
2) Is ripple counter same as shift register?
.........................................................................................................................................
.........................................................................................................................................
.........................................................................................................................................
3) Design a two bit counter, which has the states 00, 01, 10, 00, 01, 10…..
.........................................................................................................................................
.........................................................................................................................................
.........................................................................................................................................
4.6 SUMMARY
This unit introduces you the concepts of sequential circuits which is the foundation of
digital design. Flip-flops are also a sequential circuit and the basic storage unit of a
computer system. This unit also explains the working of a latch, which is the basic
circuit that can be used for storing one bit of information. The sequential circuit can
be formed using combinational circuits (discussed in the last unit) and flip flops. The
unit also discusses the construction of some of the important sequential circuits like
registers, counters, RAM. For more details, the students can refer to further reading.
106
Present State Next State Input S and R Input using DONOT Principles of Logic
Circuits II
(Qt) (Qt+1) CARE
(i) S=0, R=0
0 0 S=0, R=X
(ii) S=0, R=1
0 1 S=1, R=0 S=1, R=0
1 0 S=0, R=1 S=0, R=1
(i) S=0, R=0
1 1 S=X, R=0
(ii) S=1, R=0
D Flip-flop
Next State Input D Input using DONOT
Present State (Qt+1) CARE
(Qt)
0 0 D=0 D=0
0 1 D=1 D=1
1 0 D=0 D=0
1 1 D=1 D=1
T Flip-flop
Next State Input D Input using DONOT
Present State (Qt+1) CARE
(Qt)
0 0 T=0 T=0
0 1 T=1 T=1
1 0 T=1 T=1
1 1 T=0 T=0
2. No, shift register causes shifting of state of a flip-flop to next flip-flop, whereas
ripple counter is governed by the change of state.
00 01 10 00 01
Assuming the control signal, say Z , state transitions are:
State
Z=1 Z=1 Z=1
00 01 10
Z=0 Z=0 Z=0 Z=1
107
Introduction to Digital
Circuits
D Q
x X
Q′
Z
Dy Q
Y
Q′
Dx Dy
Z Z
Qt (x)Qt(y) 0 1 Qt (x)Qt(y) 0 1
0 1
0 1
00 00 1
2 3
2 3
01
1 01 1
6 7
6 7
11 X X
11 X X
4 5
4 5
10 1 1
10 1
108
Thus, the final counter circuit for the given states would be: Principles of Logic
Circuits II
D Q
X
Q′
D Q
Y
Q′
109
The Memory System
UNIT 5 THE MEMORY SYSTEM
Structure Page Nos.
5.0 Introduction
5.1 Objectives
5.2 The Memory Hierarchy
5.3 SRAM, DRAM, ROM, Flash Memory
5.4 Secondary Memory and Characteristics
5.4.1 Hard Disk Drives
5.4.2 Optical Memories
5.4.3 Charge-coupled Devices, Bubble Memories and Solid State Devices
5.5 RAID and its Levels
5.6 Summary
5.7 Answers
5.0 INTRODUCTION
In the previous block, fundamentals of a computer system were discussed. These
fundamentals included discussion on von-Neumann architecture based machines,
instruction execution, representation of digital data and logic circuits etc. This Block
explains the most important component of memory and Input/output systems of a
computer. This unit covers the details of the Memory. This unit discusses issues
associated with various components of the memory system, the design issues of main
memory and the secondary memory. Various characteristics of secondary memory and
its types that are used in a computer system, would also be discussed. The unit also
defines how multiple disks can be used to create a redundant array of disks that can be
used to provide a faster and reliable storage.
5.1 OBJECTIVES
After going through this Unit, you will be able to:
explain the key characteristics of various types of memories and memory hierar-
chy;
explain and differentiate among various types of random access memories;
explain the characteristics of secondary storage devices and technologies;
explain the latest secondary storage technologies;
identify the various levels of RAID technologies
In subsequent sections and next unit, we will discuss various types of memories in
more detail.
1. RAS (Row Address Strobe): On the falling edge of RAS signal, it opens or strobe
the address lines (rows) to be addressed.
2. /CAS (Column Address Strobe): Similar to /RAS, on the falling edge, this enables a
column to be selected as mentioned in the column address from the rows opened by
the /RAS to complete the read-write operation.
3. R/(/W), Write enable: This signal determines whether to perform a read operation
or a write operation. While the signal is low, write operation is enabled and data input
is also captured on falling edge of /CAS whereas high enables the read operation.
4. Sense amplifier compares the charge of the capacitor to a threshold value and
returns either logic “0” or logic “1”.
For a read operation once the address line is selected, transistor turns ON and opens
the gate for the charge of the capacitor to move to the bit line where it is sensed by the
sense amplifier. Write operation is performed by applying a voltage signal to the bit
line followed by the address line allowing a capacitor to be charged by the voltage
signal.
A block diagram of 2m× n ROM looks similar to that of RAM. As ROM is a read-only
memory there is no need of explicit read and write signals. Once the chip is selected
using chip select signals a data word is read and placed on to the data bus. Hence, in
the case of ROM, you need an unidirectional data bus i.e. only in output mode as
shown in figure 5.7. Another interesting fact about ROM is that, ROM offers more
memory cells and thus, memory as compared to the RAM for same size chip.
10
T Memory Syystem
The
m m
As shhown in Figu ure 5.7, 2 × n ROM has 2 words of n bits each foor which it haas m
addreess lines and n output datta lines. For example, in 128 × 8 ROM M, you have 128
memmory words off 8-bit each. For
F 128 × 8 ROM R i.e. 2m = 27, m = 7, yoou need 7 adddress
lines (minimum number
n of bitss required to represent
r 1288) and 8-bit ou
utput data buss.
Figurre 5.8 shows a 32×8 ROM M.
Flash Memory
Flash memory is a non-volatile semiconductor memory which uses the programming
method of EPROM and erases electrically like EEPROM. Flash memory was
designed in 1980s. Unlike, EEPROM where user can erase a byte using electrical
signals, a section of the memory or a set of memory words can be erasable in flash
memory and hence the name flash memory i.e. which erases a large block of memory
at once. Flash memory is easily portable and mechanically robust as there is no
mechanical movement in the memory to read-write data. Flash memory is widely used
in USB memory, SD and micro SD memory cards used in cameras and mobile phones
respectively.
There are two types of flash memory, viz. NAND flash memory, where read operation
is performed by paging the contents to the RAM i.e. only a block of data is accessed
not an individual byte or word; and NOR flash memory, which are able to read an
individual memory byte/word or cell.
Erase
Write Volatile/
Memory Type Mechanism/
Mechanism Non- Volatile
Level
Random-access
Read–Write Electrical/ Byte Electrical Volatile
Memory (RAM)
Read –only
Read–Only Not Applicable Masks Non-volatile
Memory (ROM)
Programmable
Read–Only Not Applicable Electrical Non-volatile
ROM (PROM)
Erasable PROM Read-
UV light/ Chip Electrical Non-volatile
(EPROM) mostly
Electrically
Read- Electrical/
Erasable Electrical Non-volatile
mostly Byte
(EEPROM)
Read- Electrical/
Flash memory Electrical Non-volatile
mostly Block
……………………………………………………………………………………
……………………………………………………………………………………
12
3. A memory has a capacity of 16K 16 The Memory System
(a) How many data input and data output lines does it have?
(b) How many address lines does it have?
……………………………………………………………………………………
……………………………………………………………………………………
4. A DRAM that stores 4K bytes on a chip and uses a square register array. Each
array is of size 4 bits. How many address lines will be needed? If the same
configuration is used for a chip which does not use square array, then how many
address lines would be needed?
………………………………………………………………………………………
………………………………………………………………………………………
5. How many RAM chips of size 256K 4 bit are required to build 1M Byte
memory?
……………………………………………………………………………………...
……………………………………………………………………………………...
13
Basic Computer Orga
anisation for writing.. HDD is coomposed of manym concenntric magneticc disks mounnted on a
central shaft
ft as shown in Figure 5.8.
Two motorss are used in HDD. First one o is called the spindle motor,
m which is used to
d motor is used to move
rotate the sppindle on whiich all the plattters are mouunted. Second
the read/write heads across the entire surface of the platter radially and is called The Memory System
actuator or access arm.
Magnetic Read and Write Mechanisms
During a read/ write operation, read/write head is kept stationary while platter is
rotated by the spindle motor. As you know, data on the disk is recorded in the form of
magnetic field. The current is passed through the read/write head which induces a
magnetic field on the surface of platter and thus, records a bit on the surface. Different
directions of current generates magnetic fields with different polarities and hence are
used for storing “1” and “0”. Similarly, to read a bit from the surface, the magnetic
field is sensed by the read/write head which produces an electric current of the same
polarity and hence the bit value is read.
Data Organization and Formatting
As discussed and shown in figure 5.8, hard disk drives consists of number of
concentric platters which are mounted on a spindle forming a cylindrical structure.
Data is written in the form of magnetic fields on both surfaces of these platters and is
read by read/write head which is connected to an actuator. In this section, we will
discuss structure of magnetic disk in detail.
Structure of the disk is shown in figure 5.10. As you know, each magnetic disk is a
circular disk mounted on a common spindle but entire disk space is not used for data.
Disk surface is divided in to thousands of concentric circular regions called tracks.
The width of every track is kept the same. Data is stored in these tracks. Magnetic
field of one track should not affect the magnetic region in the other track thus two
tracks are kept apart with each other by a constant distance. Further, each track is
divided into number of sectors and two sectors are kept apart using inter-sector gap.
Data is stored in these sectors. Each track forms a cylindrical structure with other
tracks on other platters below or above it. For example, an outer most cylinder will
have outer most track of all the platters. So, if we have n tracks in a platter then there
will be n concentric cylinders too.
Components of the drive are controlled by a disk controller. Now a days, disk
controllers are built in to the disk drive. A new or blank magnetic disk is divided into
sectors. Each sector has three components: header, 512 byte (or more) data area and a
trailer. This process of is called physical / low level formatting. Header and trailer
contains metadata about the sectors e.g. sector number, error correcting code etc. Disk
controller uses this information whenever it writes or reads a data item on to a sector.
Data is stored in series of logical blocks. The disk controller maps the logical blocks
on to the physical disk space and also manages sectors which have been used for
storing data and which are still free. This is done by the operating system after
partitioning the disk in to one or more groups of cylinders. Disk controller stores the
initial data structure file of every sector on to the disk. This data structure file contains
a list of used and free sectors, list of bad sectors etc. Windows uses File Allocation
Table (FAT) for the said purpose.
15
Basic Computer Orga
anisation
There are tw wo arrangemments with whhich platters aare divided innto tracks annd sectors.
The first arrrangement is called as connstant linear vvelocity (CLVV), in which thhe density
of bits per track
t is kept uuniform, i.e. outer tracks aare longer thaan the inner tracks
t and
hence contaains more num mber of sectoors and data. O Outermost traacks are generally 40%
longer than the innermosst track. In this arrangemennt, in order to o maintain unniform bit/
mong tracks, tthe rotation speed
data rate am s is increeased from ouutermost to innner most
track. This approach
a is used by CD-ROM and DVD D-ROM drivees.
In another approach
a callled as constaant angular velocity
v (CAV)
V), the densityy of bits /
data per track is decreassing as we move from innnermost trackk to outermost track by
keeping thee disk rotationn speed consttant. As disk is moving att a constant speed,s the
width of thee data bits inccreases in thee outer trackss, which resullts in the connstant data
rate. Figuree 5.10 shows that the widdth of sectors in outer traacks is increasing and
density of bits is decreasiing.
Disk Perforrmance
Data is readd and written on the disks by the operatting system for f usage at laater stage.
A disk storees the program ms and relateed data. How
wever, disk is a much slow wer device
and the proograms storedd on it cannoot be executeed by the prrocessing uniit directly.
Therefore, the
t programs and its related data, whicch are not in the main meemory, are
loaded in thhe main mem mory from thhe secondaryy storage. Sinnce, the speeed of disk
read/write iss very slow inn compared tot RAM, timee to read or write
w a byte from
fr or on
to the disk affects the coomputer overrall efficiencyy. Therefore, in a single read/write
r
operation on disk data ofo one or morre sectors is transferred
t too/from the meemory. An
operating syystem, in geneeral, request for
f read/writee to one or moore sectors onn the disk.
The time takken by the dissk to complette a read/ writte request of the
t operatingg system is
known as diisk access timme. There are number of faactors which affect the perrformance
of the disk. These factorss are:
1. Seek Tiime: It is deffined as a tim
me taken by tthe read/writee head, or simmply as a
head, to
o reach the desired
d track on which thee requested sector
s is locaated. Head
should reach
r the desired track in minimum tim
me. Shorter seeek time leadds to faster
I/O operration.
2. Rotationnal Latency: Since, every track consistts of a numbeer of sectors, therefore,
the readd/write operaation can beb completedd only when the desired sector is
availablle under the read/write head
h for the I/O operatio on. It dependds on the
rotational speed of the spindle and is defined as a time taken by a particular sector The Memory System
to get underneath the read/write head.
3. Data Transfer Rate: Since, large amount of data is transferred in one read/write
operation, therefore, the data transfer rate is also a factor for I/O operation. It is
defined as the amount of data read or written by the read/write head per unit time.
4. Controller overhead: It is the time taken by the disk controller for mapping logical
blocks to physical storage and keep track of which sectors are free and which are
used.
5. Queuing Delay: time spent waiting for the disk to be free.
The disk access time is defined as the summation of seek time, rotational latency, data
transfer rate, controller overhead and queuing delay and is given by the equation.
Out of the five parameters mentioned in the above equation, most of the time of the
disk controller goes in moving the read/write to the desired location and thus seeking
the information. If the disk access requests are processed efficiently then performance
of the system can be improved. The aim of disk scheduling algorithm is to serve all
the disk access requests with least possible head movement. There are number of disk
scheduling algorithms which are presented here in brief.
First Come First Serve (FCFS) scheduling: This approach serves the disk access
request in the order they arrived in the queue.
Shortest Seek Time First (SSTF) scheduling: Shortest Seek Time First disk scheduling
algorithm selects the request from the queue which requires least movement of the
head.
SCAN scheduling: The current head position and the head direction is the necessary
input to this algorithm. Disk access requests are serviced by the disk arm as disk arm
starts from one end of the disk and moves towards the other end. On reaching the
other end the direction of the head is reversed and requests are continued to be
serviced.
C-SCAN scheduling: Unlike SCAN algorithm, C-SCAN does not serve any request in
the return trip. Instead, on reaching to the end, it reverses back to the beginning of the
disk and then serves the requests.
LOOK scheduling: LOOK is similar to SCAN algorithm with only a single difference,
after serving the last request, LOOK algorithm does not go till the end instead it
immediately reverses its direction and moves to the beginning of the other end.
17
Basic Computer Orga
anisation Initially, theese optical stoorage devices commonly known
k as com
mpact disk (CDD) or CD-
DA (Digitall Audio) weree used to storre only audioo data of 60 minute
m duratiion. Later,
huge comm mercial succeess of CD leead to devellopment of low cost opptical disk
technology. These CDs can be used as auxiliary storage and can store anny type of
digital data. A variety off optical-disk devices have been introduuced. We brieffly review
some of these types.
Compact Disk
D ROM (C
CD-ROM)
Compact Disk
D or CD-R ROM are mad de of a 1.2 m mm thick sheeet of a polyycarbonate
material. Eaach disk surfaace is coated with a reflecctive materiall generally alluminium.
The standarrd size of a coompact disk is 120 mm in diameter. Ann acrylic coat is applied
on top of thee reflective suurface to prottect the disk fr
from scratchess and dust.
F
Figure 5.11:: Outer Layoout of a CD
Figure 5.112: Spiral traack of CD Figure 5.133: Land & Piit formation in CD trackk
• Sync: It is the first field in every sector. The sync field is 12 byte long. The
first byte of sync field contains a sequence of 0s followed by 10 bytes of all 1s
and 1 byte of all 0s.
• Header: Header is four byte field in the sector. Three bytes are used to
represent the sector address and one byte is used to represent the mode i.e.
how subsequent fields in the sector are going to use. There are 3 modes:
• Data: Data field contains the user 2048 byte of user data when mode is 1 or
mode 2.
• L-ECC: Layered error correcting code field is 288 byte long field which is
used for error detection and correction in mode 1. In mode 2, this field is used
to carry an additional 288 bytes of user data.
Solid state drives also known as solid state storage devices are based on flash memory.
As discussed, flash memory, a non-volatile type memory uses semiconductor devices
to store the data. The major advantage of SSD is that it is purely an electronic device
i.e. unlike HDD, SSD does not have mechanical read/ write head other mechanical
components. Hence, reading and writing through SSD is faster than HDD. Now a
days, SSD have replaced HDD in computer systems, however, SSD disks are more
expensive than HDDs.
……………………………………………………………………………………
2. What would be the rotation latency time for the disk specified above, if it has a
rotational speed of 6000 rpm?
……………………………………………………………………………………
……………………………………………………………………………………
3. What are the advantages and disadvantages of using SSD over HDD?
………………………………………………………………………………………………
………………………………………………………………………………
21
Basic Computer Organisation Another important factor for secondary storage is the reliability of data storage
system. Storing same data on more than one disks enhances reliability. If one disk
fails, then data can be accessed through another disk. Replicating data on multiple
disks is called mirroring. Mirroring brings redundancy in data. So many schemes have
been employed to enhance the performance and reliability of data and collectively
they are called as redundant arrays of inexpensive disks (RAID). Based on the trade-
off between reliability and performance RAID schemes have been categorises into
various RAID levels.
Data striping increases the data transfer speed as different data bytes are accessed in
parallel from different disks in a single disk access time. Whereas mirroring protects
data from disk failures. If one disk fails then same data is accessed from the copy of
the data stored in other disk.
RAID Levels
RAID Level-0: RAID level-0 implements block splitting of data with no protection
against disk failures. In block splitting, each block is stored in a different disk in the
array. For example, ith block of a file will be store in ( i mod n ) + 1 disk, where n is
the total number of disks in the array. In this case, a significant enhancement on the
performance can be observed as n blocks can be accessed (one each from each disk) in
a single disk access time.
22
The Memory System
b0 b1 b2 b3 Parity(b)
RAID Level-4: This level uses block striping and one disk is used to keep parity
block. This is also called block-interleaved parity organization. The advantage of
block interleaving is that parity block along with corresponding blocks on other disks
is used to retrieve the damaged block or the blocks of the failed disk. Unlike in level-
3, block access reads one disk which allows parallel access to other blocks stored in
other disks in the array.
23
Basic Computer Organisation RAID Level-5: This level stores block of data and parity in all the disks in the array.
One disk store the parity while data is spread out on different disks in the array. This
structure is also known as block-interleaved distributed parity.
24
a) All member disks The Memory System
participate in every I/O
request.
b) Synchronizes the
spindles of all the disks
to the same position. Not useful for
Parallel
2 c) The blocks are very Poor Excellent commercial
Access
small in size (Byte or purposes.
word).
d) Hamming code is
used to detect double-
bit errors and correct
single-bit error.
a) Parallel access as in
level 2, with small data
Large I/O request
blocks.
Parallel size application,
3 b) A simple parity bit is Poor Excellent
Access such as imaging
computed for the set of
CAD
data for error
correction.
a) Each member disk
operates independently,
which enables multiple
input/output requests in
parallel. Not useful for
Independent Excellent/ Fair /
4 b) Block is large and commercial
access fair poor
parity strip is created purposes.
for bits of blocks of
each disk.
c) Parity strip is stored
on a separate disk.
a) Allows independent
access as in level 4.
b) Parity strips are
distributed across all High request rate
Independent Excellent Fair /
5 disks. read intensive,
access / fair poor
b) Distribution avoids data lookup
potential input/output
bottleneck found in
level 4.
Also called the p+q
redundancy scheme, is
Application
much like level 5, but
Independent Excellent/ Fair / requiring
6 stores extra redundant
access poor poor extremely high
information to guard
availability
against multiple disk
failures.
……………………………………………………………………………………
……………………………………………………………………………………
5.6 SUMMARY
This unit introduces the concept of memory hierarchy, which is primarily required due
to the high cost per bit of high speed memory. The processing unit have register,
cache, main memory and secondary or auxiliary memory. The main memory consists
of RAM or ROM. This unit explains the logic circuit and organisation of RAM and
ROM. The unit also explains several different types of secondary storage memories.
The unit provide details on hard disk and its characteristics. It also gives details of
different kind of optical disk. The concept of access time and constant linear and
angular velocity has also been explained in details. For larger computer systems
simple hard disk is not sufficient, rather an array of disks called RAID are used for
such systems to provide good performance and reliability. The concept of RAID and
various levels of RAID has been defined in this unit. The next unit will introduce you
to the concept of high speed memories.
5.7 ANSWERS
26
2. The time of one rotation = 1/6000 min = 60/6000 sec = 1/100 sec= 10 millisec The Memory System
Rotational latency = on an average time of half rotation = 5 ms
3. SSD drives does not require any mechanical rotation, therefore are less prone to
failure. In addition, they are much faster than HDD. But they are more expensive
than HDD
4. The size of sectors on CLV disks is same on the entire disk, therefore, these disks
are rotated a different speed. Density of data is same in all the sectors. In CAV
disks the rotation speed is same, thus, sector size is more in the outer tracks.
However, reading/writing process, in general, is faster.
Check Your Progress 3
1. RAID are a set of storage devices put together for better performance and
reliability. Different kind of RAID levels have different objectives.
3. Large number of I/O requests are fulfilled by RAID level 0, 1, 4,5 ,6.
27
The Memory System
UNIT 6 ADVANCE MEMORY
ORGANISATION
Structure Page Nos.
6.0 Introduction
6.1 Objectives
6.2 Locality of Reference
6.3 Cache Memory
6.4 Cache Organisation
6.4.1 Issues of Cache Design
6.4.2 Cache Mapping
6.4.3 Write Policy
6.5 Associative Memory
6.6 Interleaved Memory
6.7 Virtual Memory
6.8 Summary
6.9 Answers
6.0 INTRODUCTION
In the last unit, the concept of Memory hierarchy was discussed. The Unit also
discussed different types of memories including RAM, ROM, flash memory,
secondary storage technologies etc. The memory system of a computer uses variety of
memories for program execution. These memories vary in size, access speed, cost and
type, such as volatility (volatile/ non-volatile), read only or read-write memories etc.
As you know, a program is loaded in to the main memory for execution. Thus, the size
and speed of the main memory affects the performance of a computer system. This
unit will introduce you to concepts of cache memory, which is small memory between
the processing unit and main memory. Cache memory enhances the performance of a
computer system. Interleaved memory and associative memories are also used as
faster memories. Finally, the unit discusses the concept of virtual memory, which
allows programs larger than the physical memory.
6.1 OBJECTIVES
After going through this Unit, you will be able to:
explain the concept of locality of reference;
explain the different cache organisation schemes;
explain the characteristics of interleaved and associative memories;
explain the concept of virtual memory.
5
Basic Computer Orga
anisation The importaant task of a computer
c is to
t execute insstructions. It has
h been observed that
on an average 80-85 percent of thee execution ttime is spennt by the proocessor in
accessing thhe instructionn or data fromm the main mmemory. The situation
s becoomes even
worst whenn instruction tto be executeed or data to be processedd is not present in the
main memoory.
Another facctor which has been observved by analyssing various programs
p is thhat during
the programm execution, the processsor tends to access a seection of thee program
instructions or data for a specific timee period. For example, wh hen a program m enters in
a loop struccture, it conttinues to acceess and execute loop stattements as loong as the
looping conndition is satiisfied. Similaarly, wheneveer a program calls a subrooutine, the
subroutine statements
s aree going to exxecute. In another case, when
w a data ittem stored
in an array or
o array like sstructure is acccessed then it is very likeely that eitherr next data
item or prevvious data iteem will be accessed by thee processor. AllA these phennomenons
are known as
a Locality off Reference orr Principle off Locality.
So, accordinng to the priinciple of loccality, for a specific timee period, the processor
tends to maake memory references
r cloosed to each oother or accesses the samee memory
addresses again
a and again. The earrlier type is known as sppatial locality ty. Spatial
locality speccifies if a datta item is acccessed then daata item storeed in a nearbyy location
to the data item just acccessed may be b accessed inn near futuree. There can bbe special
case of spaatial locality, which is terrmed as sequuence localityy. Consider a program
accesses thee elements oof a single dim mensional arrray, which is a linear data structure,
in the sequeence of its inddex. Such acccesses will reead/write on a sequence of memory
locations onne after the otther. This typee of locality, which
w is a case of spatial locality,
l is
referred to as
a sequence loocality.
Another typpe of localitty is the tem mporal localiity, if a dataa item is accessed or
referenced at
a a particularr time, then thhe same data item is expected to be acccessed for
i near future. Typically it is observedd in loop stru
some time in uctures and subroutine
s
call.
As shown in n Figure 6.1, when the proogram enters iin the loop strructure at linee 7, it will
execute the loop statemeents again andd again multipple times till the loop termminates. In
this case, processor
p needs to access instructions 9 and 10 freequently. On the other
hand, when a program acccesses a dataa item store inn an array, thhen in the nexxt iteration
it accesses a data item stoored in an adjjacent memorry location to the previous one.
If you keep the content of the cluster of expected memory references in a small,
extremely fast memory then processing time of an instruction can be reduced by a
significant amount. Cache memory is a very high speed and expensive memory as
compared to the main memory and its access time is closer to the processing speed of
the processor. Cache memory act as a buffer memory between the processor and the
main memory.
Because cache is an expensive memory so its size in a computer system is also very
small as compared to the main memory. Thus, cache stores only those memory
clusters containing data/ instructions, which have been just accessed or going to be
accessed in near future. Data in the cache is updated based on the principle of locality
explained in the previous section.
Data in main memory is stored in the form of fixed size blocks/pages. Cache memory
contains some blocks of the main memory. When processor wants to read a data item
from the main memory, a check is made in the cache whether data item to be accessed
is present in the cache or not. If data item to be accessed is present in the cache then it
is read by the processor from the cache. If data item is not found in the cache, a
memory reference is made to read the data item from the main memory, and a copy of
the block containing data item is also copied into the cache for near future references
as explained by the principle of locality. So, whenever processor attempts to read the
data item next time, it is likely that the data item is found in the cache and saves the
time of memory reference to the main memory.
As shown in the Figure 6.2, if requested data item is found in the cache it is called as
cache hit and data item will be read by the processor from the cache. And if requested
data item is not found in cache, called cache miss, then a reference to the main
memory is made and requested data item is read and block containing data item will
also be copied into the cache.
7
Basic Computer Organisation Average access time for any data item is reduced significantly by using cache then
without using cache. For example, if a memory reference takes 200 ns and cache takes
20 ns to read a data item. Then for five continuous references will take:
Time taken with cache : 20 (for cache miss) + 200 (memory reference)
+ 4 x 20 (cache hit for subsequent access)
= 300 ns
Effective access time is defined as the average access time of memory access, when a
cache is used. The access time of memory access is reduced in case of a cache hit,
whereas it increases in case of cache miss. In the above mentioned example processor
takes 20 + 200 ns for a cache miss, whereas it takes only 20 ns for each cache hit.
Now suppose, we have a hit ratio of 80%, i.e. 80 percent of times a data item would
be found in the cache and 20 % of the times it would be accessed from the main
memory. So effective access time (EAT) will be computed as :
effective access time = (cache hit x data access time from cache only )
+(cache miss x data access time from cache and main memory)
From the example it is clear that cache reduces the average access time and effective
access time for a data item significantly and enhance the computer performance.
3. Hit ration of computer system is 90%. The cache has an access time of 10ns,
whereas the main memory has an access time of 50ns. Computer the effective
access time for the system.
……………………………………………………………………………………
……………………………………………………………………………………
……………………………………………………………………………………
8
The Memory System
Cache is an extremely fast but very expensive memory as compared to the main
memory. So large cache memory may shoot up the cost of the computer system and
too small cache might not be very useful in real time. So, based on various statistical
analyses, if a computer system has 4 GB of main memory then the size of the cache
may go up to 1MB.
What would be the block size for data transfer between cache and main memory?
Block size directly affects the cache performance. Higher block size would ensure
only fewer number of blocks in cache, whereas small block size contains fewer data
items. As you increase the block size, the hit ratio first increases but it decreases as
you further increase the block size. Further increase in block size will not necessarily
result in access of newer data items, as probability of accessing data items in the block
with larger number of data items tends to decrease. So, optimal size of the block
should be chosen to maximise the hit ratio.
As execution of the process continues, the processor requests for new data items. For
new data items and thus, new blocks to be present in the cache, the blocks containing
old data items must be replaced. So there must be a mechanism which may select the
block to be replaced which is least likely to be needed in near future.
When changes in the blocks will be written back on to the main memory?
During the program execution, the value of a data item in a cache block may get
changed. So the changed block must be written back to the main memory in order to
reflect those changes to ensure data consistency. So there must be a policy, which may
decide when the changed cache block is written back to the main memory.
In certain computer organisations, the cache memory for data and instruction are
placed separately. This results in separate address spaces for the instructions and data.
These separate caches for instructions and data are known as instruction cache and
data cache respectively. If processor requests an instruction, then it is provided by the
instruction cache, whereas requested data item is provided by the data cache. Using
separate cache memories for instruction and data enhances computer performance.
While some computer systems implements different cache memories for data and
instructions other implements multiple level of cache memories. Two level cache
popularly known as L1 cache and L2 cache is most commonly used. Size of level 1
cache or L1 cache is smaller than the level 2 or L2 cache. Comparatively more
frequently used data/ instructions are stored in L1 cache.
9
Basic Computer Organisation
As discussed earlier, the main memory is divided into blocks/ frames/ pages of k
words each. Each word of the memory unit has a unique address. A processor requests
for read/write of a memory word. When a processor's request of a data item cannot be
serviced by cache memory, i.e. a cache miss occurs, the block containing requested
data item is read from the main memory and a copy of the same is stored in cache
memory. A cache memory is organised as a sequence of line. Each cache line is
identified by a cache line number. A cache line stores a tag and a block of data. Cache
and main memory structure is shown in Figure 6.3. General structure of cache
memory having M lines and N=2n main memory size is shown in figure 6.3(a) and
figure 6.3(b) respectively.
(a) Cache structure
(b) Main Memory structure
Figure 6.3: Structure of Cache and Main Memory
An example of cache memory of size 512 words is shown in Figure 6.4. The example
shown in Figure 6.4 has a main memory of 64 K words of 16 bits each and cache
10
memory can have 512 words of 16 bits each. To read a data item processor sends a 16 The Memory System
bit address to the cache and if cache misses then the data item/ word is fetched from
the main memory and accessed data item/ word is also copied into the cache. Please
note that the size of block is just 1 memory word in this case.
Main Memory Block Address ((n-k) bits) Block address size (k bits)
((n-k)-m) bits for tag m bits to identify the Cache line Block address size (k bits)
Now, the following steps will be taken by the processing logic of processing unit and
hardware of Cache memory:
1. The tag number (FE in this case) is compared against the Tag number of data
stored in the cache line (DCB in this case).
2. In case both are identical
then (this is the case of cache hit): Ath word from the cache line DCB is
accessed by the processing logic.
else (this is a case of cache miss): The cache line 16 words data is read to
cache memory line (DCB) and its tag number is now FE. The
required Ath word is now accessed by the processing logic
Direct mapping is very easy to implement but has a disadvantage as location in which
a specific block is to be stored in cache is fixed. This arrangement leads to low hit
ratio as when processor wants to read two data items belongs to two different blocks,
which map to single cache location, then each time other data item is requested, the
block in the cache must be replaced by the requested one. This phenomenon is also
known as thrashing.
Associative Mapping:
Associative mapping is the most flexible mapping in cache organisation as it allows to
store any block of the main memory in any of the cache line/or location. It uses
complete (n-k) bits of block address field as a tag field. Cache memory stores (n-k)
bits of Tag and (2k × Word Size in bit) data. When a data item/ word is requested, (n-
k) bit tag field is used by the cache control logic to search the all the tag fields stored
in the cache simultaneously. If there is a match (cache hit) then corresponding data
item is read from the cache, otherwise (cache miss) the block of data that contains the
word to be accessed is read from the main memory. It replaces any of the cache line.
In addition, the block address of the accessed block from the main memory replaces
the tag of the cache line. It is also the fastest mapping amongst all types. Different
block replacement policies are used for replacing the existing cache content by newly
read data, however, those are beyond the scope of this unit. This mapping requires
most complex circuitry, as it requires all the cache tags to be checked simultaneously
with the block address of the access request.
Main Memory Address :
Address bits for identifying
Address of a block of data is same as Tag
a word in a Block
(n-k) bits k bits
13
Basic Computer Organisation
Tag Data Block of k words
14
Cache mapping logic uses d-bits to identify the set as 𝑣 2 and ((n-k)-d)) bits are The Memory System
used to represent the tag field. In set-associative mapping, a block j can be stored at
any of the cache line of set i. To read a data item, the cache control logic first
simultaneously looks into all the cache lines using ((n-k)-d)) bits of tag field of the set
identified by d-bits of the set field, otherwise a data item is read from the main
memory and corresponding data is copied into the cache accordingly. Set associative
mapping is also known as w-way set-associative mapping. It uses lesser number of
bits (((n-k)-d) bits) as compare to (n-k) bits in associative mapping in tag field.
A comprehensive example showing possible locations of main memory blocks
in Cache for different cache mapping schemes is discussed next.
A word like 00011110 can in any cache line, for example, in the cache memory
shown above it is in line 2 and can be accessed.
(iii) 2way set associative Mapping:
The size of cache = 32 bytes
The block size of main memory = words in one line of cache =4 ⇒ k=2 bits
The number of lines in a set (w) = 2 (this is a 2 way set associative memory)
The number of sets (v) = Size of cache in words/(words per line × w )
= 32/(4×2) =4
Thus, set number can be identified using 2 bits as 22 = 4
17
Basic Computer Organisation Tag size = (n-k)-v = (8 - 2) - 2 = 4
The address mapping for an address: 11111101
Block Address of Main Memory Address of a word in a
Block
1111 11 01
1111 11 01
Tag Set Number
Set number = 11 = 3 in decimal
Tag = 1111
The address mapping for an address: 00001011
Block Address of Main Memory Address of a word in a
Block
0000 10 11
0000 10 11
Tag Set Number
Set number = 10 = 2 in decimal
Tag = 0000
• Caches and main memory can be altered by multiple processes which may
result in inconsistency in the values of the data item in cache and main
memory.
18
The Memory System
• If there are multiple CPUs with individual cache memories, data item written
by one processor in one cache may invalidate the value of the data item in
other cache memories.
These issues can be addressed in two different ways:
1. Write through: This writing policy ensures that if a CPU updates a cache,
then it has to write/ or make the changes in the main memory as well. In
multiple processor systems, other CPUs-Cache need to keep an eye over the
updates made by other processor's cache into the main memory and make
suitable changes accordingly. It creates a bottleneck as many CPUs try to
access the main memory.
2. Write Back: Cache control logic uses an update bit. Changes are allowed to
write only in cache and whenever a data item is updated in the cache, the
update bit of the block is set. As long as data item is in the cache no update is
made in the main memory. All those blocks whose update bit is set is replaced
in the main memory at the time when the block is being replaced in the cache.
This policy ensures that all the accesses to the main memory are only through
cache, and this may create a bottleneck.
You may refer to further readings for more details on cache memories.
Check Your Progress 2
1. Assume that a Computer system have following memories:
RAM 64 words with each word of 16 bits
Cache memory of 8 Blocks (block size of cache is 32 bits)
Find in which location of cache memory a decimal address 21 can be found if
Associative Mapping is used.
……………………………………………………………………………………
……………………………………………………………………………………
2. For the system as given above, find in which location of cache memory a decimal
address 27 will be located if Direct Mapping is used.
…………………………………………………………………………………………
………………………………………………………………………………
3. For the system as given above, find in which location of cache memory a decimal
address 12 will be located if two way set associative Mapping is used.
……………………………………………………………………………………
……………………………………………………………………………………
Hardware Organization
Associative memory consists of a memory array and logic for m words with n bits per
word as shown in block diagram in Figure 6.15. Both argument register (A) and key
register (K) have n bits each. Each bit of argument and key register is for one bit of a
word. The match register M has m bits, one each for each memory word.
The key register provides a mask for choosing a particular field or key in the argument
word. The entire argument is compared with each memory word only if the key
register contains all 1s. Otherwise, only those bits in the argument that have 1s in their
corresponding positions of the key register are compared. Thus, the key provides a
mask or identifying information, which specifies how reference to memory is made.
The content of argument register is simultaneously matched with every word in the
memory. Corresponding bits in the mach register is set by the words that have match
with the content of the argument register. Set bits of the matching register indicates
that corresponding words have a match. Thereafter, memory is accessed sequentially,
to read only those words whose corresponding bits in the match register have been set.
21
Basic Computer Organisation
Example: Consider an associative memory of just 2 bytes. The content register and
argument registers are also shown in the diagram.
Please note as four most significant bits of key register are 1, therefore only they are
matched.
22
Let us say, you have a main memory of size 256K (218)words. This requires 18-bits to The Memory System
specify a physical address in main memory. A system also has an auxiliary memory as
large as the capacity of 16 main memories. So, the size of the auxiliary memory is
256K ×16 = 4096 K which requires 24 bits to address the auxiliary memory. A 24-bit
virtual address will be generated by the processor which will be mapped into an 18-bit
physical address by the address mapping mechanism as shown in Figure 6.17.
6.8 SUMMARY
This unit introduces you to the concept relating to cache memory. The unit defines
some of basic issues of cache design. The concept of cache mapping schemes were
explains in details. The direct mapping cache uses simple modulo function, but has
limited use. Associative mapping though allows flexibility but uses complex circuitry
and more bits for tag field. Set-associative mapping uses the concept of associative
and direct mapping cache. The unit also explain the use of memory interleaving,
which allows multiple words to be accessed in a single access cycle. The concept of
23
Basic Computer Organisation content addressable memories are also discussed. The cache memory, memory
interleaving and associative memories are primarily used to increase the speed of
memory access. Finally, the unit discusses the concept of virtual memory, which
allows execution of programs requiring more than physical memory space on a
computer. You may refer to further readings of the block for more details on memory
system.
6.9 ANSWERS
Check Your Progress 1
In set associative memory the given tag can be stored in any of the 8
lines.
2. Main memory size = 64 words (a word = 16 bits) = 26 ⇒ n=6 bits
Block Size = 32 bits = 2 words = 21 ⇒ k=1 bit
The size of cache = 8 blocks of 32 bits each = 8 lines ⇒ m=3 bits
Tag size for direct mapping = (n-k) - m = (6 - 1) - 3 = 2
The address mapping for an address: 27 in decimal that is 011011
1. Memory interleaving divides the main memory into modules. Each of these
module stores the words of main memory as follows (example uses 4 modules
and 16 word main memory.
Module 0: Words 0, 4, 8, 12 Module 1: Words 1, 5, 9, 13
Module 2: Words 2, 6, 10, 14 Module 3: Words 3, 7, 11, 15
Thus, several consecutive memory words can be fetched from the interleaved
memory in one access. For example, in a typical access words 4, 5, 6, and 7 can
be accessed simultaneously from the Modules 0, 1, 2 and 3 respectively.
2. Associative memory do not use addresses. They are accessed by contents. They
are very fast.
25