1 ;; Originally from GBDK by Pascal Felber.
42 LD B,#0x00 ; Sign extend is not necessary with mul
46 ;; 16-bit multiplication
53 ;; DE = less significant word of product
55 ;; Register used: AF,BC,DE,HL
58 LD HL,#0x00 ; Product = 0
59 LD A,#15 ; Count = bit length - 1
60 ;; Shift-and-add algorithm
61 ;; If MSB of multiplier is 1, add multiplicand to partial product
62 ;; Shift partial product, multiplier left 1 bit
64 SLA E ; Shift multiplier left 1 bit
66 JR NC,.mlp1 ; Jump if MSB of multiplier = 0
67 ADD HL,BC ; Add multiplicand to partial product
69 ADD HL,HL ; Shift partial product left
71 JR NZ,.mlp ; Continue until count = 0
72 ;; Add multiplicand one last time if MSB of multiplier is 1
73 BIT 7,D ; Get MSB of multiplier
74 JR Z,.mend ; Exit if MSB of multiplier is 0
75 ADD HL,BC ; Add multiplicand to product