ive noticed that their is a big difference between the z80 instruction set and the 6502 instruction set

Anything relating to non Sinclair computers from the 1980's, 90's or even before.
Post Reply
User avatar
777
Manic Miner
Posts: 512
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

ive noticed that their is a big difference between the z80 instruction set and the 6502 instruction set

Post by 777 »

only some of the opcodes are the same.are the 2 different processors that different to code for?
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1
catmeows
Manic Miner
Posts: 718
Joined: Tue May 28, 2019 12:02 pm
Location: Prague

Re: ive noticed that their is a big difference between the z80 instruction set and the 6502 instruction set

Post by catmeows »

Not really. They have quite similar set of actions but they differ a lot in adressing modes and also mnemonics for machine code instructions differ a lot.
For example, storing register A into memory byte $8000
Zilog: ld ($8000), a
Motorola sta $8000
Proud owner of Didaktik M
User avatar
777
Manic Miner
Posts: 512
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: ive noticed that their is a big difference between the z80 instruction set and the 6502 instruction set

Post by 777 »

ok i see, so there are equivalents?
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1
User avatar
PROSM
Manic Miner
Posts: 476
Joined: Fri Nov 17, 2017 7:18 pm
Location: Sunderland, England
Contact:

Re: ive noticed that their is a big difference between the z80 instruction set and the 6502 instruction set

Post by PROSM »

777 wrote: Tue Aug 25, 2020 3:10 pm only some of the opcodes are the same.are the 2 different processors that different to code for?
Yes, they are different architectures, designed by two different teams with two different design goals. The 6502 is a simplified version of the Motorola 6800 design, whereas the Z80 is a software-compatible upgrade to the Intel 8080. There are similarities, but the mnemonics, addressing modes and flags differ quite a bit.

If you need to do a quick and dirty conversion, you can use this Z80 to 6502 recompiler from the AtariAge forums. Tools probably exist for the reverse as well. Of course, you'll need to rewrite all of the system-specific code (graphics, sound, etc.)
All software to-date
Working on something, as always.
catmeows
Manic Miner
Posts: 718
Joined: Tue May 28, 2019 12:02 pm
Location: Prague

Re: ive noticed that their is a big difference between the z80 instruction set and the 6502 instruction set

Post by catmeows »

No. Or depends on point of view.
Both can store or read byte, add or subtract a value to/from another one. They can shift byte value left or right, they can jump to another piece od code etc.
But details how it is done on 6502 and z80 are different.
For example, adding two 16 bit values is matter of single instruction on Z80. On 6502, you have not such instruction but you can write short code doing very same thing.
If you want short answer, the both cpus are in same class but have quite different philopsophy how to do things.
Proud owner of Didaktik M
User avatar
777
Manic Miner
Posts: 512
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: ive noticed that their is a big difference between the z80 instruction set and the 6502 instruction set

Post by 777 »

so i guess there is no table of equivalents?
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1
User avatar
PROSM
Manic Miner
Posts: 476
Joined: Fri Nov 17, 2017 7:18 pm
Location: Sunderland, England
Contact:

Re: ive noticed that their is a big difference between the z80 instruction set and the 6502 instruction set

Post by PROSM »

catmeows wrote: Tue Aug 25, 2020 3:31 pm No. Or depends on point of view.
Both can store or read byte, add or subtract a value to/from another one. They can shift byte value left or right, they can jump to another piece od code etc.
But details how it is done on 6502 and z80 are different.
For example, adding two 16 bit values is matter of single instruction on Z80. On 6502, you have not such instruction but you can write short code doing very same thing.
If you want short answer, the both cpus are in same class but have quite different philopsophy how to do things.
Yes, I agree with you there. I suppose my first reply was a bit too general - they are different processors, yes, but the coding style doesn't have to change by much. Both can be programmed to do the same thing, but the implementation details will differ a bit for each processor.
777 wrote: Tue Aug 25, 2020 3:50 pm so i guess there is no table of equivalents?
There is little direct equivalence of instructions between the CPUs, as they both have a different architecture. However, they are similar enough that you should be able to rewrite the code line-by-line without too much alteration. This is what Geoff Crammond did to port The Sentinel to the CPC and Spectrum from the BBC Micro.

EDIT: Interesting bit on this webpage about The Sentinel. You can see the direct comparison between a bit of original 6502 source and the Z80 conversion. There is some equivalence but certain parts have to be implemented in multiple instructions.
All software to-date
Working on something, as always.
User avatar
1024MAK
Bugaboo
Posts: 3123
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: ive noticed that their is a big difference between the z80 instruction set and the 6502 instruction set

Post by 1024MAK »

Yes and no.

Both are 8 bit, but the Z80 can run 8080 code.

The 6502 uses page zero (upper address byte = 0 hex) in place of a lot of register operations. The machine stack is in page one (upper address byte = 1 hex). It has no 16 bit registers. It has many addressing modes.

It has the reset, maskable and the non-maskable interrupt vectors near the top of the memory map.

Hence often there is RAM at the bottom of the memory map (0x0000 upwards) and ROM at the top (0xFFFF downwards).

It is NOT a RISC processor (the 6502 is definitely a CISC type) but some consider it’s simple instruction set to be the inspiration used by Acorn in the development of the ARM which is a RISC processor. The 6502 is very quick to respond to interrupts and jump to an interrupt routine, for example (compared to its competitors of the time).

