0% found this document useful (0 votes)
20 views9 pages

68 B OaishQazi Exp7

Uploaded by

Oaish Qazi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views9 pages

68 B OaishQazi Exp7

Uploaded by

Oaish Qazi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Don Bosco Institute of Technology, Kurla

Academic Year 2024-25

EXPERIMENT NO: 7

Title: A program to simulate Booth's multiplication

Name: Qazi Mohd Oaish Azher


Roll No: 68
Batch: C
Division: B

Class: S.E Comps (Sem III) Lecturer: Sejal M Chopra


Subject: DLCA Lab
Don Bosco Institute of Technology, Kurla
Academic Year 2024-25

Class: S.E Comps (Sem III) Lecturer: Sejal M Chopra


Subject: DLCA Lab
EXPERIMENT NO: 7
A program to simulate Booth's multiplication
AIM Write a program to simulate Booth's multiplication.
LEARNING To implement the operation of the arithmetic unit including the implementation
OBJECTIVE of fixed point multiplication for signed numbers.
LEARNING Students will be able to write a higher level language code for simulating
OUTCOME hardware operation for Booth's multiplication process.
LAB CSL 302.6: Ability to implement various algorithms for arithmetic operations.
OUTCOME
PROGRAM PO-1,
OUTCOME PO5-2,
PO8-3,
PO9-3,
PO12-2,
PSO1-2
BLOOM'S Create
TAXONOMY
LEVEL
THEORY Booth's Algorithm is an efficient algorithm for performing binary
multiplication, particularly for signed numbers. It was introduced by Andrew
Donald Booth in 1951 and is designed to optimize multiplication by
reducing the number of additions/subtractions required, especially in the
presence of consecutive ones or zeros in the binary representation of the
multiplier.

Key Concepts:
• Binary Multiplication: Booth's algorithm allows for the
multiplication of signed binary numbers represented in two's
complement.
• Two's Complement: A way to represent negative numbers
in binary by inverting all bits and adding 1. Booth’s
algorithm uses this to handle both positive and negative
operands.
• Arithmetic Shifts: The algorithm performs arithmetic shifts
to divide or multiply numbers by powers of two.
Steps of Booth's Algorithm:
1. Initialization:
o The multiplier and multiplicand are initialized in
binary form.
o The product register consists of the multiplier, an
accumulator (initialized to 0), and an additional bit
Q1Q_1Q1 (set to 0 initially).
o The algorithm uses a counter that matches the
Class: S.E Comps (Sem III) Lecturer: Sejal M Chopra
Subject: DLCA Lab
Don Bosco Institute of Technology, Kurla
Academic Year 2024-25

number of bits in the binary number.


2. Examine the Least Significant Bits (LSB):
o The algorithm checks the LSB of the multiplier
(Q0Q_0Q0) and the extra bit Q1Q_1Q1:
▪ 00 or 11: Perform an arithmetic right shift on
the product register.
▪ 01: Add the multiplicand to the accumulator
and perform an arithmetic right shift.
▪ 10: Subtract the multiplicand from the
accumulator and perform an arithmetic right
shift.
3. Repeat:
o Repeat the above steps for as many bits as the binary
numbers contain.
4. Stop:
o Once the counter reaches zero, the product (result) is
stored in the accumulator and the multiplier section
of the product register.
Flowchart

Class: S.E Comps (Sem III) Lecturer: Sejal M Chopra


Subject: DLCA Lab
Don Bosco Institute of Technology, Kurla
Academic Year 2024-25

Pros of Booth's Algorithm:


1. Efficiency for Large Multipliers: When the multiplier
contains long sequences of 1's or 0's, the algorithm reduces
the number of operations.
2. Handles Signed Numbers: It works with both positive and
negative numbers due to the two's complement
representation.
3. Reduces Hardware Complexity: It reduces the number of
operations, which in turn minimizes hardware complexity.
Cons of Booth's Algorithm:
1. Performance Degradation for Alternating Bits: If the
multiplier has alternating 1's and 0's, the algorithm ends up
performing more operations.
2. Additional Logic: It requires additional logic for checking
the bits of the multiplier and handling the arithmetic
operations.
3. Slower for Random Multipliers: For certain combinations
of numbers, it may not be as fast as other multiplication
algorithms.

