Module 2 COA
Module 2 COA
Module 2 COA
NIST University
Institute Park, Pallur Hills, Berhampur, Odisha
CSE and ECE
1
NIST University www.nist.edu
National Institute of Science & Technology
//MODULE-2//
By
Nibedita P Mohapatra
Assistant Professor
Department of Computer Science and Engineering
NIST Confidential
Outline
Signed number representation
National Institute of Science & Technology
Sign-Magnitude representation
1's Complement representation
2's Complement representation
In all the above three schemes, the most-significant bit (msb) is called the
sign bit. The sign bit is used to represent the sign of the integer - with 0 for
positive integers and 1 for negative integers. The magnitude of the integer,
however, is interpreted differently in different schemes.
NIST Confidential
n-bit Sign Integers in Sign-Magnitude
Representation:
National Institute of Science & Technology
In sign-magnitude representation:
The remaining n-1 bits represents the magnitude (absolute value) of the
integer. The absolute value of the integer is interpreted as "the magnitude
of the (n-1)-bit binary pattern".
NIST Confidential
Example 1: Suppose that n=8 and the binary representation is 0 100
National Institute of Science & Technology
0001B.
Sign bit is 0 ⇒ positive
Absolute value is 100 0001B = 65D
Hence, the integer is +65D
NIST Confidential
National Institute of Science & Technology
NIST Confidential
n-bit Sign Integers in 1's Complement
National Institute of Science & Technology
Representation
In 1's complement representation:
Again, the most significant bit (msb) is the sign bit, with value of 0
representing positive integers and 1 representing negative integers. The
remaining n-1 bits represents the magnitude of the integer, as follows:
For positive integers, the absolute value of the integer is equal to "the
magnitude of the (n-1)-bit binary pattern".
For negative integers, the absolute value of the integer is equal to "the
magnitude of the complement (inverse) of the (n-1)-bit binary
pattern" (hence called 1's complement).
NIST Confidential
National Institute of Science & Technology
NIST Confidential
n-bit Sign Integers in 2's Complement
Representation
National Institute of Science & Technology
For positive integers, the absolute value of the integer is equal to "the
magnitude of the (n-1)-bit binary pattern".
For negative integers, the absolute value of the integer is equal to "the
magnitude of the complement of the (n-1)-bit binary pattern plus one"
(hence called 2's complement).
NIST Confidential
National Institute of Science & Technology
NIST Confidential
National Institute of Science & Technology
NIST Confidential
National Institute of Science & Technology Fixed & floating point representations
Because of the fixed precision (i.e., fixed number of bits), an n-bit 2's
complement signed integer has a certain range. For example, for n=8, the
range of 2's complement signed integers is -128 to +127. During addition
(and subtraction), it is important to check whether the result exceeds this
range, in other words, whether overflow or underflow has occurred.
NIST Confidential
National Institute of Science & Technology
NIST Confidential
National Institute of Science & Technology Floating Point Number Representation
A floating-point number (or real number) can represent a very large
(1.23×10^88) or a very small (1.23×10^-88) value. It could also represent
very large negative number (-1.23×10^88) and very small negative number
(-1.23×10^88), as well as zero, as illustrated:
NIST Confidential
National Institute of Science & Technology
NIST Confidential
National Institute of Science & Technology Character representation
In computer memory, character are "encoded" (or "represented") using a
chosen "character encoding schemes" (aka "character set", "charset",
"character map", or "code page").
For example, in ASCII (as well as Latin1, Unicode, and many other
character sets):
code numbers 65D (41H) to 90D (5AH) represents 'A' to 'Z', respectively.
code numbers 97D (61H) to 122D (7AH) represents 'a' to 'z', respectively.
code numbers 48D (30H) to 57D (39H) represents '0' to '9', respectively.
NIST Confidential
National Institute of Science & Technology
NIST Confidential
National Institute of Science & Technology
Computer Arithmetic
We have discussed three representations for signed integers: signed-
magnitude, 1's complement and 2's complement. Computers use 2's
complement in representing signed integers. This is because:
There is only one representation for the number zero in 2's complement,
instead of two representations in sign-magnitude and 1's complement.
NIST Confidential
National Institute of Science & Technology
It is used for the purpose of adding two n-bit binary numbers.
It requires n full adders in its circuit for adding two n-bit binary
numbers.
4-bit ripple carry adder is used for the purpose of adding two 4-bit
binary numbers.
NIST Confidential
In Mathematics, any two 4-bit binary numbers A 3A2A1A0 and
B3B2B1B0 are added as shown below-
National Institute of Science & Technology
NIST Confidential
Using ripple carry adder, this addition is carried out as shown by the
following logic diagram-
National Institute of Science & Technology
NIST Confidential
Ripple Carry Adder works in different stages.
National Institute of Science & Technology
Each full adder takes the carry-in as input and produces carry-out and
sum bit as output.
The carry-out produced by a full adder serves as carry-in for its
adjacent most significant full adder.
When carry-in becomes available to the full adder, it activates the full
adder.
After full adder becomes activated, it comes into operation.
The carry out produced by each full adder serves as carry-in for its
adjacent most significant full adder.
Each carry bit ripples or waves into the next stage.
That’s why, it is called as “Ripple Carry Adder”.
NIST Confidential
National Institute of Science & Technology
Disadvantages
Ripple Carry Adder does not allow to use all the full adders
simultaneously.
Each full adder has to necessarily wait until the carry bit becomes
available from its adjacent full adder.
This increases the propagation time.
Due to this reason, ripple carry adder becomes extremely slow.
This is considered to be the biggest disadvantage of using ripple carry
adder.
NIST Confidential
National Institute of Science & Technology Carry Look Ahead Adder-
NIST Confidential
National Institute of Science & Technology
NIST Confidential
National Institute of Science & Technology
The carry-in of any stage full adder depends only on the following two
parameters-
Bits being added in the previous stages
Carry-in provided in the beginning
Now,
The above two parameters are always known from the beginning.
So, the carry-in of any stage full adder can be evaluated at any instant
of time.
Thus, any full adder need not wait until its carry-in is generated by its
previous stage full adder.
NIST Confidential
National Institute of Science & Technology 4-Bit Carry Look Ahead Adder-
Consider two 4-bit binary numbers A3A2A1A0 and B3B2B1B0 are to be
added. Mathematically, the two numbers will be added as-
NIST Confidential
National Institute of Science & Technology
NIST Confidential
National Institute of Science & Technology
Now,
Clearly, C1, C2 and C3 are intermediate carry bits.
So, let’s remove C1, C2 and C3 from RHS of every equation.
Substituting (1) in (2), we get C2 in terms of C0.
Then, substituting (2) in (3), we get C3 in terms of C0 and so on.
NIST Confidential
National Institute of Science & Technology
These equations show that the carry-in of any stage full adder depends
only on-
Bits being added in the previous stages
Carry bit which was provided in the beginning
NIST Confidential
National Institute of Science & Technology
NIST Confidential
National Institute of Science & Technology
Multiplication
Multiplication
Repeated Addition
Unsigned Integers
Generating partial products, shifting, and adding
Just like longhand multiplication
Two’s Complement Multiplication
Straightforward multiplication will not work if either the multiplier or
multiplicand are negative
multiplicand would have to be padded with sign bit into a 2n-bit partial
product, so that the signs would line up.
In a negative multiplier, the 1’s and 0’s would no longer correspond to
add-shift’s and shift-only.
NIST Confidential
National Institute of Science & Technology Booth multiplier
Booth algorithm gives a procedure for multiplying binary integers in
signed 2’s complement representation in efficient way, i.e., less number of
additions/subtractions required. It operates on the fact that strings of 0’s in
the multiplier require no addition but just shifting and a string of 1’s in the
multiplier from bit weight 2^k to weight 2^m can be treated as 2^(k+1 ) to
2^m.
As in all multiplication schemes, booth algorithm requires examination of
the multiplier bits and shifting of the partial product. Prior to the shifting,
the multiplicand may be added to the partial product, subtracted from the
partial product, or left unchanged according to following rules:
The multiplicand is added to the partial product upon encountering the first
0 (provided that there was a previous ‘1’) in a string of 0’s in the multiplier.
The partial product does not change when the multiplier bit is identical to
the previous multiplier bit.
NIST Confidential
National Institute of Science & Technology
NIST Confidential
Booth Multiplication Flow chart
National Institute of Science & Technology
NIST Confidential
Carry save multiplier
National Institute of Science & Technology
NIST Confidential
National Institute of Science & Technology Division restoring and non restoring techniques
NIST Confidential
Restoring Division Algorithm For Unsigned Integer :
National Institute of Science & Technology
Step-2: Then the content of register A and Q is shifted left as if they are a
single unit
Step-3: Then content of register M is subtracted from A and result is stored
in A
Step-4: Then the most significant bit of the A is checked if it is 0 the least
significant bit of Q is set to 1 otherwise if it is 1 the least significant bit of Q
is set to 0 and value of register A is restored i.e. the value of A before the
subtraction with M .
NIST Confidential
Non-Restoring Division For Unsigned Integer
National Institute of Science & Technology
NIST Confidential
Floating Point Arithmetic
National Institute of Science & Technology
There are several ways to represent floating point number but IEEE 754 is
the most efficient in most cases. IEEE 754 has 3 basic components:
The Sign of Mantissa –
NIST Confidential
National Institute of Science & Technology
The exponent field needs to represent both positive and negative exponents.
A bias is added to the actual exponent in order to get the stored exponent.
NIST Confidential
National Institute of Science & Technology
IEEE 754 numbers are divided into two based on the above three
components: single precision and double precision.
49
National Institute of Science & Technology
50
National Institute of Science & Technology
51
National Institute of Science & Technology
2.Double precision:
biased exponent 1023+6=1029
1029 = 10000000101
Normalized mantisa = 010101001
we will add 0's to complete the 52 bits
52
National Institute of Science & Technology
NIST Confidential
THANK YOU