I update above, but I only require it to work between 0 and 77.
Mike solution might be better, if it requires less registers.
Code: Select all
; Divide L by 6
;============
; Inputs:
; L = Dividend
;----------------
; implemnetation : multiplies by 43 (=~ 256/6 +1), and returns the high byte (H)
; NOTE: 43 = 32 + 8 + 2 +1
; OR using add and subtracts in sequence: 2 4 5 10 11 22 44 43
LD H, 0
LD D, H ; DE = HL
LD E, L
ADD HL, HL ; x02
ADD HL, HL ; x04
ADD HL, DE ; x05
ADD HL, HL ; x10
ADD HL, DE ; x11
ADD HL, HL ; x22
ADD HL, HL ; x44
SBC HL, DE ; x43
; result in H