Chapter 2 OfArch
Chapter 2 OfArch
Flip-Flops
The simplest form of sequential circuit is the flip-flop. There are a variety of flip
flops, all of which share two properties:
The flip-flop is a bi-stable device, i.e. has two stable states. It exists in one
of two states and, in the absence of input, remains in that state. Thus, the
flip-flop can function as a 1-bit memory.
The flip-flop has two outputs, which are always the complements of each
other. These are generally labeled Q and . Q
Q
First, let us show that the circuit is bistable. Assume that both S and R are 0 and
that Q is 0. The inputs to the lower NOR gate are and Thus, the output means that
the inputs to the upper NOR gate are Q = 0 and S = 0. Thus the output =1
Q the inputs to the upper NOR gate are
means that = 1 and R = Q0 which has the
output Q = 0. Thus, the state of the circuit is internally consistent and remains
stable as long as S = R = 0. A similar line of reasoning shows that the state Q = 1,
= 0 is also stable
Q for R = S = 0.
Thus, this circuit can function as a 1-bit memory. We can view the output Q as the
“value” of the bit. The inputs S and R serve to write the values 1 and 0,
Q
1
Q
respectively, into memory. To see this, consider the state Q = 0, = 1, S = 0, R =
0. Suppose that S changes to the value 1. Now the inputs to the lower NOR gate
are S = 1, Q = 0. After some time delay Δt, the output of the lower NOR gate will
be Q = 0 (see Figure 1-14). So, at this point in time, the inputs to the upper NOR
gate become R = 0, = 0.
The S–R latch can be defined with a table similar to a truth table, called a
characteristic table, which shows the next state or states of a sequential circuit as a
function of current states and inputs. In the case of the S–R latch, the state can be
defined by the value of Q. Table 1-6a shows the resulting characteristic table.
Observe that the inputs S = 1, R = 1 are not allowed, because these would produce
an inconsistent output (both Q and equal 0).
D Flip-Flop
One problem with S–R flip-flop is that the condition must be avoided. One way to
do this is to allow just a single input. The D flip-flop accomplishes this.
The D flip-flop is sometimes referred to as the data flip-flop because it is, in effect,
storage for one bit of data. The output of the D flip-flop is always equal to the most
recent value applied to the input. Hence, it remembers and produces the last input.
D Qn+1
0 0
1 1
2
J–K Flip-Flop
Like the S–R flip-flop, it has two inputs. However, in this case all possible
combinations of input values are valid. Note that the first three combinations are
the same as for the S–R flip-flop. With no input asserted, the output is stable. If
only the J input is asserted, the output is stable. If only the J input is asserted, the
result is a set function, causing the output to be 1; if only the K input is asserted,
the result is a reset function, causing the output to be 0.When both J and K are 1,
the function performed is referred to as the toggle function: the output is reversed.
Thus, if Q is 1 and 1 is applied to J and K, then Q becomes 0.
T flip flop
Another type of flip flop found in sequential circuit is toggle flip flop. This flip
flop is obtained from a JK type when inputs J and K are connected to provide a
single input designated by T. the T flip flop therefore has only two conditions.
When T= 0(J=K=0) a clock transition does not change the state of the flip flop.
When T=1(J=K=1) a clock transition complements the state of the flip flop. These
conditions can be expressed by a characteristics equation:
3
Basic flip-flops
Registers
As an example of the use of flip-flops, let us first examine one of the essential
elements of the CPU: the register. As we know, a register is a digital circuit used
within the CPU to store one or more bits of data. Two basic types of registers are
commonly used: parallel registers and shift registers.
4
PARALLEL REGISTERS A parallel register consists of a set of 1-bit memories
that can be read or written simultaneously. It is used to store data.
SHIFT REGISTER A shift register accepts and/or transfers information serially.
Shift registers can be used to interface to serial I/O devices. In addition, they can
be used within the ALU to perform logical shift and rotate functions.
Counters
Another useful category of sequential circuit is the counter. A counter is a register
whose value is easily incremented by 1 modulo the capacity of the register; that is,
after the maximum value is achieved the next increment sets the counter value to 0.
Thus, a register made up of n flip-flops can count up to An example of a
counter in the CPU is the program counter.
5
Chapter 2
Data Representation
Data in computers is represented in binary form. The represented data can be
number, text, movie, color (picture), sound, or anything else. It is up to the
application software that presents the data to portray the data accordingly. We
enter data into a computer using letters, digits & special symbols. But inside the
computer, there is no color, letter, digit or any other character inside the computer
system unit.
Just like any other electrical device, computers understand and respond to only the
flow of electrical charge. They also have storage devices that work based on
magnetism. This shows that the overall structure of computers work only in binary
conditions (the semi-conductors are conducting or not conducting, a switch is
closed or opened, a magnetic spot is magnetized or demagnetized). Hence, data
must be represented in the form of binary code that has a corresponding electrical
signal.
The form of binary data representation system we are seeking is similar to the
binary number system in mathematics. Nevertheless we humans are not
accustomed to the use of binary numbers. The main focus of this chapter is on how
data is represented in computers. Since understanding of binary number system is
essential to understand binary data representation, conversion of numbers from a
given number base to another base, is also discussed here. The number systems
(bases) we will discuss are: decimal, binary, octal, and hexadecimal.
6
BIT
BYTE
This large unit is called a byte and is the basic “unit of data representation”
in a computer system
Bits can be organized into large units to make them represent more and
meaningful information;
The commonly used byte contains 8 bits
Since each bit has two states and there are 8 bits in a byte, the total amount
of data that can be represented is 28 or 256 possible combinations;
Each byte can represent a character (a character is either a letter, a number or
a special symbol such as +,-,?,*, $, etc
A byte is then used as a unit of measurement in the computer memory,
processing unit, external storage and during communication;
If the computer memory is 524288 byte, this is expressed in short by saying
512KB, where KB stands for kilobyte.
1 Kilobyte(1KB) is 210 or 1024 bytes
1 Megabyte(MB) is 220 bytes or 210 kilobytes
1 Gigabyte(GB) is 230 bytes or 220 kilobytes or 210 megabytes
WORD
7
Word refers the number of bits that a computer process at a time or a
transmission media transmits at a time
Although bytes can store or transmit information, the process can even be
faster if more than one byte is processed at a once;
A combination of bytes, then form a “word”
A word can contain one, two, three or four bytes based on the capacity of the
computer
Word length is usually given in bits
We say that a computer is an 8-bits, a 16 bit, a 32 bit or a 64 bit computer to
indicate that the amount of data it can process at a time;
The large the word length a computer has the more powerful and faster it is.
I. Non-positional number system: The symbols of the number have the same
value regardless of its position in the number. The value of a symbol (digit) in a
number does not depend on the position of the digit in number.
II. Positional number system: The value of a symbol in the number is determined
by its position, the symbol and the base of the number system. In all positional
number systems, the base has the following properties
1. It determines the number of different symbols it has. For example, there are
10 different symbols in base 10 (decimal) number system and there are 2
symbols in base 2 (binary) number system.
2. The maximum value of a single digit is one less than the base value. For
example, the largest single digit number in the decimal (base 10) number
system is 9.
3. The positional value of each symbol is expressed by the power of the base.
For example, the value of the symbol 7 in the decimal number 75 is 70
(7×101) while the value of 7 in the decimal number 756 is 700 (7×10 2). The
source of the variation is the position of the digit in the number and this
value is expressed as a multiple of powers of the base.
The decimal number system, also called the base 10 number system, is the number
system we use in our day-to-day life. The preference of this number system by
humans is attributed to their nature that humans have 10 fingers. It is believed that
humans start counting using their fingers. This fact is the basis for the preference
of the decimal number system by humans.
We can associate the two digits of the binary number system with two states of
electrical systems, magnetic systems, and switches. The following table shows the
conventional association. It is also possible to exchange the association but it
becomes confusing since it is the opposite of the convention (what is agreed on).
0 1
Electronic No current There is
current
Magnetic Demagnetized Magnetized
Switch Off On
9
Data representation using the binary number system results in a large string of 0s
and 1s. This makes the represented data large and difficult to read. Writing such a
binary string becomes tedious as well. For the sake of writing the binary strings in
a short hand form and make them readable, the octal and the hexadecimal number
systems are used.
Octal number system, also called base 8 number system, has 8 different symbols:
0, 1, 2, 3, 4, 5, 6, and 7. The octal number system is used to write binary numbers
in short form. An octal number has about one-third of the digits in its binary
equivalent.
The hexadecimal number system, also called base 16 number system, has 16
different symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. The hexadecimal
number system is usually referred as hex for short. It is used to write binary
numbers in short form. A hex number has about one-fourth of the digits in its
binary equivalent. Memory addresses and MAC addresses are usually written in
hex.
Step 1: Divide the given decimal number by m (the desired base). The result will
have a quotient and a remainder.
Step 2: Divide the quotient by m. Still you get a quotient and a remainder.
Step 3: Repeat step 2 until the quotient becomes 0. You should note that we are
conducting integer division. In integer division n/m, the quotient is 0
whenever n < m.
Step 4: Collect and arrange the remainders in such a way that the first remainder is
the least significant digit and the last remainder is the most significant digit
(i.e., RnRn-1 … R2R1).
Example: Convert the following decimal number 47 into binary, octal, and
hexadecimal.
a. Conversion to binary
10
In order to convert the given decimal numbers into binary (base 2), they are
divided by 2.
Quotient Remainder
47 ÷ 2 23 1
23 ÷ 2 11 1
11 ÷ 2 5 1
5÷2 2 1
2÷2 1 0
1÷2 0 1
Since the quotient becomes 0 at the last division, the division has to stop and we
should collect the remainders starting from the last one. Hence the result is
1011112. Note that, starting from the second division, at each consecutive division
the quotient of the previous division is used as the dividend.
b. Conversion to octal
Here the numbers are divided by 8 because the required base is octal (base 8).
Quotient Remainder
47 ÷ 8 5 7
5÷8 0 5
Therefore, 47 = 578
c. Conversion to hexadecimal
Since the conversion now is into hexadecimal (base 16) the given decimal numbers
are divided by 16.
Quotient Remainder
47 ÷ 16 2 15
2 ÷ 16 0 2
Remember that the remainders are all in decimal and when you write the result in
the required base, the remainders has to be converted into that base. The
hexadecimal equivalent for the decimal 15 is F and that of 2 is 2. For conversion of
decimal numbers into binary and octal or vice versa, there is no problem of looking
for the equivalent of each remainder. You need such conversion of a remainder
only when the remainder is a double digit number. Therefore, 47 = 2F16
11
Step 1: Multiply each digit by its positional value.
Step 2: Calculate the sum of the products you get in step 1. The resulting sum you
get is the decimal equivalent for the given number in base m.
Therefore, 1100012 = 49
It is evident that calculating the product of 0s since the product is 0 and do not
contribute anything to the final result. However, you should remember to skip the
positional value as well.
Therefore, 228 = 18
D116 = (13 × 161) + (1 × 160); you should be aware that the calculations are in
decimal thus the hex digit D must first be converted into
its decimal equivalent (13).
= (13 × 16) + (1 × 1)
= 208 + 1
= 209
12
It is possible to use decimal number system as an intermediate base to convert
from any base to any other base. However, for conversion from binary to octal or
vice versa, there is a very simple method.
Step 1: Group the binary digits (bits) starting from the rightmost digit. Each group
should contain 3 bits. If the remaining bits at the leftmost position are fewer
than 3, add 0s at the front.
Step 2: For each 3-bit binary string, find the corresponding octal number. Table 3-1
shows the conversion equivalents.
A. 110011
110 011
6 3
The bits are grouped in three with the equivalent octal digit given below the three
bit group. Thus, 1100112 = 638
B. 1101111
Since we are left with a single bit at the leftmost position, two 0s are added at the
front to make create a three-bit group. The result shows that 11011112 = 1578.
Step 1: For each octal digit, find the equivalent three digit binary number.
Step 2: If there are leading 0s for the binary equivalent of the leftmost octal digit,
remove them.
Example: Find the binary equivalent for the octal numbers 73 and 160.
13
A. 73
7 3
111 011
Since there are no leading 0s at the leftmost position (the bits for octal 7), there is
no 0 to remove. Therefore, 738 = 1110112
B. 160
1 6 0
001 110 000
The binary equivalent for the leftmost octal digit 1 has two 0s. To get the final
result, remove them and concatenate the rest. Thus, 1608 = 11100002
One possible way to convert a binary number to hexadecimal, is first to convert the
binary number to decimal and then from decimal to hex. Nevertheless, the simple
way to convert binary numbers to hex is by grouping as used in conversion to
octal. Here a single group has 4 bits.
Step 1: Starting from the rightmost bit, group the bits in 4. If the remaining bits at
the leftmost position are fewer than 4, add 0s at the front.
Step 2: For each 4-bit group, find the corresponding hexadecimal number. You can
use Table 3-1 to find conversion equivalents.
A. 1110110001
0011 1011 0001
2 B 1
B. 10011110
1001 1110
9 E
14
VI. Conversion from Hexadecimal to Binary
Step 1: For each hexadecimal digit, find the equivalent four digit binary number.
Step 2: If there are leading 0s for the binary equivalent of the leftmost
hexadecimal digit, remove them.
Example: Find the binary equivalents for the hexadecimal numbers 1C and 823.
A. 1C
1 C
0001 1100
After removing the leading 0s for the binary equivalent of the leftmost
hexadecimal number 1, the result becomes 11100. Thus, 1C16 = 111002
B. 823
8 2 3
1000 0010 0011
15
Convert 1101001112 to hexadecimal
Example 2: Find the octal equivalent for the hexadecimal number 3D5
Convert 3D516 to binary
3 D 5
0011 1101 0101
If the numbers we want to represent are only positive (unsigned) integers, the
solution is straight forward; simply represent the unsigned integer with its binary
value. For example, 34 is represented as 00100010 in 8 bits. In this section, the
discussion is on representation of signed integers. Signed integers can be are
represented in several alternative ways. These alternatives are used for various
purposes based on their convenience for the applications.
Computer storage has a limited capacity to hold data. The number of bits available
for data representation determines the range of integers we can represent. With 4
bits, it is possible to represent a total of 16 integers. If the number of available bits
increases to 5, we can represent 32 integers. In fact with every bit added, the
number of possible integers we can represent is doubled. In general, the number of
integers we can represent with n bits is 2 n. Singed integers include positive
integers, negative integers, as well as zero. The 2 n places are partitioned among the
negative, positive, and zero. For example, with 8 bits, it is possible to represent 256
different integers. Typically, 128 of them are positive integers and zero while the
rest 128 of them are negative integers.
16
Signed integer representations discussed in this section are sign magnitude, 1’s
complement, 2’s complement, and excess-N. We assume the number of bits
available for representation is 8 unless explicitly specified.
A problem of this representation method is that there are two representations for 0;
a positive 0 and a negative 0. An integer with all the magnitude bits and the sign
bit set to 0 is a positive 0 while an integer with all the magnitude bits set to 0 and a
1 on its sign bit is a negative 0. This type of ambiguous representation is
undesirable and as a solution, the negative zero can be ignored. The biggest
problem of this representation method is, however, its inconvenience in binary
arithmetic. Early computers, for instance IBM 7090, used this representation.
17
0
1
2
20
126
127
128
129
130
236
254
255
... ... . . . (a)
. . .
00000000
00000001
00000010
01111110
01111111
10000000
10000001
10000010
11101100
11111110
11111111
00010100
. . . ... ... . . . (b)
-0
-1
-2
-108
-126
-127
0
1
2
20
126
127
Figure 2-1: Sign-magnitude representation number line; (a) the unsigned decimal
value of the binary number, (b) the binary numbers, (c) the actual value
the binary numbers represent in sign-magnitude representation
Every number system has two complement systems. For a given base n the
complements are n’s complement and (n-1)’s complement. Thus, in decimal
numbers system (base 10), the complement systems are 10’s complement and 9’s
complement. Similarly in binary number system, the complements are 2’s
complement and 1’s complement. Using complements in binary number systems
makes subtraction and logical negation very simple. Calculating the complement of
a binary integer is trivial. Furthermore, using complements makes arithmetic
operations simple.
The one’s complement of a binary integer is found by inverting all 0s to 1s and all
1s to 0s. This makes complementing operation simple at hardware level. In one’s
complement integer representation, the negative of an integer is represented by its
complement. For example, the one’s complement representation of 16 and -16 in 8
bits are 00010000 and 11101111 respectively.
18
0
1
2
20
126
127
128
129
130
236
254
255
... ... . . . (a)
. . .
00000000
00000001
00000010
01111110
01111111
10000000
10000001
10000010
11101100
11111110
11111111
00010100
. . . ... ... . . . (b)
-127
-126
-125
-19
-1
-0
0
1
2
20
126
127
Figure 2-2: One’s complement number line; (a) the unsigned decimal value of the
binary number, (b) the binary numbers, (c) the actual value the binary
numbers represent in one’s complement representation
There is only one representation for 0 where all the bits are set to 0. The
consequence is that the number of negative integers is one more than their positive
counterparts. The arrangement of two’s complement integers on the number line is
similar to that of one’s complement except that the last value is -1 rather than -0.
Figure 2-3 shows this.
0
1
2
20
126
127
128
129
130
236
254
255
01111110
01111111
10000000
10000001
10000010
11101100
11111110
11111111
00010100
-20
-2
-1
0
1
2
20
126
127
Figure 2-3: Two’s complement number line; (a) the unsigned decimal value of the
binary number, (b) the binary numbers, (c) the actual value the binary
numbers represent in two’s complement representation
19
2.3 Floating Point Numbers
In this representation decimal numbers are represented with a fixed length format.
In order not to waste bits, the representation will normalize all the numbers. For
example, 0.000123 wastes three zeroes on the left before non -zero digits. There
zeroes have no meaning except to indicate the position of the Decimal point.
Normalizing this number result in .123x10-3 .123 is the normalized mantissa; -3 is
the exponent. We have normalized this by eliminating all the meaningless zeroes
to the left of the first non-zero digit and by adjusting the exponent.
In representing a number in floating point we use 1 bit for sing, some bits for
exponent and the remaining bit for mantissa.
Biased exponent = true exponent + excess 2n-1, where n is the number of bits
representing the exponent.
20
Ex1.
Represent –234.375 in floating point using 7 bit for exponent and 16 bit for
mantissa.
First we have to change to normalized binary
i. e 234 = 11100010
0.375= 0.011
234.375 = 11100010.011 = 0.11100010011x28
True exponent = 8
Excess 2n-1 = 27-1= 26= 64
Biased exponent = 8+26 = 8+64 = 72
= 100 1000 2
Therefore –234.375 is represented as
1 1001000 1110001001100
000
Ex2. Represent 34.25 in floating point using 7 bit for exponent and 24 bits
for mantissa.
34.25 = 1000 10.0 12
The normalized form of 34.25 = .10001001x 26
True exponent = 6; 2n-1 = 27-1= 6+26
=6+64=70
70 = 10001102
Floating-point Arithmetic
21
To perform floating-point arithmetic:
First correct the numbers to normalized binary of the same exponent
Apply the operator
If necessary normalize the result
Ex1. Find 23.375+ 41.25 using 7-bit for exponent and 10 bit for mantissa.
23.37+41.25 = 0.01011101x26+0.1110010x26
= (0.010111011+0.11100101)26
= 0.1010000101x26
For systems with much I/O and little computation of numbers, it is efficient to use
a mechanism in which each digit of a number is represented in their binary
equivalent. The BCD (Binary Coded Decimal), also called packed decimal,
representation is based on this idea. In order to have representations for the ten
digits of the decimal number system, we need a four bit string. Thus 0 = 0000, 1 =
0001, 2 = 0010… and 9 = 1001. In BCD, multiples of 8 bits, in which the bits are
grouped in 4, are used to represent decimal numbers. Thus the decimal number 461
is represented as 0000 0100 0110 0001.
Although BCD avoids complex conversions of binary numbers to decimal and vice
versa, it is inefficient in memory space usage. As the total number of unique
combinations with 4 bit strings is 16, 10 of them are used to represent the numbers.
Two more bit strings can be used to represent positive and negative signs (although
the bit string for 0 and 9 are used as positive and negative signs respectively). The
remaining bit strings are wasted. Performing arithmetic in BCD is similar to that of
other representations but the circuitry needs is also much complex. Sign-magnitude
as well as complement systems can be used in BCD. The complement system is
either 9’s complement or 10’s complement. Since complements have the advantage
of simplicity in arithmetic, they are preferred.
22
2.4.2 Characters
ASCII is a standard for use in the United States. Many countries adapted their own
versions of ASCII. There are also 8-bit versions of ASCII which allow having
additional 128 rooms for more characters, especially of those languages based on
the Latin character. To allow encoding of characters of all the languages in the
world, a character set known as the Unicode is devised. The Unicode character has
variants known as UTF-8, UTF-16, and UTF-32. UTF-8 is the same as ASCII.
UTF-16 and UTF-32 use 16-bit and 32-bit per character respectively, thus, have
incorporated much more characters. For backward compatibility with ASCII, the
first 128 characters of UTF-16 and UTF-32 are similar to those of ASCII.
23