我無法找出非還原整數除法的後校正。出於某種原因,我不斷收到我糾正的地方,不需要更正或不需要糾正的地方非還原有符號整數除法後校正
繼承人僞碼算法。 Dividend
是16位,其他8位。通過Dividend_Sign
,Remainder_Sign
我的意思是他們的最高有效位是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;
現在一個地步,我基本上都正確的答案IM,它只是需要進行後糾正了這樣或那樣的......或者根本沒有糾正後。林不知道所有的糾正情況是什麼。現在我有一個心不是工作一半時間的東西,但在這裏它是無論如何:
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
你能否詳細說明,或至少列舉,不工作的案件? – 2012-04-22 23:38:48
atm發現-10:2和-10:-2是正確的預校正和糾正混亂。 -16:4需要更正,但沒有。我認爲這與他們剩下0分有關。 – ollo 2012-04-23 00:10:14
請解釋一旦校正完成後剩餘部分所需的要求(暫時忽略如何完成校正)。 – 2012-04-23 00:16:23