doMultiply: ;returns HL = HL times A. No overflow protection. push bc push de rrca ;test if A is odd or even by dividing A by 2. jr c, isOdd ;is even ld b,a loop_multiplyByEvenNumber: add hl,hl ;double A until B runs out. djnz loop_multiplyByEvenNumber pop de pop bc ret isOdd: push hl pop de ;de contains original HL. We'll need it later. ld b,a loop_multiplyByOddNumber: add hl,hl djnz loop_multiplyByOddNumber add hl,de ;now add in original HL for the leftover add. pop de pop bc ret