For asm guys, the fast way to do this...

페이지 1/2
| 2

By PingPong

Prophet (4093)

PingPong의 아바타

03-06-2011, 21:14

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

Login or 등록 to post comments

By ARTRAG

Enlighted (6923)

ARTRAG의 아바타

03-06-2011, 21:24

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

By Eugeny_Brychkov

Paragon (1232)

Eugeny_Brychkov의 아바타

03-06-2011, 21:35

What "+1" means?

By PingPong

Prophet (4093)

PingPong의 아바타

03-06-2011, 21:44

@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)

By Eugeny_Brychkov

Paragon (1232)

Eugeny_Brychkov의 아바타

03-06-2011, 21:54

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

By flyguille

Prophet (3031)

flyguille의 아바타

03-06-2011, 22:39

2 M1 ???? WTF!!!!!

By Eugeny_Brychkov

Paragon (1232)

Eugeny_Brychkov의 아바타

03-06-2011, 23:05

2 M1 ???? WTF!!!!!
Sorry I was wrong. 2 meant for a number of machine cycles, not /M1 signals Sad
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

By flyguille

Prophet (3031)

flyguille의 아바타

03-06-2011, 23:09

2 M1 ???? WTF!!!!!
Sorry I was wrong. 2 meant for a number of machine cycles, not /M1 signals Sad 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)

By Eugeny_Brychkov

Paragon (1232)

Eugeny_Brychkov의 아바타

03-06-2011, 23:15

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.

By Eugeny_Brychkov

Paragon (1232)

Eugeny_Brychkov의 아바타

03-06-2011, 23:18

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)

By Marq

Champion (387)

Marq의 아바타

03-06-2011, 23:35

In some situations could be even like this, if the table content can be trashed (or is in ROM?) Smile

ld sp,hl (6+1)
ex (sp),hl (4+1)

페이지 1/2
| 2