Last modified on 18 April 2011, at 15:45

Programming:Logarithm

Revision as of 15:45, 18 April 2011 by Octoate (Talk | contribs) (added logarithm)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Log of base 2

; input: hl (unsigned)
; output: a = log2(hl) (rounded down and from -1 to 15) (8-bit integer signed)
log2:
	ld	a, 16
	scf
log2loop:
	adc	hl, hl
	dec	a
	jr	nc, log2loop
	ret