Skip to navigation


Extra tracks: Multiply8x8Signed

Name: Multiply8x8Signed [Show more] Type: Subroutine Category: Extra tracks Summary: Multiply two 8-bit numbers, one of which is signed
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * CalcSegmentVector calls Multiply8x8Signed

This routine calculates the following, retaining the sign in A. A= A * U / 256 Specifically, if the last instruction to affect the N flag before the call is an LDA instruction, and A is signed, then set: A= |A| * U * abs(A) = A * U / 256 So this multiplies A and U, retaining the sign in A.
.Multiply8x8Signed PHP \ Store the N flag on the stack, as set by the LDA just \ before the call, so this equals abs(A) JMP MultiplyHeight+11 \ Jump into the MultiplyHeight routine to do this: \ \ JSR Absolute8Bit \ Set A= |A| \ \ JSR Multiply8x8 \ Set (A T)= A * U \ \ = |A| * U \ \ \ \ So A= |A| * U / 256 \ \ PLP \ Retrieve sign in N, which we \ \ set to abs(A) above \ \ JSR Absolute8Bit \ Set A= |A| * abs(A) \ \ = A * U / 256 \ \ RTS \ Return from the subroutine \ \ So this sets A= A * U while retaining the sign in A EQUB &FC, &FC \ These bytes appear to be unused