Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decoding 68k instructions

I'm writing an interpreted 68k emulator as a personal/educational project. Right now I'm trying to develop a simple, general decoding mechanism.

As I understand it, the first two bytes of each instruction are enough to uniquely identify the operation (with two rare exceptions) and the number of words left to be read, if any.

Here is what I would like to accomplish in my decoding phase:

1. read two bytes
2. determine which instruction it is
3. extract the operands
4. pass the opcode and the operands on to the execute phase

I can't just pass the first two bytes into a lookup table like I could with the first few bits in a RISC arch, because operands are "in the way". How can I accomplish part 2 in a general way?

Broadly, my question is: How do I remove the variability of operands from the decoding process?

More background:

Here is a partial table from section 8.2 of the Programmer's Reference Manual:

Table 8.2. Operation Code Map

Bits 15-12      Operation
0000            Bit Manipulation/MOVEP/Immediate
0001            Move Byte
...
1110            Shift/Rotate/Bit Field
1111            Coprocessor Interface...

This made great sense to me, but then I look at the bit patterns for each instruction and notice that there isn't a single instruction where bits 15-12 are 0001, 0010, or 0011. There must be some big piece of the picture that I'm missing.

This Decoding Z80 Opcodes site explains decoding explicitly, which is something I haven't found in the 68k programmer's reference manual or by googling.

like image 235
mwcz Avatar asked Nov 05 '22 14:11

mwcz


1 Answers

I've decided to simply create a look-up table with every possible pattern for each instruction. It was my first idea, but I discarded it as "wasteful, inelegant". Now, I'm accepting it as "really fast".

like image 133
mwcz Avatar answered Nov 16 '22 11:11

mwcz