Z80 Routines:Optimized:addAtoHL

From WikiTI
Revision as of 16:06, 7 November 2009 by Dr. D'nar (Talk | contribs)

Jump to: navigation, search


This is an optimized addAtoHL. It is a little faster and doesn't need another 16-bit register.

Also it can be changed to add A to any 16-bit register. The only down side is one extra byte.

Use it as a subroutine (don't forget the ret) or macro.

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    ;^ these two lines
	sub l      ;v increase h if there is carry
	ld h,a
;5 bytes and 20 clock cycles
;but no other 16-bit register messed up
 

Thanks to CoBB.