For a learning project like this one, this would probably be overkill, but my personal suggestion for instruction decoding is that it really pays in the long term to use a data driven decoder. It's fairly easy to do a handcoded "if bits A..B are 0b1000 and..." decoder for the basic integer parts of the instruction set, but especially as you get into complexities like SIMD and if you need your decoder to be easy to mo…
It's a kind of serialization/deserialization, or what I think Python and some others call "pickling". Same task. Turn these raw bit patterns into typed values.
Ada probably comes closest of the major languages to pulling it off. It has separation of the abstract/programmer's view of a data type and the implementation / low representation of that type.
Specify a bunch of records like:
for Instruction use record
Condition at 0 range 31 .. 28;
ImmFlag at 0 range 27 .. 27;
Opcode at 0 range 24 .. 21;
CondFlag at 0 range 20 .. 20;
Rn at 0 range 19 .. 16;
Rd at 0 range 15 .. 12;
Operand at 0 range 11 .. 0;
end record;
Then aim a pointer at your instructions and read them as records/structs.It works particularly cleanly with a nice RISC encoding like ARM. I'm not actually sure if that would work in Ada. The use representation syntax might not be generic enough.