It’s main reason for being successful, was that it was considerably cheaper than Motorola’s 6800 processor. But could use most of the support chips designed for the 6800. It also helped to reduce system costs by having an on chip clock generator circuit (just add a resistor and capacitor, or a crystal and a couple of capacitors) and did not have multiplexed address/data bus pins.

The Z80 has a 16 bit stack pointer, so the stack can be anywhere in RAM. It has far more registers than all of it’s contemporary rivals. So in simple applications, it does not always need any RAM. At reset it starts execution at address 0x0000, so in most systems you will find ROM from 0x0000.

The Z80 has a separate I/O address space. So there is no need to have the I/O devices mapped into the normal memory map (unlike the 6502).

Because the Z80 has more than 256 instructions, prefix codes are used. So the instructions are variable both in length, and in the time it takes the processor to execute them. This makes interfacing memory mapped video displays more difficult (unlike the 6502 which is far more predictable).

The Z80 has some 16 bit maths instructions plus various clever memory saving instructions.

Z80 code can be made far more compact compared to 6502 code. However there is a speed penalty if a programmer goes too far with this.

Overall, for the same memory bus timing (NOT processor clock speed) there is not much between the 6502 and the Z80 overall. Each has its strengths and weaknesses. Of that era, the winner in terms of processor power is the 6809. But it was late to the party...

Overall, the biggest factor is often the rest of the machine rather than just the processor. In a system with plenty of RAM, more or less anything the 6502 can do, the Z80 can also do. And vice versa.

But if you ask a programmer who is far more familiar with one than the other, he/she will obviously sing the praises of the one they know (and love)...

Mark
Last edited by 1024MAK on Tue Aug 25, 2020 4:12 pm, edited 2 times in total.
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
User avatar
PeterJ
Site Admin
Posts: 6878
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: ive noticed that their is a big difference between the z80 instruction set and the 6502 instruction set

Post by PeterJ »

If you Google 'convert 6502 to z80' there are plenty of threads. The general consensus seems to be don't try and convert. I've only looked briefly though
User avatar
1024MAK
Bugaboo
Posts: 3123
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: ive noticed that their is a big difference between the z80 instruction set and the 6502 instruction set

Post by 1024MAK »

The question of converting code from one to the other, is the same as converting code from one language to another language. There will be some common operations / instructions. But although both can run a program that does exactly the same thing, the detail of how it’s done is different between them.

A good Z80 coder will know most, if not all of the tricks of the Z80. Similarly, a good 6502 coder will know most, if not all of the tricks of that processor.

One of the reasons for the mnemonics being so different is because the companies did not want to have legal trouble. And wanted to do their own thing.

The Z80 mnemonics are intensionally different to Intel’s 8080 mnemonics for example.

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
catmeows
Manic Miner
Posts: 718
Joined: Tue May 28, 2019 12:02 pm
Location: Prague

Re: ive noticed that their is a big difference between the z80 instruction set and the 6502 instruction set

Post by catmeows »

1024MAK wrote:Of that era, the winner in terms of processor power is the 6809. But it was late to the party...
I have developed strange obsession about 6809. It started as simple idea of Speccy based on 6809.
Now, few months later, I have found myself writing specs for the computer. Weird.
Proud owner of Didaktik M
User avatar
1024MAK
Bugaboo
Posts: 3123
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: ive noticed that their is a big difference between the z80 instruction set and the 6502 instruction set

Post by 1024MAK »

The Hitachi 6309 is even better... :lol:

I got one to play with, but that project has not gone anywhere yet :oops:

You do have watch out for the different types, there are two different clock input designs.

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
User avatar
PeterJ
Site Admin
Posts: 6878
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: ive noticed that their is a big difference between the z80 instruction set and the 6502 instruction set

Post by PeterJ »

1024MAK wrote: Tue Aug 25, 2020 4:05 pm The winner in terms of processor power is the 6809. But it was late to the party...
Such a pity it was wasted on the Dragon 32, though in all honesty my negative view of the machine comes from the poor graphics and uppercase only character set.
catmeows
Manic Miner
Posts: 718
Joined: Tue May 28, 2019 12:02 pm
Location: Prague

Re: ive noticed that their is a big difference between the z80 instruction set and the 6502 instruction set

Post by catmeows »

PeterJ wrote: Tue Aug 25, 2020 6:32 pm
1024MAK wrote: Tue Aug 25, 2020 4:05 pm The winner in terms of processor power is the 6809. But it was late to the party...
Such a pity it was wasted on the Dragon 32, though in all honesty my negative view of the machine comes from the poor graphics and uppercase only character set.
Motorola provided family of support chips for their cpu and Dragon 32 (and Tandy Color Computer) is Motorola 6809, Motorola SAM (Synchronous Address Multiplexer), Motorola VDG (Video Display Generator) plus some RAM and ROM with Microsoft's BASIC. Kind of cheap, out of box, Motorola computer. The only thing you need to do is to design case and keyboard layout.
Even without custom video hardware like Sinclair or Commodore had, they still could choose better video by Motorola or Texas Instrument.
Proud owner of Didaktik M
User avatar
1024MAK
Bugaboo
Posts: 3123
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: ive noticed that their is a big difference between the z80 instruction set and the 6502 instruction set

Post by 1024MAK »

PeterJ wrote: Tue Aug 25, 2020 6:32 pm
1024MAK wrote: Tue Aug 25, 2020 4:05 pm The winner in terms of processor power is the 6809. But it was late to the party...
Such a pity it was wasted on the Dragon 32, though in all honesty my negative view of the machine comes from the poor graphics and uppercase only character set.
The graphics and text limitations are partly due to the chip used, the 6847.

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
Post Reply