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

Re: 6502 illegal opcodes questions



John Selck wrote:
Am 19.05.2006, 22:34 Uhr, schrieb Eric Smith <eric@brouhaha.com>:

"John Selck" <gpjiweg@t-online.de> writes:

And then we would have ended up like the Z80: That a copy loop is faster
than the actual block copy instruction :D


Can you cite an example?  The block move instructions on the Z80 are
actually fairly efficient.  They use three memory cycles to move a byte,
vs. the theoretical minimum of two.  Doing a block copy via a software
loop is going to require at least five memory cycles per byte moved, and
probably more.


LDIR eats 21 clock cycles per iteration, doing the same with other Z80
instructions can be way faster.

I tried to use the Z80 in the C128 for block copy/fill because I thought
"hey, it has a block copy command, so I guess it is fast" but it wasn't.
Then I tried normal opcodes, it was way faster than using LDIR but still
not faster than copying the stuff with the 8502.

Here's a list of Z80 instruction and their clock cycles:

http://www.ftp83plus.net/Tutorials/z80inset1A.htm

I would like to point out that these are 21 Z80 clocks going twice the rate of a 6502 (I don't know if this is true for C128 but 1MHz 6502 is comparable to a 2MHz Z80 and were competing side by side). If you are going to move only a few bytes it is more efficient to do so by load, store, load, store etc... less setup and no looping.

I think you are wrong if you are talking about more data. LDIR is the most convenient and fastest way to copy a block of data with the Z80. I think doing any form of loop is slower. (Even if you use the POP instruction and keep within a page you end up at 21.5 clocks per byte).

The Z80 is not a memory oriented processor its strength is to have many registers (for the mid/late 70's) and to have efficient instructions using them. 6502 is contrary, it has almost no registers but do memory access more efficiently and ends up with a fairly similar performance. 6502 might well do a memory block move faster than Z80.

To say something on this threads topic the Z80 also has undocumented/illegal opcodes and a few are convenient to use. These are a result of the instruction decoding and work in all the real Z80's. Most of the "illegal" instructions are just "advanced" NOP's that takes longer than a normal NOP. Some with strange effects on flags though. It is especially a topic for emulators, to do these correctly...

Knut