prefix bytes: an idea for 65Org816
Posted: Fri Mar 12, 2010 9:20 pm
A previous thread explored various ideas for enhancing the 6502, and came up with two specific implementation ideas: the 65Org32 and the 65Org16, which have 32-bit and 16-bit "bytes" respectively, retaining the general shape of the 6502 programming model, but with naturally wider data.
In both those cases we get some extra space in the opcodes, which we can use for novel opcodes, for implicit operands, for operations like multibit shifts or small-constant increments, for specifying alternate registers, and so on.
Since then Ruud mentioned the idea of prefix bytes in the (not) TTL 6502 thread (and indeed the ST7 has three prefix bytes, to add one or both of two modifications to instructions)
Looking at a table of 6502 opcodes, leaving aside all the post-6502 enhancements, we see 4 columns of undefined bytes and another 30-plus sporadic undefined bytes.
It might be interesting to speculate on what use could be made of those undefined values, if we allow one optional prefix byte and leave unprefixed defined operations to act the same as they do on 6502. I'll assume that a prefix byte takes one additional clock cycle, and that complexity of instruction decoding isn't a limiting factor - I'm thinking of FPGA implementation.
The 4 undefined columns naturally suggest a 6-bit extension field to normal operations: could be 1 or 2 single-shot mode bits and 4 or so address bits, varied according to the instruction being modified.
The 30 or so sporadic undefined bytes could be used in one of two ways: as a prefix byte, or as an unprefixed novel opcode.
Ideally the prefixed forms would be used for less common operations, or more expensive operations, to decrease the effective cost of the prefix. For example, using a prefix for a 16-bit memory operation because that will take extra cycles anyway.
That gives us 5 types of (composite) opcode:
1 - single-byte 6502 opcodes, with the usual operands, if any
2 - up to 30 or so novel opcodes
3 - 6502 opcodes prefixed by one of the 4 undefined columns
4 - any other byte prefixed by one of the 4 undefined columns
5 - 6502 opcodes prefixed by one of the 30 sporadic undefined bytes
No need to define and use all of them, of course. But I think it shows there's lots of space to fit in various ideas.
Some initial ideas on how to use the extra control bits or opcodes:
1. specify one of 8 or 16 registers
2. specify 8 or 16-bit datatype (or maybe 32-bit or 24-bit)
3. more bits to relative branches
4. small constants for shift or increment operations
5. multi-register push and pop
6. re-introduce some favourite post-6502 enhancements
(In some ways, this could be viewed as a second take on the 65816, which is a compatible extension but with practical limits on implementation complexity to make an economically small custom chip. This is a compatible extension with more implementation freedom, for FPGA.)
In both those cases we get some extra space in the opcodes, which we can use for novel opcodes, for implicit operands, for operations like multibit shifts or small-constant increments, for specifying alternate registers, and so on.
Since then Ruud mentioned the idea of prefix bytes in the (not) TTL 6502 thread (and indeed the ST7 has three prefix bytes, to add one or both of two modifications to instructions)
Looking at a table of 6502 opcodes, leaving aside all the post-6502 enhancements, we see 4 columns of undefined bytes and another 30-plus sporadic undefined bytes.
It might be interesting to speculate on what use could be made of those undefined values, if we allow one optional prefix byte and leave unprefixed defined operations to act the same as they do on 6502. I'll assume that a prefix byte takes one additional clock cycle, and that complexity of instruction decoding isn't a limiting factor - I'm thinking of FPGA implementation.
The 4 undefined columns naturally suggest a 6-bit extension field to normal operations: could be 1 or 2 single-shot mode bits and 4 or so address bits, varied according to the instruction being modified.
The 30 or so sporadic undefined bytes could be used in one of two ways: as a prefix byte, or as an unprefixed novel opcode.
Ideally the prefixed forms would be used for less common operations, or more expensive operations, to decrease the effective cost of the prefix. For example, using a prefix for a 16-bit memory operation because that will take extra cycles anyway.
That gives us 5 types of (composite) opcode:
1 - single-byte 6502 opcodes, with the usual operands, if any
2 - up to 30 or so novel opcodes
3 - 6502 opcodes prefixed by one of the 4 undefined columns
4 - any other byte prefixed by one of the 4 undefined columns
5 - 6502 opcodes prefixed by one of the 30 sporadic undefined bytes
No need to define and use all of them, of course. But I think it shows there's lots of space to fit in various ideas.
Some initial ideas on how to use the extra control bits or opcodes:
1. specify one of 8 or 16 registers
2. specify 8 or 16-bit datatype (or maybe 32-bit or 24-bit)
3. more bits to relative branches
4. small constants for shift or increment operations
5. multi-register push and pop
6. re-introduce some favourite post-6502 enhancements
(In some ways, this could be viewed as a second take on the 65816, which is a compatible extension but with practical limits on implementation complexity to make an economically small custom chip. This is a compatible extension with more implementation freedom, for FPGA.)