Software - Math - Integer Division
8-bit / 8-bit = 8-bit quotient, 8-bit remainder (unsigned)
- Inputs:
- TQ = 8-bit numerator
- B = 8-bit denominator
- Outputs:
- TQ = 8-bit quotient of TQ / B
- accumulator = remainder of TQ / B
;
LDA #0
LDX #8
ASL TQ
L1 ROL
CMP B
BCC L2
SBC B
L2 ROL TQ
DEX
BNE L1
16-bit / 8-bit = 8-bit quotient, 8-bit remainder (unsigned)
- Inputs:
- TH = bits 15 to 8 of the numerator
- TLQ = bits 7 to 0 of the numerator
- B = 8-bit denominator
- Outputs:
- TLQ = 8-bit quotient of T / B
- accumulator = remainder of T / B
;
LDA TH
LDX #8
ASL TLQ
L1 ROL
BCS L2
CMP B
BCC L3
L2 SBC B
;
; The SEC is needed when the BCS L2 branch above was taken
;
SEC
L3 ROL TLQ
DEX
BNE L1
page revision: 2, last edited: 22 Feb 2008 02:41