Prev: 53083 Up: Map Next: 53141
53118: Multiply
Used by the routine at ScaleDisplacement.
Multiplies the byte in D by the byte in C.
Input
D One byte
C The other byte
Output
HL The product
The byte in D is multiplied by the byte in C. Eight bits are tested, and each bit that is set adds the shifted byte into the product.
Multiply 53118 LD H,0 The product starts at zero, with eight bits to test.
53120 LD B,H
53121 LD L,H
53122 LD E,D
53123 LD A,8
53125 JR Multiply_Bit Test the first bit.
Multiply_Loop 53127 DEC A One fewer bit remains.
53128 RET Z The product is ready.
53129 SLA C Shift the other byte up.
53131 RL B
Multiply_Bit 53133 RR D The next bit of the byte.
53135 JR NC,Multiply_Loop This bit adds nothing.
53137 ADD HL,BC Add the shifted byte into the product.
53138 JP Multiply_Loop The next bit.
Prev: 53083 Up: Map Next: 53141