非復元整数除算の事後修正がわかりません。どういうわけか、修正が必要ないところを修正したり、必要なときに修正しない場合があります。
ここにアルゴリズムの擬似コードがあります。Dividend
16ビットと他の8ビットです。つまりDividend_Sign
、Remainder_Sign
MSBが1であるため、2の補数で負になります。
LoopCounter = 8;
do {
Shift Dividend Left with 0 in LSB;
if (Dividend_Sign XOR Divisor_Sign) {
Shift 0 into Quotient;
DividendHighByte = DividendHighByte + Divisor;
} else {
shift 1 into Quotient;
DividendHighByte = DividendHighByte - Divisor; // subtraction by 2's complement
}
} while (loopCounter != 0);
Remainder = DividendHighByte;
// here i do the Quotient conversion
invert MSB; // shifted out anyway. Probably should be used for overflow check, not important atm.
shift 1 into Quotient;
今、私は基本的に正しい答えを持っている時点で、何らかの方法で後修正する必要があります...またはまったく後修正しないでください。すべての修正ケースが何であるかわかりません。今、私は半分の時間は機能していないものを持っていますが、とにかくここにあります:
if (Dividend_Sign XOR Remainder_sign) { // diff signs so correct
if (Remainder_Sign XOR Divisor_Sign) { // diff signs just add
Remainder = Remainder + Divisor;
Quotient = Quotient - 1;
} else {
Remainder = Remainder - Divisor;
Quotient = Quotient + 1;
}
}
http://en.wikipedia.org/wiki/Division_%28digital%29
http://www.acsel-lab.com/arithmetic/papers/ARITH17/ARITH17_Takagi.pdf