LD HL,(HL) ; z80 does not have this, does anyone know the fasted way to accomplish that?
My proposal is:
LD A,(HL) ; 7+1
INC HL ; 6+1
LD H,(HL) ; 7+1
LD L,A ; 4+1
but is slow... 28 T-states
ログイン/登録して投稿
LD HL,(HL) ; z80 does not have this, does anyone know the fasted way to accomplish that?
My proposal is:
LD A,(HL) ; 7+1
INC HL ; 6+1
LD H,(HL) ; 7+1
LD L,A ; 4+1
but is slow... 28 T-states
same as
ld e,(hl)
inc hl
ld d,(hl)
ex de,hl
just you could save something assuming HL does not cross 256 boundaries
ld e,(hl)
inc l
ld d,(hl)
ex de,hl
What "+1" means?
@ARTRAG: thanks, i will align to a 256 boundary the structure
@Eugeny:+1 is the extra wait state added to z80 by the msx architecture (M1 wait state)
LD A,(HL) has 2 M1 cycles, thus +2
LD H,(HL) - same, +2
Thus your code has 30, not 28 t-states
Consider the following code:
LD SP,HL (6+1)
POP HL (10+3)
------------------
20 in total
2 M1 ???? WTF!!!!!
2 M1 ???? WTF!!!!!
Sorry I was wrong. 2 meant for a number of machine cycles, not /M1 signals 
2 /M1 signals occur during "LD A,(nn)" command execution.
I agree correct number for the original code: 28.
LD SP,HL (6+1)
POP HL (10+1)
------------------
even 18 in total
2 M1 ???? WTF!!!!!
Sorry I was wrong. 2 meant for a number of machine cycles, not /M1 signals
COrrect number for your code: 28.
LD SP,HL (6+1)
POP HL (10+1)
------------------
18 in total
this is not standard coding
ld sp, hl
pop hl
will make the code unstable IF a interrupt is called in between the ld sp,hl and the pop
also you needs to restore the SP pointer,
so if you are IN a bucle
and you can make sure ISR is disabled "DI" executed. ok, is an interesting approach.
but is not for ocasional use
because before the "ld sp, hl" you needs to save the sp address.
ld (mem), sp
...
di
ld sp, hl ; bucle part.
pop hl
...
ld sp, (mem)
Initial task was "fast way to do this".
If overall code is not large and does not use push/pop/sp (ex/exx instead), then stack is not relevant as it can be restored after the code was executed. DI/EI is required only once before and after, respectively.
because before the "ld sp, hl" you needs to save the sp address.
ld (mem), sp
...
di
ld sp, hl ; bucle part.
pop hl
...
ld sp, (mem)
Again, initial task was "fast way to do this". This = LD HL,(HL).
"..." is very important part in your example. If it happens 10 times, it's one story, but if it happens 1,000,000 times then absolutely different and time spent to save SP is a fraction of time routine spends on actual LD HL,(HL)
In some situations could be even like this, if the table content can be trashed (or is in ROM?) 
ld sp,hl (6+1)
ex (sp),hl (4+1)
Don't you have an account yet? Become an MSX-friend and register an account!
