Skip to navigation


Maths (Arithmetic): Multiply8x16

Name: Multiply8x16 [Show more] Type: Subroutine Category: Maths (Arithmetic) Summary: Multiply an 8-bit and a 16-bit number
Do the following multiplication of two unsigned numbers: (U T) = U * (V T) / 256 The result is also available in (U A).
.Multiply8x16 JSR Multiply8x8+2 \ Set (A T) = T * U STA W \ Set (W T) = (A T) \ = T * U \ \ So W = T * U / 256 LDA V \ Set A = V JSR Multiply8x8 \ Set (A T) = A * U \ = V * U STA U \ Set (U T) = (A T) \ = V * U LDA W \ Set (U T) = (U T) + W CLC \ ADC T \ starting with the low bytes STA T BCC mult1 \ And then the high bytes, so we get the following: INC U \ \ (U T) = (U T) + W \ = V * U + (T * U / 256) \ = U * (V + T / 256) \ = U * (256 * V + T) / 256 \ = U * (V T) / 256 \ \ which is what we want .mult1 RTS \ Return from the subroutine