5.2. Alu Lecture 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

Operands (Numbers)

• How to deal numbers


• How to categories them

Some Real numbers are:


2 , 19, -19, 1.5, ½, 5/4, 8 ½, 0.8901, 10010101, 18x10^15 etc……..

* But in the end every number has to be represented in Binary Format


How Computer Designers Categories
Numbers:
• Integers

An n-bit sequence of binary digits is interpreted as an unsigned integer


A.
10100111 = ? 128+32+4+2+1

• Floating Point Numbers


• 10101.0101010101 x2^0 1.01010101010101 x 2^4
But What About SIGNED Numbers:
• Sign Magnitude Representation:
• Treat Most Significand (leftmost) Bit in the word as sign bit
What's the Problem with Sign Magnitude
• Problem of Two Zeros
• 00000000 = ?
• 10000000 = ?

The Other Problem


How to add 010110
+ 100100
______________
111010
That’s Actually Wrong
What's Wrong ? 010110 = 22
+ 100100 = -4
______________ ____
111010 != 18

• Simplest operation such as addition and subtraction require consideration


of both signs and magnitudes making the operation complex.

• Because of these drawbacks, sign-magnitude representation is rarely used


in implementing the integer portion of the ALU.
• What is commonly used ?
2’s Complement Representation (not operation)
• Like Sign Magnitude, twos complement
representation also uses the Most
Significand bit as sign bit.
• MSB is treated as Sign Bit but a Weighted
bit too with a Negative Weighted Value.
• Use of Value Box for Conversion between
Twos Complement Binary to Decimal.
Does this Representation Overcomes the Drawback of
Sign Magnitude Representation ?
010110 = 22
+ 100100 = -28
______________ _____
111010 -6

-32 16 8 4 2 1
1 1 1 0 1 0

• -32+16+8+2 = -6
Sign Magnitude Representation
Range - (2n-1 - 1) to 2n-1 - 1

For n =8 Range = -127 to +127


Numbers of Zeros Two Zeros

Negation Toggle the Sign Bit -42 = 10101010


+42 = 00101010
Expansion of Bit Length Move the Sign Bit (MSB) to the new Sign bit position
and fill the in between bits with Zero
1001 = -1 in 8 bit 10000001 = -1
Overflow rule If two same sign numbers are added and the result
yields a carry out of the MSB of the Magnitude it
represent an Overflow
Subtraction Rule To subtract B from A ?????
2’s Complement Representation
Integers are Fixed Point Representation
• Radix point is fixed and assumed to be to the right of the rightmost
digit.
2’s Complement (Integer) Arithmetic
• Negation:
Rules
1) Take the complement of each bit of integer ( including the sign bit)
2) Treating the result an unsigned integer add 1.
• Special Case to Consider:
1) Consider A= 0000 0000,
In that case: Twos complement of 0 = 1 0000 0000
There is a carry out of the MSB position which is ignored.
Negation of 0 is 0.
• 2) If we take negation of bit pattern of 1 followed by all zeros, we get
back the same number.
2’s Complement (Integer) Arithmetic (Cont.…)
• Addition:
• Addition proceeds as if the two numbers are unsigned integers.
• If a carry occurs, it is ignored.
• If result is larger than that can be held in the word size, it is said to be
overflow condition , ALU must signal this fact so that no attempt is made to
use the result.
• To detect overflow following rule is observed:
Overflow Rule:
If two numbers are added, and they are both positive or both negative,
then overflow occurs if and only if the result has the opposite sign.
Overflow can occur whether or not there is a carry.
Addition of
Integers
Represented in
2s Complement
Notation
2’s Complement (Integer) Arithmetic (Cont.…)
• Subtraction:
To subtract one number ( subtrahend ) from another ( minuend ) take the Twos
complement (negation) of the subtrahend and add it to the minuend.

• Multiplication:

But Take a Break !!!!


Unsigned Integers Multiplication
• How do we Multiply ?
8279
x 109
_________
74511
0000 x
8279xx
_________
902411

Multiplication involves generation of partial products one for each digit in the
Multiplier. These partial products are then summed to produce the final product.
Each Partial product is placed one place ahead (shifted one bit left) of the previous
one.
What about
Unsigned Binary Integer ?
• Unsigned Integers:
• Multiplication involves generation of partial products one for each bit (digit) in the
Multiplier. These partial products are then summed to produce the final product.
• Partial products can be easily defined for binary data:
When the Multiplier bit is 0, the partial product is 0
When the Multiplier bit is 1, the partial product is Multiplicand.
• The total product is produced by summing the partial products. Each successive partial
product is shifted one position to the left relative to the preceding partial product.
• Multiplication of two n bit integers results in a product of up to 2n bit in length.
• In computerized multiplication we perform running addition. This eliminates the need for
storage of all partial products.
• For each 1 on the Multiplier an Add & a Shift operation is required and for 0 a Shift
operation is required.
End of Break
Return back to Two Complement (Integer) Arithmetic
2’s Complement (Integer) Arithmetic (Cont.…)
• Twos Complement Multiplication:
Addition and Subtraction on Twos complement are performed by treating them
unsigned integer, but this cannot be done with multiplication.
For Multiplication of two numbers represented in Twos Complement notation
Booth’s Algorithm is used:
Arithmetic Shift Right preserves the sign bit by not only shifting An-1 to An-2 but
also keeping it there.
ASSIGNMENT
• Take Two Integers:
First Integer: For B21 take -21, B20 take -20, B19 -19 and so on
Second Integer: For Starting Seat Numbers from 1-9, add 100 in last Two
digits of your Seat Number.
Other: Last two digits of your seat number.
• Convert them to Binary format (Twos Complement Notation) using a
suitable bit length size.

• Multiply them using Booth’s Algorithm.


Show your full working on a piece of paper and submit by 19th March 2024

You might also like