I am trying to follow the division algorithm for signed numbers (2's complement representation) based on the algorithm described here. This is the standard restoring method with M and AQ registers where M is the divisor, Q is the dividend and A is the signed extended of Q. When I want to apply the method for negative numbers, it doesn't work and I am confused where is the mistake exactly. I created a simple example for -11/3 which is shown below.
Any idea about that?
Update:
It seems that the method doesn't work for 1/(-1) where quotient is -1 and remainder is 0. The initial value of registers are M=1111, A=0000 and Q=0001. In the first step, AQ is shifted to the left, so A=0000 and Q=001-. Since A and M has different sign, A=A+M=0000+1111=1111 which is -1. Since the sign of A has changed (previous 0 and now -1), we have to restore A to 0000 and insert Q[0]=0 which results in A=0000 and Q=0010.
By doing that three more times (four in total), A=0001 and Q=000-. Again A=A+M=0001+1111=0000. Since the result is 0, we keep A and insert Q[0]=1. So, the final values are A=0001 and Q=0001. As divisor and dividend signs are different, the quotient is the twos complement of Q and A is the remainder. Therefore, 1/(-1)=-1x(-1)+1 according to the algorithm. Something is wrong here...
