1 ;; Originally from GBDK by Pascal Felber.
6 ;; Need to sign extend before going in.
26 ;; HL, DE (left, right irrelivent)
32 ;; 16-bit multiplication
39 ;; DE = less significant word of product
41 ;; Register used: AF,BC,DE,HL
44 LD HL,#0x00 ; Product = 0
45 LD A,#15 ; Count = bit length - 1
46 ;; Shift-and-add algorithm
47 ;; If MSB of multiplier is 1, add multiplicand to partial product
48 ;; Shift partial product, multiplier left 1 bit
50 SLA E ; Shift multiplier left 1 bit
52 jp NC,.mlp1 ; Jump if MSB of multiplier = 0
53 ADD HL,BC ; Add multiplicand to partial product
55 ADD HL,HL ; Shift partial product left
57 jp NZ,.mlp ; Continue until count = 0
58 ;; Add multiplicand one last time if MSB of multiplier is 1
59 BIT 7,D ; Get MSB of multiplier
60 JR Z,.mend ; Exit if MSB of multiplier is 0
61 ADD HL,BC ; Add multiplicand to product