Two's complement division operation

The two-complement division operation is to calculate the two numbers in the form of one's complement. Compared with the division of the original code, the dividend, the divisor and the remainder of the two-complement division are calculated in the form of double sign bits, and finally The sign bit of the remainder obtained represents the sign bit of the final result.

Alternate addition and subtraction

Question: Suppose the machine word length is 5 digits, x=+0.1000, y=-0.1011, use the complement alternate method to find x/y?

  • First, calculate the complement of x, the complement of y, and the complement of -y through the title. Both are represented by double sign bits.
  • x(complement)=00.1000, y(complement)=11.0101, (-y)(complement)=00.1011

First, judge whether the dividend x (complement) and the divisor y (complement) are the same sign or different sign. If it is the same sign, subtract y (complement). If it is the same sign, add y (complement).

The calculated remainder is then compared with the divisor y (complement):

  • If it is the same number, the quotient is 1, move one place to the left, and then subtract y (complement), subtracting y (complement) is equivalent to adding (-y) (complement)
  • If it is an opposite sign, the quotient is 0, move one place to the left, and add y (complement)

The detailed calculation process is as follows:

Insert picture description here

  • x(complement)=00.1000, divisor y(complement)=11.0101. Two numbers are different signs. So use x(complement)+y(complement)=11.1101
  • 11.1101 continues to compare with y (complement) and finds that it is the same number. The quotient is 1, the remainder 11.1101 is moved one place to the left, and the result of adding (-y) (complement) is 00.0101
  • The remainder 00.0101 continues to be compared with y (complement), and it is found that it is an opposite sign. The quotient is 0. At this time, the quotient is 10. The remainder 00.0101 moves one place to the left, and the result of adding (y) (complement) is 11.11111
  • The remainder 11.11111 continues to be compared with y (complement), and it is found to be the same number. The quotient is 1. At this time, the quotient is 101. The remainder 11.11111 moves one place to the left, and the result is 00.1001 after adding (-y) (complement)
  • The remainder 00.1001 continues to be compared with y (complement), and it is found that it is an opposite sign. The quotient is 0. At this time, the quotient is 1010. The remainder 00.1001 moves one place to the left, and the result is 00.0111 after adding (y) (complement)
  • It is reasonable to say that when this step is reached, the remainder 00.0111 is different from y (complement), and the last digit of the quotient (the machine word length is specified as 5 digits) should be 0, but due to the addition and subtraction of the complement code, the last one is required. The quotient of the bit is 1

The final quotient is 10101, and the remainder is 00.0111. The sign bit of the remainder directly indicates that the final result is also positive.

Guess you like

Origin blog.csdn.net/brokenkay/article/details/108761315