Crea sito

CPU Z80 vs MOS 6502 (English version)

[Final synthesis, an American comparison]

on the left side here is the MOS 6502 on the right side you can see the CPU Z80

Before to read this article, please remove any faction flag. I decided to go deeper into the topic already discussed in the article [ Aleph-Proect: the choice of the CPU(Italian)]. Simply because I believe that the last article did not provide a clear example, and never focuses which are the real differences, that should characterize this choice.

Although in that article I showed, in broad terms those information concerning the architecture of the processor, those features do not translate into readily understandable informations (for non-experts).

The devil is hidden in the details

When, in a technical manual it is said that a CPU 6502 performs an operation in a lower number of machine cycles than the Z80, in reality it is not said that the 6502, only performs elementary operations “all in eight-bit mode only”. So to perform a sum between two 16-bit numbers such as: 8960 + 2132, you cannot use ADD HL, BC, but you must make a small “program” that twice sums the eight-bit registers and the carryover must be considered for each sum added over the calculus made.

– This means that working with such a CPU means having to do “long encodings” like you do on RISC processors. – Instead, the Z80 CPU already has numerous instructions for executing 16-bit sums, and instructions for loops and moving memory blocks. In short, whoever chooses a MOS 6502 CPU, chooses a more “stupid” CPU to which everything must be explained.

The advantage of the CPU 6502 consists in the fact that, once the problem is broken down, the MOS 6502 manages to deal with it, with a lower number of machine cycles compared to the ZILOG Z80 counterpart. But this value never materializes in a faster calculation speed, because the MOS 6502, which started with a maximum speed of 1 Mhz, was then brought to 2 Mhz, in the HCMOS version. But remember that the ZILOG Z80 was designed to operate at 4 Mhz, in the Z80A version, and then subsequently reached the speed of 20 Mhz in the HCMOS or Z80C version.

PLEASE NOTE: the NEC D780C at 3.5 MHz of the Zx-Spectrum was an inefficient clone of the Zilog Z80 and had inferior characteristics if compared with the Zilog Z80A.

Considering what told above, here is the situation that unfolds for the programmer who wants to move a 16K bytes buffer from one memory location to another. Those who choose a CISC type of architecture make a more compact assembly coding, because the processor has its specific instructions for managing even more complex operations. On the other hand, those who decide to program “a sort of RISC CPU” but with a slower clock, in terms of Mhz, find themselves having to make long encodings in which every single intermediate data passage must be explained. And this major work will not be rewarded by a greater speed of execution. This is the evidence of the facts and this is the true question that appears when it has been private of nostalgia for disappeared brands, of the years gone by. – Today, in the time that I write, the fastest processor in the world is a CISC processor built by INTEL that is backwards compatible with the i8088’s, and that is compatible with a close relative of the Zilog Z80. –

FOLLOWS AN ASSEMBLY CODING EXAMPLE: the test code, copies all the data starting from the address 8000 HEX to the address BFFF HEX in the area included by the interval [C000 HEX … FFFF HEX].
– The Z80 employs 86 mSeconds at 4Mhz (minimum speed).
– MOS 6502 takes 131.5 mSeconds.

The Z80 is true that it uses more machine cycles for an equivalent complex operation, but these cycles can run at a higher frequency, just because the processor has a longer pipe-line, and an internal clock different from the one applied at the entrance. The Z80Cs I tried were not affected by any problems even if they were over-charged by 30% of cpu clock frequency. In summary, all the 10Mhz Z80s I have tested have worked for at least 5 years at 13.5 MHz, without any anomaly found.

The same cannot be said of MOS 6502, which mounted at 4 Mhz, in the Apple it was necessary to slow it down to 1 Mhz, for the input / output with the peripherals. – Also note that the devices on MOS 6502, “can only be mapped in RAM”, losing memory addresses useful to the system. – Instead the Z80 can address 256 I / O devices without losing a single byte of memory, because it manages the INPUT / OUTPUT in a separate address space.

[There are not many known bugs on the Z80 cpu, its reliability is beyond doubt]
Even the unpublished op-codes seems to work well on all the cpu I tried. The only op-codes that show abnormal behavior are: OTIR,
OTDRs that would not update the carry-flag as documented.

