Z80 Routines:Optimized:addAtoHL

From WikiTI
Revision as of 06:51, 5 November 2009 by Galandros (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


This is an optimized addAtoHL because it is a little faster and doesn't need other 16-bit register. Also it can be changed to add A to any 16-bit register. The only down is 1 extra byte.

Normal way:

	ld d,$00
	ld e,a
	add hl,de
;4 bytes and 22 clock cycles
 
addAtoHL:
	add a,l
	ld l,a
	adc a,h    ;^ this two line
	sub l      ;v increase h if there is carry
	ld h,a
;5 bytes and 20 clock cycles
;but no other 16-bit register pair messed
 

Thanks to CoBB.