Here's a user-defined function that you can add to your bB program if you want to be able to divide a 16-bit number by an 8-bit number. It's taken directly from a routine I found here:
http://6502org.wikid...are-math-intdiv
function div16by8 asm LDX #8 ASL temp2 div16by8_1 ROL BCS div16by8_2 CMP temp3 BCC div16by8_3 div16by8_2 SBC temp3 SEC div16by8_3 ROL temp2 DEX BNE div16by8_1 RTS endTo call the function, you must pass it three parameters. When the function exits, the two parts of the answer will be in the accumulator and temp2.
The following pseudocode example uses the function to divide a 16-bit integer by an 8-bit integer, giving a 16-bit integer as the result:
quotient_hibyte = div16by8 (numerator_hibyte, numerator_lobyte, divisor) quotient_lobyte = temp2This next pseudocode example uses the function to divide an 8.8 fixed-point (16-bit) number by an 8-bit integer, giving an 8.8 fixed-point number as the result:
quotient_wholepart = div16by8 (numerator_wholepart, numerator_fractionalpart, divisor) quotient_fractionalpart = temp2As you can see, they're exactly the same, except for the way we interpret the parameters and results.
This routine is for *unsigned* values, and hasn't been tested with "negative" numbers.
Michael













