What is a good design for expanding opcodes? Are there any tutorials on YouTube or good text tutorials on designing expanding opcodes? I always make mistakes on switching from one line to another and "counting" in binary. I pretty much know how to design them, but I don't really understand it and I make so many mistakes. I also don't have any examples to go by and check my answer.
Here's one example of what kind of designing and exercises I need:
Design 1 three-address instruction, 10 two-address instr, 7 one-address instr and 4 zero-address instr. The addresses are 8 bits each and 2 bits for an instruction (style: 00 xx yy zz)

So I went about doing designing it like this:

00 xx yy zz

00 00 yy zz
00 01 yy zz
00 10 yy zz
00 11 yy zz
10 00 yy zz
10 01 yy zz
10 10 yy zz
10 11 yy zz
11 00 yy zz
11 01 yy zz

11 10 00 zz
11 10 01 zz
11 10 10 zz
11 10 11 zz
11 11 00 zz
11 11 01 zz
11 11 10 zz

11 11 11 00
11 11 11 01 
11 11 11 10 
11 11 11 11


and the last one is all 1s so I guess it's correct. Maybe if there are no tutorials on YouTube, someone can simplify it or explain it here in text?
It looks like this is simply the problem of mapping a set of possible values (i.e., possible instructions) to some bit encoding.

You haven't specified whether all instruction encodings need to have the same length.


If they can have different lengths, usually you'll want them to form a prefix-free encoding (no encoded value is a prefix of any other).
If all instruction encodings must have the same length,any mapping that gives different instructions different encodings is acceptable.


Your solution doesn't look OK to me.  00 00 yy zz is a prefix of 00 xx yy zz if xx, yy, and zz are the addresses 00000000.

Editorial comment: the exercise is a bit boring and trivial, and doesn't involve much in the way of deep concepts.  It's just a matter of "bit-packing".