WK3 Study Session 2.1
WK3 Study Session 2.1
1:
Introduction
This study session focuses on the most complex aspect of the Arithmetic and Logic Unit (ALU),
computer arithmetic. Computer arithmetic is commonly performed on two very different types of
numbers:
i. Integer And
ii. Floating Point.
In both cases, the representation chosen is a crucial design issue and is treated first.
There is limited number of symbols in the number system called digits. These symbols
represent different values depending on the position they occupy in the number. The value
of each digit in a number can determined by examining the digit is under consideration, the
position of the digit in the number and the total number of digits in the number system. The
total number of digits used in a number system is called its base or radix.
Here MS stands for Most Significant and signifies the leftmost digit or bit. LS stands for Least
Significant and signifies the rightmost digit or bit.
2.2 The Arithmetic And Logic Unit
The arithmetic and logic unit (ALU) is that part of the computer that actually performs arithmetic
and logical operations on data. All of the other elements of the computer system- Control unit,
registers memory, I/0- are there mainly to bring into the ALU for it to process and then take the
result back out.
An ALU and all electronic components in the computers are based on the use of simple digital
logic devices that can store binary digits and perform simple Boolean logic operations.
Data are presented to the ALU in registers and the results of an operation are stored in registers.
These registers are temporary storage locations within the processor that are connected by signal
paths to the ALU. The ALU may also set flags as the result of an operation. For example, an
overflow flag is set to 1 if the result of a computation exceeds the length of the register into which
it is to be stored. The flag values are also stored in registers within the processor. The control unit
provides signals that control the operation of the ALU and the movement of the data into and out
of the ALU.
2.3 Integer Representation
In the binary number, arbitrary numbers can be represented with just the digits zero and one the
minis sign and the period or radix point.
-1101.01012= -13.312510
For purposes of computer storage and processing, however we do not have the benefits of minus
signs and periods. Only binary digits (0 and 1) may be used to represent numbers. If we are limited
to non-negative integers, the representation is straight forward.
When an integer binary number is positive, the sign is represented by 0 and the magnitude by a
positive binary number. When the number is negative, the sign is represented by 1 but the rest of
the number may be represented in one of three possible ways:
i. Signed-magnitude representation
ii. Signed-1' s complement representation
iii. Signed 2' s complement representation
The signed-magnitude representation of a negative number consists of the magnitude and a
negative sign. In the other two representations, the negative number is represented in either the 1's
or 2's complement of its positive value. As an example, consider the signed number 14 stored in
an 8-bit register. + 14 is represented by a sign bit of 0 in the leftmost position followed by the
binary equivalent of 14: 00001110. Note that each of the eight bits of the register must have a
value and therefore 0' s must be inserted in the most significant positions following the sign bit.
Although there is only one way to represent + 14, there are three different ways to represent - 14
with eight bits.
In signed-magnitude representation 1 0001110
In signed-1's complement representation 1 1110001
In signed-2's complement representation 1 1110010
The signed-magnitude system is used in ordinary arithmetic but is awkward when employed in
computer arithmetic. Therefore, the signed-complement is normally used. The 1's complement
imposes difficulties because it has two representations of 0 (+0 and - 0). It is seldom used for
arithmetic operations except in some older computers. The 1's complement is useful as a logical
operation since the change of 1 to 0 or 0 to 1 is equivalent to a logical complement operation. The
following discussion of signed binary arithmetic deals exclusively with the signed-2's complement
representation of negative numbers.
+6 00000110 - 6 11111010
- 13 11110011 - 13 1111001 1
In each of the four cases, the operation performed is always addition, including the sign bits. Any
carry out of the sign bit position is discarded, and negative results are automatically in 2's
complement form.
The complement form of representing negative numbers is unfamiliar to people used to the signed-
magnitude system. To determine the value of a negative number when in signed-2's complement,
it is necessary to convert it to a positive number to place it in a more familiar form. For example,
the signed binary number 1111 1001 is negative because the leftmost bit is I. Its 2's complement
is 00000111, which is the binary equivalent of +7. We therefore recognize the original negative
number to be equal to -7.
2.4 Overflow
When two numbers of n digits each are added and the sum occupies n + 1 digits, we say that an
overflow occurred. When the addition is performed with paper and pencil, an overflow is not a
problem since there is no limit to the width of the page to write down the sum. An overflow is a
problem in digital computers because the width of registers is finite. A result that contains n + 1
bits cannot be accommodated in a register with a standard length of n bits. For this reason, many
computers detect the occurrence of an overflow, and when it occurs, a corresponding flip-flop is set
which can then be checked by the user.
The detection of an overflow after the addition of two binary numbers depends on whether the
numbers are considered to be signed or unsigned. When two unsigned numbers are added, an
overflow is detected from the end carry out of the most significant position. In the case of signed
numbers, the leftmost bit always represents the sign, and negative numbers are in 2' s complement
form. When two signed numbers are added, the sign bit is treated as part of the number and the end
carry does not indicate an overflow.
An overflow cannot occur after an addition if one number is positive and the other is negative, since
adding a positive number to a negative number produces a result that is smaller than the larger of
the two original numbers. An overflow may occur if the two numbers added are both positive or
both negative. To see how this can happen, consider the following example. Two
signed binary numbers, + 70 and + 80, are stored in two 8-bit registers. The range of numbers that
each register can accommodate is from binary + 127 to binary - 128. Since the sum of the two
numbers is + 150, it exceeds the capacity of the 8-bit register. This is true if the numbers are both
positive or both negative. The two additions in binary are shown below together with the last two
carries.
Note that the 8-bit result that should have been positive has a negative sign bit and the 8-bit result
that should have been negative has a positive sign bit. If, however, the carry out of the sign bit
position is taken as the sign bit of the result, the 9-bit answer so obtained will be correct. Since the
answer cannot be accommodated within 8 bits, we say that an overflow occurred.
An overflow condition can be detected by observing the carry into the sign bit position and the carry
out of the sign bit position. If these two carries are not equal, an overflow condition is produced.
This is indicated in the examples where the two carries are explicitly shown. If the two carries are
applied to an exclusive-OR gate, an overflow will be detected when the output
of the gate is equal to 1.
2.5 Decimal Fixed-Point Representation
The representation of decimal numbers in registers is a function of the binary code used to
represent a decimal digit. A 4-bit decimal code requires four flip-flops for each decimal digit. The
representation of 4385 in BCD requires I6 flip-flops, four flip-flops for each digit. The number
will be represented in a register with I6 flip-flops as follows:
O1OO 0011 1000 0101
By representing numbers in decimal, we are wasting a considerable amount of storage space since
the number of bits needed to store a decimal number in a binary code is greater than the number
of bits needed for its equivalent binary representation. Also, the circuits required to perform
decimal arithmetic are more complex. However, there are some advantages in the use of decimal
representation because computer input and output data are generated by people who use the
decimal system. Some applications, such as business data processing, require small amounts of
arithmetic computations compared to the amount required for input and output of decimal data.
For this reason, some computers and all electronic calculators perform arithmetic operations
directly with the decimal data (in a binary code) and thus eliminate the need for conversion to
binary and back to decimal. Some computer systems have hardware for arithmetic calculations
with both binary and decimal data.
The representation of signed decimal numbers in BCD is similar to the representation of signed
numbers in binary. We can either use the familiar signed-magnitude system or the signed-
complement system. The sign of a decimal number is usually represented with four bits to conform
with the 4-bit code of the decimal digits. It is customary to designate a plus with four 0' s and a
minus with the BCD equivalent of 9, which is 1001.
The signed-magnitude system is difficult to use with computers. The signed-complement system
can be either the 9's or the 10's complement, but the 10's complement is the one most often used.
To obtain the 10's complement of a BCD number, we first take the 9's complement and then add
one to the least significant digit. The 9's complement is calculated from the subtraction of each
digit from 9.
The procedures developed for the signed-2's complement system apply also to the signed-10's
complement system for decimal numbers. Addition is done by adding all digits, including the sign
digit, and discarding the end carry. Obviously, this assumes that all negative numbers are in 10's
complement form. Consider the addition (+375) + (-240) = + 135 done in the signed- 10's
complement system.
The 9 in the leftmost position of the second number indicates that the number is negative. 9760 is
the 10's complement of 0240. The two numbers are added and the end carry is discarded to obtain
+ 135. Of course, the decimal numbers inside the computer must be in BCD, including the sign
digits. The addition is done with BCD adders.
The subtraction of decimal numbers either unsigned or in the signed-10's complement system is
the same as in the binary case. Take the 10' s complement of the subtrahend and add it to the
minuend. Many computers have special hardware to perform arithmetic calculations directly with
decimal numbers in BCD. The user of the computer can specify by programmed instructions that
the arithmetic operations be performed with decimal numbers directly without having to convert
them to binary.
2.6 Floating-Point Representation
The floating-point representation of a number has two parts. The first part represents a signed,
fixed-point number called the mantissa. The second part designates the position of the decimal
(or binary) point and is called the exponent. The fixed-point mantissa may be a fraction or an
integer. For example, the decimal number + 6132.789 is represented in floating-point with a
fraction and an exponent as follows:
The value of the exponent indicates that the actual position of the decimal point is four
positions to the right of the indicated decimal point in the fraction. This representation is
equivalent to the scientific notation +0.6132789 X 10+4. Floating-point is always interpreted
to represent a number in the following form:
Only the mantissa m and the exponent e are physically represented in the register (including
their signs). The radix r and the radix-point position of the mantissa are always assumed. The
circuits that manipulate the floating-point numbers in registers conform with these two
assumptions in order to provide the correct computational results.
A floating-point binary number is represented in a similar manner except that it uses base 2
for the exponent. For example, the binary number + 1001.11 is represented with a n 8-bit
fraction and 6-bit exponent a s follows:
A floating-point number is said to be normalized if the most significant digit of the mantissa is
nonzero. For example, the decimal number 350 is normalized but 00035 is not. Regardless of
where the position of the radix point is assumed to be in the mantissa, the number is normalized
only if its leftmost digit is nonzero. For example, the 8-bit binary number 00011010 is not
normalized because of the three-leading 0's. The number can be normalized by shifting
it three positions to the left and discarding the leading O's to obtain 11010000. The three shifts
multiply the number by 23 = 8. To keep the same value for the floating-point number, the exponent
must be subtracted by 3. Normalized numbers provide the maximum possible precision for the
floating-point number. A zero cannot be normalized because it does not have a nonzero digit. It is
usually represented in floating-point by all O's in the mantissa and exponent.
Arithmetic operations with floating-point numbers are more complicated than arithmetic
operations with fixed-point numbers and their execution takes longer and requires more complex
hardware. However, floating-point representation is a must for scientific computations because of
the scaling problems involved with fixed-point computations. Many computers and all electronic
calculators have the built-in capability of performing floating-point arithmetic operations.
Computers that do not have hardware for floating-point computations have a set of subroutines to
help the user program scientific problems with floating-point numbers.
In-text question
What is arithmetic and logic unit (ALU)?
- is that part of the computer that actually performs arithmetic and logical operations on
data. All of the other elements of the computer system, such as; Control unit, registers
memory, I/0- are there mainly to bring into the ALU for it to process and then take the
result back out.
What is the CPI for each sequence? Which code sequence is faster? By how much?
https://images.app.goo.gl/kBtFRAmYncgviXLr8
https://computersciencewiki.org/index.php/Architecture_of_the_central_processing_unit
_(CPU)