0% found this document useful (0 votes)
5 views

Computer Architecture

The document details various computer arithmetic algorithms for signed numbers, including addition, subtraction, multiplication, and division. It explains signed magnitude and 2’s complement methods, along with Booth's algorithm for multiplication and restoring division. The document also summarizes key algorithms and their applications in computer arithmetic.

Uploaded by

adityaspal2004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Computer Architecture

The document details various computer arithmetic algorithms for signed numbers, including addition, subtraction, multiplication, and division. It explains signed magnitude and 2’s complement methods, along with Booth's algorithm for multiplication and restoring division. The document also summarizes key algorithms and their applications in computer arithmetic.

Uploaded by

adityaspal2004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Let's dive even deeper into each of the computer arithmetic algorithms you mentioned,

including the details of the addition, subtraction, multiplication, and division algorithms for
signed numbers, especially focusing on signed magnitude and 2’s complement, as well as
Booth’s algorithm and restoring division. I'll cover the step-by-step procedures and examples
for each method.

1. Addition Algorithm of Signed Numbers

a) Addition of Signed Magnitude Numbers

In signed magnitude representation, numbers are represented with a sign bit that indicates
whether the number is positive (0) or negative (1). The magnitude of the number is represented
in binary.

Steps for Signed Magnitude Addition:

1.​ Step 1: Check the signs of the two numbers.


○​ If both numbers have the same sign (both positive or both negative), add the
magnitudes.
○​ If the signs are different (one positive, one negative), subtract the smaller
magnitude from the larger magnitude.
2.​ Step 2: After performing the addition or subtraction of magnitudes, assign the sign of the
result:
○​ If both numbers had the same sign, the result retains that sign.
○​ If the numbers had opposite signs, assign the sign of the number with the larger
magnitude.

Example:

●​ Add +5+5 and −3-3:


○​ Magnitude of +5+5 = 5 (binary 0101).
○​ Magnitude of −3-3 = 3 (binary 0011).
○​ Since the signs are different, subtract: 5−3=25 - 3 = 2.
○​ The result will have the sign of the number with the larger magnitude, which is
+5+5, so the result is +2+2 (binary 0010).

b) Addition of 2’s Complement Numbers

2’s complement is the most common representation for signed numbers in digital computers
because it simplifies arithmetic operations like addition and subtraction.
Steps for 2’s Complement Addition:

1.​ Step 1: Check the signs of the two numbers:​

○​ If both numbers have the same sign, add the numbers directly in binary.
○​ If the signs are different, treat it as a subtraction problem (add the 2’s
complement of the negative number).
2.​ Step 2: Perform binary addition, and if there is a carry out from the most significant bit
(MSB), discard it (because the carry is not part of the result in 2’s complement).​

Example:

●​ Add +5+5 (binary 0101) and −3-3 (binary 1101 in 4-bit 2’s complement):
○​ +5=0101+5 = 0101
○​ −3=1101-3 = 1101
○​ Add: 0101 + 1101 = 10110 (5 + (-3) = 2).
○​ The result is 0110 (binary for +2).

Notice that the carry out from the MSB (1 in 10110) is discarded, leaving 0110 as the final
result.

2. Subtraction Algorithm of Signed Numbers

a) Subtraction of Signed Magnitude Numbers

For signed magnitude subtraction, we can convert the subtraction into an addition problem by
using the 2’s complement of the number to be subtracted.

Steps for Signed Magnitude Subtraction:

1.​ Step 1: Convert the subtraction to addition by taking the 2’s complement of the number
to be subtracted (i.e., a−ba - b becomes a+(−b)a + (-b)).​

2.​ Step 2: Use the addition algorithm for signed magnitude to perform the addition.​

Example:

●​ Subtract +5−3+5 - 3:
○​ +5=0101+5 = 0101, and −3=1101-3 = 1101.
○​ Convert subtraction to addition: +5+(−3)+5 + (-3).
○​ Add: 0101 + 1101 = 10110, which gives 22 (binary 0010).
b) Subtraction of 2’s Complement Numbers

In 2’s complement, subtraction is simplified by just adding the 2’s complement of the number to
be subtracted.

Steps for 2’s Complement Subtraction:

