A86: Re: adding hl and a


[Prev][Next][Index][Thread]

A86: Re: adding hl and a




Easy...you want to be incrementing H (high byte) and not HL.  I suggest not
using a function, but a macro or just inlining the code yourself:

; 19/24 cycles, 5 bytes
 add a,l
 ld l,a
 jr nc,skip
 inc h
skip:

Alternatively...

; trash de: 22 cycles, 4 bytes
; save de: 43 cycles, 6 bytes
 push de
 ld e,a
 ld d,0
 add hl,de
 pop de


As a function...

; 36/42 cycles , 5 bytes + 3 bytes per call
 call add_hl_a
...
add_hl_a:
 add a,l
 ld l,a
 ret nc
 inc h
 ret

Personally, I usually use the 4 byte DE method, but that assumes you don't
need DE preserved (most cases you don't).

>
> I feel realy stupid about this but I am haveing troubble adding a to hl.
> First time I had probelms i made this little function.
> a_plus_hl:
> add a,l
> ld l,a
> ret nc
> inc hl
> ret
> ;but when i used it like this
> ld hl,$FC00
> ld a,$08
> call a_plus_hl
> ld hl,$a0
> call a_plus_hl
> ;after this hl would contain $FCA8  ad first i thought it was the emu
> ;so i put it on my calc and messed up the memory due to this
> ;can anyone tell me wtf is going on?
>
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com
>
>



References: