From: Bernhard Held <bernhard@be...>  20020322 09:13:38

> there is one more option besides compare/subtract, subtract and restore > by copy, subtract and restore by add, and this is subtract OR add. You > make one add or subtract in every cycle and no restore or compare. This > algorithm looks like this: > > int udivtst(int a, int b) { > int c,q=0 > > b<<=(nBitsQ1); > for(c=0; c<nBitsQ; c++) { > if(a<0) a+=b; > else a=b; > q<<=1; > q+=a>=0; > b>>=1; > } > > return q; > } Sounds very interesting. But I stopped implementing a 16 / 16 bit = 16 bit division for SDCC at this line: b<<=(nBitsQ1); This shifts my 16 bit divisor by 15 bits to the left. To avoid loss of MSBs I would have to implement 31 (or 32) bit variables and operations (!) for b and a. This would be very ineffective on a 8051. Is this correct or am I wrong? Bernhard 