Computer Architecture
Computer Architecture
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.
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.
Example:
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:
○ 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.
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.
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.
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:
3. Multiplication Algorithm
For signed number multiplication, we treat the problem as multiplying the magnitudes, then
apply the appropriate sign to the result.
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:
4. Division Algorithm
The process for dividing signed numbers is very similar to multiplying signed numbers:
Example:
These algorithms are central to computer arithmetic and are implemented in hardware and
software to perform basic mathematical operations efficiently.