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