How safe is to use undocumented Z80 instructions?

Página 2/2
1 |

Por Chardson

Champion (411)

imagem de Chardson

22-04-2007, 08:21

Hi all,

I was modifing a routine I found on the web to work with some programs I am doing. But my modifications needed more two 8 bit registers. So, to avoid a lot of pushs and pops, I was thinking about using IXl and IXh (specially because of their accumulator properties). But I was wondering if it would turn to be a big trouble, compatibility-wise.And there's always the option to use the alternative register set - 100% documented and safe Smile

Yeah, I could use them, but this routine belongs to a lib I am doing while I work on the main program. And I don't think it is good for a "general" routine to use exx. If so, every "general" routine should use them and main programs should never. Wink

Por AuroraMSX

Paragon (1902)

imagem de AuroraMSX

22-04-2007, 12:58

Yeah, I could use them, but this routine belongs to a lib I am doing while I work on the main program. And I don't think it is good for a "general" routine to use exx. If so, every "general" routine should use them and main programs should never. WinkDocumentation is the key here. You're also using the normal registers - all of them, apparently. Does that imply that main programs should never do that? No, it means that if the main program uses the registers, it has the responsibility to save their values somewhere - e.g. on the stack - before calling your lib function, and restore them afterwards. The same holds for the alternative register set: if the main program uses it, it will have the responsibility to save the contents.
Your lib documentation will just note that this particular routine uses the alternative registers and you're done Smile

But that's just my 2cts... (Plus: who else is going to use that lib and which other program than the one you're currently working on uses this lib? Wink )

Por Edwin

Paragon (1182)

imagem de Edwin

22-04-2007, 13:56

In my experience, exx is rarely a solution for the problem because you lose the current values of bc, de, hl as well. Which you don't really want because you were out of registers for a reason. In that case it's a very good solution to use ixl, ixh, iyl and iyh for storage of 8 bit values or counters. In many cases it's the faster solution. I use them quite a lot myself. Much more than exx. I haven't heard of any compatibility issue with any msx machine.

Por wolf_

Ambassador_ (10076)

imagem de wolf_

22-04-2007, 14:34

NYYRIKKI: do you obfuscate your tax forms as well, like that? Hannibal

Por PingPong

Prophet (4086)

imagem de PingPong

22-04-2007, 16:32

In my experience, exx is rarely a solution for the problem because you lose the current values of bc, de, hl as well. Which you don't really want because you were out of registers for a reason. In that case it's a very good solution to use ixl, ixh, iyl and iyh for storage of 8 bit values or counters. In many cases it's the faster solution. I use them quite a lot myself. Much more than exx. I haven't heard of any compatibility issue with any msx machine.

I agree: most people under-estimate the index registers claiming that they are slow, but exchanging register bank could be even slow or more slow, especially if you need to have on-line all the register values (normal+switched). this usually need a lot of EXX where storing values in ix (H/L) and iy (H/L) does not need anything.

the trick is to use ix/iy for rare-changing values...

Of course, always depends to the use you need to do.

Por Chardson

Champion (411)

imagem de Chardson

22-04-2007, 22:34

Yeah, I could use them, but this routine belongs to a lib I am doing while I work on the main program. And I don't think it is good for a "general" routine to use exx. If so, every "general" routine should use them and main programs should never. WinkDocumentation is the key here. You're also using the normal registers - all of them, apparently. Does that imply that main programs should never do that? No, it means that if the main program uses the registers, it has the responsibility to save their values somewhere - e.g. on the stack - before calling your lib function, and restore them afterwards. The same holds for the alternative register set: if the main program uses it, it will have the responsibility to save the contents.
Your lib documentation will just note that this particular routine uses the alternative registers and you're done Smile

But, IMHO, saving all registers and the alternate ones would need so many push'es and pop's that it is not worth it. I prefer to save exx registers to routines that have any sort of (semi-)parallel processing.

Also, I couldn't agree more with Edwin. This routine mine, I can't switch actual bc, de and hl values, because they all need to be used. It would be very tricky to use exx all the time and correctly.

But that's just my 2cts... (Plus: who else is going to use that lib and which other program than the one you're currently working on uses this lib? Wink )

Probably, none after me is going to use it. But when it is done, I will share it on internet Smile. And no other program uses it, but the intention is that my next projects will rely on them.

Por AuroraMSX

Paragon (1902)

imagem de AuroraMSX

23-04-2007, 22:13

In my experience, exx is rarely a solution for the problem because you lose the current values of bc, de, hl as well. Which you don't really want because you were out of registers for a reason.Good point. On the other hand, if you just want some register space for an extra loop counter, exx may still be an option. It's probably just me, but using undocumented instructions grates my nerves a bit Wink

Por wolf_

Ambassador_ (10076)

imagem de wolf_

23-04-2007, 22:22

short message of unimportance: Chardson's post was a quote-mess.. Tongue Plz do read what you post within the edit-time. Now and then some oddness flips through that wouldn't have been there if we all check what we post. Tnx! Running Naked in a Field of Flowers

Por AuroraMSX

Paragon (1902)

imagem de AuroraMSX

23-04-2007, 22:29

short message of unimportance: Chardson's post is a quote-mess.. Tonguebut now it's all correct-mess eh... correctness, thanx to wolfness

Página 2/2
1 |