Ch 3. Arithmetic for computers - (3)
3. Division
- Division = ‘adder’ (subtracter) + ‘shifter’ registers
- Positive Integer에 대해서만 고려
- Algorithm
If (partial remainder ≥ divisor) then quotient bit = 1; remainder = remainder - divisor; else quotient bit = 0; shift down next dividend bit
- Ex)
- 1000 (divisor)
- 1001010 (dividend)
- 1001 (quotient)
- 10 (remainder)
Division: Implementation
- Final Version을 활용
- Dividend
- 64bits
- Shift Right
- Shift Left
- register Hi
- Remainder 저장
- mfhi $t0
- 32bits
- register Lo
- Quotient 저장
- mflo $t1
- 32bits
Division of signed number
- Quotient
- Dividend와 Divisor의 sign
- 같으면 positive
- 다르면 negative
- Dividend와 Divisor의 sign
- Remainder
- Dividend와 같은 sign을 가짐
- Ex)
- +7 / 2 = 3(Q) 1(R)
- -7 / 2 = -3(Q) -1(R)
- +7 / -2 = -3(Q) 1(R)
- -7 / -2 = 3(Q) -1(R)