Long division in base 2 as hardware: the shift-subtract-restore loop that yields a quotient and remainder.
Binary division is the long division you learned in school, done in base 2. Restoring division turns it into a tight hardware loop over three registers: A holds the running remainder (starts at 0), Q holds the dividend and fills up with the quotient, and M holds the divisor.
Each round brings in one more bit of the dividend, tries to subtract the divisor, and decides a single quotient bit. If the trial subtraction goes negative, the divisor did not fit — so the value is restored (added back) and the quotient bit is 0; otherwise it fits and the bit is 1.
A : Q register left by one bit.A = A - M.A is negative (top bit 1): set the new quotient bit Q0 = 0 and restore with A = A + M.A is non-negative: set Q0 = 1 (no restore needed).Q is the quotient and A is the remainder.Divide 7 (Q = 0111) by 3 (M = 0011). 4 bits.
step A Q
init 0000 0111
1 shift 0000 1110
A - M < 0 -> restore, Q0=0 0000 1110
2 shift 0001 1100
A - M < 0 -> restore, Q0=0 0001 1100
3 shift 0011 1000
A - M = 0 -> keep, Q0=1 0000 1001
4 shift 0001 0010
A - M < 0 -> restore, Q0=0 0001 0010
quotient Q = 0010 = 2
remainder A = 0001 = 1 (7 ÷ 3 = 2 remainder 1)A this round, so adding it back returns A to its pre-subtraction value — hence restoring division. That extra add is wasted work on every 0 quotient bit.