Z80 Routines:Optimized:addAtoHL: Difference between revisions

From WikiTI
Jump to navigationJump to search
Galandros (talk | contribs)
New page: AddAtoHL AddAtoHL This is an optimized addAtoHL because it is a little faster and doesn't need other 16-bit register. Also it...
 
Galandros (talk | contribs)
mNo edit summary
Line 4: Line 4:
This is an optimized addAtoHL because it is a little faster and doesn't need other 16-bit register.
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.
Also it can be changed to add A to any 16-bit register. The only down is 1 extra byte.
Use it as a subroutine (don't forget the ret) or a macro.


Normal way:
Normal way:

Revision as of 14:52, 5 November 2009


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. Use it as a subroutine (don't forget the ret) or a 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    ;^ 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.