Computer Arithmetic Algorithm

In this course, we will study What is the computer arithmetic Algorithm and how arithmetic operations such as addition, subtraction, Algorithm, and multiplication are done on a computer.

What is Computer Arithmetic?

Computer arithmetic is the way in which our computer performs arithmetic operations like addition, subtraction, multiplication, and division. The arithmetic operations are performed on binary or decimal data.

Addition and Subtraction for Computer Arithmetic

The magnitude of the two numbers is designated by A and B. There are eight different conditions that need to be considered that depending on the sign of the numbers and the operation performed. These conditions are listed in the first column of the Table.

Also learn, Pin Diagram of 8085 Microprocessor

What is Computer Arithmetic?

Algorithm for Computer Arithmetic

The two signs A, and B, are compared with the help of an exclusive-OR gate. In case if the output of the gate is 0 the signs are identical; otherwise, the signs are different. For an add operation, in case of identical signs, the magnitudes are added.

  • For a subtract operation, in case of different signs, the magnitudes are added. The magnitudes are added with microoperation EA A + B. In which EA is a register that combines E and A. The carry in E is equal to 1 if there is an overflow in addition. The value of E is transferred into the AVF.
  • If the signs are different than two magnitudes are subtracted for an add operation or identical for a subtract operation. The magnitudes are subtracted by adding A to the 2’s complement of B.
  • When 1 comes in E it indicates that A >= B and the number in A is the correct result. If this number is zero then the sign A must be made positive.
  • When 0 comes in E it indicates that A < B., In this we have to take the 2’s complement of the value in A.
  • In other paths of the flowchart, the sign of the result is the same as that of the sign of A so there is no change required in A. In case of A < B, then the sign of the result is the complement of the original sign of A. So it is necessary to complement A, to get the correct sign
  • The final result is in register A and its sign is in As. The overflow indication is given by the AVF.
  • Subtraction is done by the addition of A to the 2’s complement of B.
  • The output carry is transferred to E, where it is used to determine the relative magnitudes of the two numbers.

Algorithm for Computer Arithmetic

Multiplication for Computer Arithmetic

As in all multiplication schemes, the booth algorithm requires examination of the multiplier bits and the shifting of partial products.

Multiplication for Computer Arithmetic

  • Before shifting the multiplicand can be added to the partial product, subtracted from the partial, or left unchanged.
  • The multiplicand is subtracted from the partial product on an encounter with the first least significant 1 in a string of 1’s in the multiplier.
  • The multiplicand is added to the partial product on an encounter with the first 0 in a string of 0’s in the multiplier.
  • There is no change in the partial product when the multiplier bit is identical to the previous multiplier bit.
  • The algorithm works for both positive or negative multipliers.
  • The negative multiplier ends with a string of 1’s and the last operation will be a subtraction of the appropriate weight.
  • The two bits of the multiplier in Qn and Qn+1 is inspected. In case the two bits are equal to 10, then it means the first 1 in a string of 1 ‘s has been encountered.
  • This requires the subtraction of the multiplicand from the partial product in AC.
  • If the two bits are equal to 01, then it means that the first 0 in a string of 0’s has been encountered.
  • This requires the addition of the multiplicand to the partial product in the accumulator.
  • When the two bits are equal, there is no change in the partial product.

Also learn, Block Diagram of 8085 Microprocessor