;;;
; mult r16, r8
; Multiples an 8-bit number (in LOW(\1)) with H, result in HL
; @param \2 A temporary register. Make SURE it's not one of H, L, HIGH(\1), or LOW(\1).
; @return HL The result
; @return HIGH(\1) 0
; @return \2 0
; @return ZF Set
; @destroy CF
;;;
mult: macro
ld L, 0
ld HIGH(\2), L
ld \2, 7
; Optimized first iteration
sla H
jr NC, .loop\@
ld L, LOW(\2)
.loop\@
add HL, HL
jr NC, .noAdd\@
add HL, DE
.noAdd
dec \2
jr NZ, .loop\@
endm
Try to improve mult op by using example here: http://wikiti.brandonw.net/index.php?title=Z80_Routines:Math:Multiplication
originally here: https://github.com/joeldipops/gbz80-pseudoOps/pull/8
'Now constant time, and uses less regs' eg.
;;; ; mult r16, r8 ; Multiples an 8-bit number (in LOW(\1)) with H, result in HL ; @param \2 A temporary register. Make SURE it's not one of H, L, HIGH(\1), or LOW(\1). ; @return HL The result ; @return HIGH(\1) 0 ; @return \2 0 ; @return ZF Set ; @destroy CF ;;; mult: macro ld L, 0 ld HIGH(\2), L ld \2, 7
.loop\@ add HL, HL jr NC, .noAdd\@ add HL, DE .noAdd dec \2 jr NZ, .loop\@ endm