SOFTWARE C/C++/Java/Python
USED
STEPS TO 1. Take two decimal numbers from the user in the range of 0 to 15,both positive
EXECUTE THE and negative(M=Multiplicand & Q=Multiplier) and convert it to 4-bit binary
PROGRAM numbers.
2. Negative numbers are represented in two's complement form.
3. Initialize the counter with the count of number of bits.
4. Initialize the one bit register Q1as 0.
5. Intialise A to zero ,where A is accumulator which stores the MSB of the result.
Multiplier Q stores the LSB of the result.
6. Check LSB bit of Q and Q-1:
a. If they are 11 or 00 arithmetic shift is done for A,Q and Q-1
and decrement the counter.
b. If they are 01 add A to M and then arithmetic shift is done for A,Q and Q-1 and
decrement the counter.
c. If they are 10 sub M from A and then arithmetic shift is done for A,Q and Q-1
and decrement the counter.
7.Check the counter, if it is not 0,move to step 6,otherwise store the result in A
and Q.

CODE
def booth_multiplication(m, r, n):
def binary_representation(value, bits):
if value >= 0:
return format(value, f'0{bits}b')
else:
return format((1 << bits) + value, f'0{bits}b')

Class: S.E Comps (Sem III) Lecturer: Sejal M Chopra


Subject: DLCA Lab
Don Bosco Institute of Technology, Kurla
Academic Year 2024-25

def binary_addition(x, y, bits):


result = bin((int(x, 2) + int(y, 2)) % (1 << bits))[2:]
return result.zfill(bits)

def arithmetic_right_shift(A, Q, Q_1):


combined = A + Q + Q_1
shifted = combined[0] + combined[:-1]
return shifted[:len(A)], shifted[len(A):-1], shifted[-1]

A = '0' * n
Q = binary_representation(r, n)
M = binary_representation(m, n)
M_neg = binary_representation(-m, n)
Q_1 = '0'
count = n

print(f"Initial values: A = {A}, Q = {Q}, Q-1 = {Q_1}, M = {M}, -M =


{M_neg}")

while count > 0:


print(f"\nStep {n - count + 1}:")
if Q[-1] == '1' and Q_1 == '0': # 10 -> A = A - M
A = binary_addition(A, M_neg, n)
print(f"A = A - M -> A = {A}")
elif Q[-1] == '0' and Q_1 == '1': # 01 -> A = A + M
A = binary_addition(A, M, n)
print(f"A = A + M -> A = {A}")

A, Q, Q_1 = arithmetic_right_shift(A, Q, Q_1)


print(f"Arithmetic Right Shift -> A = {A}, Q = {Q}, Q-1 = {Q_1}")

count -= 1

result = A + Q
print(f"\nFinal binary result: {result}")

final_result = int(result, 2)
if result[0] == '1':
final_result -= 1 << (2 * n)

print(f"Final decimal result: {final_result}")


return final_result

# Taking input from the user


m = int(input("Enter the multiplicand (integer): "))
r = int(input("Enter the multiplier (integer): "))
n = int(input("Enter the number of bits: "))

booth_multiplication(m, r, n)
Class: S.E Comps (Sem III) Lecturer: Sejal M Chopra
Subject: DLCA Lab
Don Bosco Institute of Technology, Kurla
Academic Year 2024-25

OUTPUT

Class: S.E Comps (Sem III) Lecturer: Sejal M Chopra


Subject: DLCA Lab
Don Bosco Institute of Technology, Kurla
Academic Year 2024-25

CONCLUSION The implementation of Booth's algorithm for multiplying two signed


decimal numbers enhances our understanding of binary arithmetic using
two's complement representation. It efficiently handles the multiplication
process by managing the accumulator and multiplier through conditional
operations based on the least significant bits, demonstrating its
effectiveness in digital computing.

Class: S.E Comps (Sem III) Lecturer: Sejal M Chopra


Subject: DLCA Lab
Don Bosco Institute of Technology, Kurla
Academic Year 2024-25

REFERENCES 1.William Stallings, “Computer Organization and Architecture:


Designing for Performance”,Pearson Publication, 10 th Edition, 2013

Class: S.E Comps (Sem III) Lecturer: Sejal M Chopra


Subject: DLCA Lab
Don Bosco Institute of Technology, Kurla
Academic Year 2024-25

2. B. Govindarajulu, “Computer Architecture and Organization: Design


Principles and Applications”, Second Edition, McGraw Hill
(India)

Class: S.E Comps (Sem III) Lecturer: Sejal M Chopra


Subject: DLCA Lab

You might also like