Post
by tvrfan » Sun Nov 15, 2015 4:40 pm
John,
There's a couple of things here .....
First, let me say YES - it IS very confusing to have different sizes of ops, and even worse when some options use an odd 'register' value. Frankly, I think it's a pain in the arse. If all ops were the same size, it would be *FAR* easier to decode, just for starters. Unfortunately in the olden days of computing, space was much more at a premium, and RAM cost a lot of money, clock speeds lower, so stuff was squeezed into small spaces for speed and compactness.
Operands - some operations are 'commutative', which means order independent. For example, addition, A+B = B+A; this also applies for multiplication.
This is not true for subtraction or divison of course, B-A != A-B . I say this little thing in case it helps, it's quite possible that pocket guide actually has a couple of things in the wrong order, it doesn't matter in many cases, but will confuse the poor learner.
What I did in SAD was to have a master operand table (you will see that in source code I posted), and it defines what goes where in terms of operands, size, and other stuff.
It's actually got quite a bit of info in that structure, necessary to decode correctly, and even then it still needs some 'C' code for the final details. It's not at all simple.
Generally - I believe these are always true (someone correct me if I'm wrong !!)
The last operand in the opcode sequence (=byte) is ALWAYS the destination register, except for STW, STB. [obviously not for jumps,ret, etc]
For 3 op operands, e.g. AD3W, the last two bytes are always registers, with last as destination.
The multimode opcodes (as example above) the 'option' always starts at the first operand, (be that an immediate, register, or indexed/ indirect address) .
Jump offsets are always relative to the start of next opcode (plus or minus as relevant).
Hope that helps a bit, no easy answer..