Write Booths algorithm. Also explain floating point arithmetic operation. Describe signal addition and subtraction in detail.
Q.) Write Booths algorithm. Also explain floating point arithmetic operation. Describe signal addition and subtraction in detail.
Subject: Computer Organization and ArchitectureBooth's Algorithm
Booth's algorithm is a multiplication algorithm that multiplies two signed binary numbers in two's complement notation. The algorithm is efficient because it reduces the number of additions required to calculate the product. Here is the step-by-step approach to Booth's algorithm:
Initialization: Let's consider two numbers, a multiplicand
M
and a multiplierQ
. Also, letA
be an accumulator initialized to zero, andQ-1
be a bit used for the Booth's algorithm, initialized to 0. The number of bits inA
,Q
, andM
should be the same. Letcount
be initialized to the number of bits inQ
.Examine
Q0
andQ-1
: Look at the least significant bit ofQ
(denoted asQ0
) and the extra bitQ-1
. There are four possible combinations:00
,01
,10
, and11
.Operation Decision: Depending on the combination of
Q0
andQ-1
, perform the following operations:- If
Q0 Q-1
is01
, addM
toA
. - If
Q0 Q-1
is10
, subtractM
fromA
. - If
Q0 Q-1
is00
or11
, do nothing (these represent the same sign for two consecutive bits inQ
).
- If
Arithmetic Shift: Perform an arithmetic right shift on the combined
A
,Q
, andQ-1
bits. This means thatA
,Q
, andQ-1
are treated as a single number, and they are all shifted to the right by one bit. The sign bit ofA
is retained.Decrement Counter: Decrease the
count
by 1.Loop or Terminate: If
count
is not zero, go back to step 2. Otherwise, terminate the algorithm. The result is inA
andQ
combined, withA
holding the most significant bits andQ
the least significant bits.
Example:
Let's multiply 3
(multiplicand) by -4
(multiplier) using Booth's algorithm.
Binary representations:
M = 0011 (3)
Q = 1100 (-4, in two's complement)
A = 0000 (initialized to zero)
Q-1 = 0 (initialized to zero)
count = 4 (since we're using 4-bit numbers)
Step | A | Q | Q-1 | Operation | Comment |
---|---|---|---|---|---|
0 | 0000 | 1100 | 0 | Initial values | |
1 | 0000 | 1100 | 0 | Check Q0 Q-1 |
00 - do nothing |
2 | 0000 | 0110 | 0 | Shift right | |
3 | 0000 | 0110 | 0 | Check Q0 Q-1 |
00 - do nothing |
4 | 0000 | 0011 | 0 | Shift right | |
5 | 0000 | 0011 | 0 | Check Q0 Q-1 |
01 - add M to A |
6 | 0011 | 0011 | 0 | Shift right | |
7 | 0001 | 1001 | 1 | Check Q0 Q-1 |
10 - subtract M from A |
8 | 1110 | 1001 | 1 | Shift right | |
9 | 1111 | 0100 | 1 | Check Q0 Q-1 |
01 - add M to A |
10 | 0010 | 0100 | 0 | Shift right | Final result (A and Q combined) |
The final product is 00100100
, which is -12
in decimal, as expected (since 3 * -4 = -12
).
Floating Point Arithmetic Operation
Floating point arithmetic operations are used to perform calculations on real numbers that have a decimal point and can have a very wide range of values. The most common standard for representing floating point numbers is the IEEE 754 standard.
Floating point numbers are represented in three parts:
- Sign bit (S): Determines whether the number is positive or negative.
- Exponent (E): Encodes the magnitude of the number.
- Mantissa or Significand (M): Encodes the precision of the number.
The value of a floating point number is determined by the following formula:
[ V = (-1)^S \times 1.M \times 2^{(E - \text{bias})} ]
where bias
is a fixed value determined by the format (for example, in IEEE 754 single precision, the bias is 127).
Example:
Consider the IEEE 754 single-precision floating point representation of the number 5.75
:
S = 0 (positive)
E = 128 (with a bias of 127, so the actual exponent is 1)
M = 1.11 (in binary, which is 1.75 in decimal)
So, the value is:
[ V = (-1)^0 \times 1.11_2 \times 2^{(128 - 127)} = 1.75 \times 2^1 = 5.75 ]
Signal Addition and Subtraction
Signal addition and subtraction are fundamental operations in signal processing. They involve combining or removing signal amplitudes at corresponding points in time or space.
Signal Addition
To add two signals, you simply add their amplitudes point by point. If x(t)
and y(t)
are two signals, their sum z(t)
is given by:
[ z(t) = x(t) + y(t) ]
Signal Subtraction
Similarly, to subtract one signal from another, you subtract their amplitudes point by point. If x(t)
and y(t)
are two signals, the result of subtracting y(t)
from x(t)
is z(t)
:
[ z(t) = x(t) - y(t) ]
Example:
Let's say we have two discrete-time signals:
x[n] = {1, 2, 3}
y[n] = {4, 5, 6}
The addition of x[n]
and y[n]
is:
z[n] = x[n] + y[n] = {1+4, 2+5, 3+6} = {5, 7, 9}
The subtraction of y[n]
from x[n]
is:
z[n] = x[n] - y[n] = {1-4, 2-5, 3-6} = {-3, -3, -3}
In both cases, the operations are performed element-wise.