[The BUG chapter of 6502, is full of cases where the programmer just has to give up]
[Wikipedia-English [bug of processor 6502]

Source-code comparison between cpu 6502 (left), and Zilog Z80 (right)

8 Risposte a “CPU Z80 vs MOS 6502 (English version)”

  1. Why not move code from 8000..bfff -> C000..ffff by selfmodifying code?

    ldx #$00
    Rep lda $8000,x
    Chg sta $c000,x
    inx
    bne rep
    inc Rep+2
    inc Chg+2
    bne Rep
    rts

    1. Infoelettronica

      @ GoNiLoTTo
      The self-modifying code is a trick that only works on features written in ram. – A system routine written in ROM, could not use this “trick”. However you are right to talk about it, because it is right that we also know these things. Every INTELLIGENT idea is always welcome. Good proposals deserve good answers.

      (from 6502.org)
      Even more speed can be gained by using self-modifying code, i.e. replacing the (ZeroPage),Y addressing mode with the Absolute,Y addressing mode. This will take 2 fewer cycles per byte. There will be some additional cycles from the added instructions that self-modify the code, but the self-modification occurs only once, and therefore adds these cycles to total number of cycles, rather than the number of cycles per byte moved. As always, the instructions that are self-modified can’t be located in ROM.

      http://6502.org/source/general/memory_move.html

      1. Z80 LDIR with its 21t/byte is far from the fastest way to copy data. There are faster ways.
        Using bunch of LDI (loop unrolling) – 16t/byte.
        Using stack: POP:POP:POP… – PUSH:PUSH:PUSH… (regpairs), which gives roughly ~ 10+11t per two byte, or 21/2 ~= 10.5t per byte + some time for SP setup and EXX:EX AF,AF’s… This is top for block-transer speed for Z80.
        Note there are memory fill using bunch of PUSH, which is 11t/2byte = 5.5t per byte.

        1. Thank you Alex. A good contribute. This test was made to be a school examples so i couldn’t tell it inside the main post. But I like that you know this method, this was said some years ago on some forums.
          (I share the link)

          https://retrocomputing.stackexchange.com/questions/4744/how-fast-is-memcpy-on-the-z80

          If someone wants to visit the (Alex) site
          (here is the link)
          http://www.worldofspectrum.org/Flash/

          If someone want contact the author of Infoelettronica on Facebook
          here is the group link
          https://www.facebook.com/groups/2137592983022885/

  2. The ZX Spectrum’s Z80 was running at 3.5MHz because the clock was derived from the 14MHz clock used by the ULA to generate the video signal… not because of poor performances of the CPU. Some ZX Spectrum used “true” Z80 (from Zilog) and not clones from NEC.

    1. From Infoelettronica
      @ DENNIS

      Yes what you say about ULA is true. And some SPECTRUMs had the ZILOG processor. However (officially) it was amstrad cpc 464 who declared it in the specifications. Many MSXs have the NEC D780C-1, while others have the Zilog. – It is a rather difficult search for details, because companies have not always been consistent with the proposed specifications to customers. But basically when it is said of inferior characteristics, I mean small technical details.

      For example the (clone Z80) NEC D780C-1 has a [DELAY MAX on falling edge of _MREQ equal to 100nS]

      The mostek (clone Z80) MK3880 has a DELAY MAX on falling edge of _MREQ equal to 80nS]

      It has a higher stability in “overclock”, it stays colder.
      But this does not mean that it is not a good processor, because the NEC D780C-1 is perfectly identical to the Zilog Z80 “original” (1976) before the zilog emitted the Z80A, Z80B, Z80C.

      (NEC D780C-1)
      https://datasheetspdf.com/pdf/520058/NEC/D780C/1

      (zilog “ORIGINAL” before z80A tecnical MANUAL)
      http://www.classiccmp.org/cini/pdf/Zilog/Zilog%20Z80-CPU%20Technical%20Manual.PDF

      (Mostek mk3880)
      http://datasheets.chipdb.org/Mostek/3880.pdf

  3. Your cherry picked comparison is cherry picked.

    1. The 6502 isn’t very fast at block copies, and the Z80 is, so this example favors the Z80. But you leave out the part where the 65816, has memory move opcodes that take 7 clock cycles per byte, and if the memory being moved uses fixed addresses (like scrolling a graphics screen), it can move a block of memory at the rate of about 5 clock cycles per byte using 16 bit code and a partially unrolled loop. FWIW, that’s not even the fastest way to implement a block memory move on the Z80.

    2. You use 16 MHz for the Z80 while conveniently ignoring the fact that Apple IIc Plus machines have been upgraded to speeds as high as 16 MHz using a different clock, faster 65C02, and faster cache RAM. Some 65816 upgrades for certain machines have been clocked over 20 MHz. Just using a 16 MHz clock speed makes the 6502 faster than the Z80 for your example even though even though the 6502 isn’t good at that.

    3. The 6502 bugs were fixed in the 65C02 and 65816.

    4. The Hitachi HD64180 and Zilog Z180 run Z80 code faster, and are available in speeds as high as 33 MHz. They also include some additional instructions making some code optimizations possible if you choose to support the new instructions. A 6 MHz 64180 was advertised as being as fast as an 8 MHz Z80. If you can take advantage of the new hardware multiply instruction, math intensive applications can see an even greater speed improvement. There are Z180 compatible CPUs that offer even greater improvements in the # of clock cycles required per instruction, but they loose some sort of compatibility such as interrupt levels.

    5. Both the Z80 and 6502 are available as FPGA cores that have been clocked over 100 MHz in some designs.

    1. From Infoelettronica
      @ JamesD

      Most of the things you write (I believe they are true). But don’t get confused. – The comparison must be made between two specific subjects.
      A) zilog Z80
      b) mos 6502
      All Z80s can be compared with all MOS 6502s.
      I can’t compare apples with pears, to understand which apple is better. And the cherries are not yet ripe, you could have avoided this expression that “makes you lose score and partiality of judgment”.
      If we want to compare the two families (MOS vs Zilog) then things change.
      Because the MOS 65816 should be compared with the ZILOG Z280 derived from the Zilog Z800. (All this is absurd and sly).

      the comparison of this article can be summarized as follows.

      CMP AX, BX (assembly 8088)
      ax = z80
      bx = mos 6502.

      (STOP).

I commenti sono chiusi.