1.​ Step 1: Convert the subtraction problem into an addition problem by taking the 2’s
complement of the number being subtracted (i.e., a−ba - b becomes a+(−b)a + (-b)).
2.​ Step 2: Add the two numbers (one of them being the 2’s complement of the other).
3.​ Step 3: If there is a carry from the MSB, discard it.

Example:

●​ Subtract 5−35 - 3 (in 4-bit 2’s complement):


○​ 5=01015 = 0101, and 3=00113 = 0011.
○​ Find the 2’s complement of 3: Invert 0011 to get 1100, and add 1 to get 1101.
○​ Add 5+(−3)=0101+1101=101105 + (-3) = 0101 + 1101 = 10110, which results in
0110 (binary for 2).

3. Multiplication Algorithm

a) Multiplication of Signed Numbers

For signed number multiplication, we treat the problem as multiplying the magnitudes, then
apply the appropriate sign to the result.

Steps for Signed Multiplication:

1.​ Step 1: Multiply the magnitudes of the two numbers (ignoring their signs for now).
2.​ Step 2: Apply the sign to the result:
○​ If both numbers have the same sign, the result is positive.
○​ If the signs are different, the result is negative.

Example:

●​ Multiply +5+5 and −3-3:


○​ Magnitudes: 5×3=155 \times 3 = 15.
○​ Since one is positive and the other is negative, the result is negative.
○​ So, +5×−3=−15+5 \times -3 = -15.

b) Booth’s Algorithm for Multiplication


Booth’s algorithm is an efficient method of multiplying signed binary numbers that reduces the
number of operations. It works by looking at pairs of bits from the multiplier.

Steps for Booth’s Algorithm:

1.​ Step 1: Initialize the multiplicand, multiplier, and accumulator.


2.​ Step 2: Check the last two bits of the multiplier:
○​ 00: Do nothing.
○​ 01: Add the multiplicand to the accumulator.
○​ 10: Subtract the multiplicand from the accumulator.
○​ 11: Do nothing.
3.​ Step 3: After each step, shift the accumulator and multiplier to the right.
4.​ Step 4: Repeat the steps for the length of the multiplier.

Example (using 4-bit numbers for simplicity):

●​ Multiply 5×35 \times 3.


○​ Step 1: Initial values are:
■​ Multiplicand = 5 (0101)
■​ Multiplier = 3 (0011)
■​ Accumulator = 0000
○​ Step 2: Apply Booth's algorithm rules and shift accordingly.

4. Division Algorithm

a) Division of Signed Numbers

The process for dividing signed numbers is very similar to multiplying signed numbers:

1.​ Step 1: Divide the magnitudes of the two numbers.


2.​ Step 2: Apply the sign to the result:
○​ If both numbers have the same sign, the result is positive.
○​ If the signs are different, the result is negative.

Example:

●​ Divide +5÷−3+5 \div -3:


○​ Magnitudes: 5÷3=15 \div 3 = 1 (quotient) with a remainder of 2.
○​ Since the signs are different, the result is negative.
○​ So, +5÷−3=−1+5 \div -3 = -1 with a remainder of 2.

b) Restoring Division Algorithm


Restoring division is a step-by-step process that divides the dividend by the divisor, restoring
the remainder when needed.

Steps for Restoring Division:

1.​ Step 1: Initialize the quotient and remainder.


2.​ Step 2: Shift the dividend and divisor.
3.​ Step 3: Subtract the divisor from the shifted dividend.
4.​ Step 4: If the result is negative, restore the previous state by adding the divisor back.
5.​ Step 5: Repeat until the division is complete.

Summary of Key Algorithms:

1.​ Addition/Subtraction of Signed Magnitude Numbers: Convert subtraction to addition


using the 2’s complement, then proceed with the regular addition algorithm.
2.​ 2’s Complement Addition/Subtraction: Perform binary addition/subtraction directly,
with special handling for carries and signs.
3.​ Multiplication: Use signed magnitude multiplication for basic cases, and optimize using
Booth's algorithm.
4.​ Division: Use restoring division or non-restoring division for dividing signed
numbers.

These algorithms are central to computer arithmetic and are implemented in hardware and
software to perform basic mathematical operations efficiently.

You might also like