The main emphasis of this tutorial is that it is necessary to differentiate between the different classes of instructions. This means that we need to set aside special bitpatterns for the opcodes (the opcodes tell the processor what to do; e.g. add two numbers together), resulting in limitations on the number of instructions that we can define.
Differentiation is important as it tells the processor what to do with each part of an instruction. For example, in question A1 the 15 bits after the 3-bit opcode can either be address or opcode, depending on whether the instruction is from class I, J or K.
Since the processor will do very different things with those 15 bits depending on whether it is opcode or address, it is necessary that the processor knows from the start which class an instruction comes from.
Question A1
There’s a huge range of possibilities for this question, and I will go through only the one that is in the lecture notes. See if you can come up with other possible designs.
The important thing in designing expanding opcode schemes is that if the instruction opcodes were to be fully enumerated, the opcode patterns of different classes must not overlap.
That said, let’s see how we can design this opcode. The instruction set for this question consists of 3 classes (which we will call I, J and K for convenience). All instructions are 36 bits long, addresses are 15 bits long, and register numbers are 3 bits long.
Class I: 7 instructions, each with 2 addresses and 1 register
Class J: 500 instructions, each with 1 address and 1 register
Class K: 50 instructions, with no addresses or registers.
The rule of thumb is that we should always start designing the “most complex” instruction first. This would be class I, with 2 addresses and 1 register.
Class I
Opcode1 (3 bits) Address 1 (15 bits) Address 2 (15 bits) Register (3 bits)
We need to differentiate class I from the remaining classes, and we also require 7 instructions (i.e. 7 opcodes) for class I. This is ok, since we have 3 opcode bits, allowing us a total of 8 opcodes. We set aside the pattern 000 to indicate that an instruction is not from class I, and we use the patterns 001 to 111 for class I insturctions.
So for class I we have:
Opcode1 (3 bits) Address 1 (15 bits) Address 2 (15 bits) Register (3 bits)
001 – 111 anything anything anything
We move on to the next class, class J:
Class J
Opcode1 (3 bits) Opcode2 (15 bits) Address 1(15 bits) Register (3 bits)
Opcode1 must take the value of 000, as 001 to 111 are reserved for the class J instructions. We need 500 instructions for class J, and hence we require 9 bits for the opcode. Since we have 15 bits for Opcode2, this leaves us with 6 bits spare, so we will divide the 15 bits of Opcode2 into a 6 bit portion and a 9 bit portion.
We design the opcodes such that if the first six bits of opcode2 is 000000, the instruction is a class J instructions, and the remaining 9 bits will hold the 500 opcodes.
Opcode1 (3 bits) Opcode2 (15 bits) Address 1(15 bits) Register (3 bits)
000 000000xxxxxxxxx Anything Anything
Here xxxxxxxx is the 9 opcode bits for the 500 instructions.
Class K
For class K, we only require 50 opcodes. The six-bit portion of opcode2 can still be used as opcodes for this class, as long as they do not take on the value of 000000, since this is reserved for class J. So we have:
Opcode1 (3 bits)
000
Opcode2 (15 bits)
000001 to xxxxxxxxx
110010
Unused
Don’t care
Unused
Don’t Care
The 9 bit portion is unused in this case.
Question A-2
We are to design an expanding opcode scheme for this machine:
Instruction length: 12 bits
Register Number length: 3 bits
Class I: 4 instructions with 3 registers
Class J: 255 instructions with 1 register
Class K: 16 instructions with 0 registers
We begin, as usual, with the most complex instruction, which is class I in this case.
Opcode1 (3 bits) Register 1 (3 bits) Register 2 (3 bits) Register 3 (3 bits)
We only require 4 opcodes out of a possible 8. We choose 000 to 011, since this allows us to use the first bit to differentiate class I from the rest of the instruction classes (i.e. for class I the first bit is always 0):
Class I
Opcode1 (3 bits) Register 1 (3 bits) Register 2 (3 bits) Register 3 (3 bits)
000 to 011 Anything Anything Anything
Class J
We require 255 instructions in this class, and therefore we need 8 bits to do this. The instruction format will therefore be:
Opcode1 (3 bits) Opcode2 (3 bits) Opcode3 (3 bits) Register 1 (3 bits)
Remember that the first bit of Opcode1 is used to differentiate between class I and the rest of the classes. For class J and K, this bit is always 1. The remaining 2 bits of opcode1, plus the 3 bits of opcode2 and 3 bits of opcode3 will give us the 8 bits we require.
We also need to differentiate between class J and K. Fortunately 8 bits gives us 256 opcodes, and we only need 255. So we set aside the pattern 111111111 for class K.
So for class J, we have:
Opcode1 (3 bits) Opcode2 (3 bits) Opcode3 (3 bits) Register 1 (3 bits)
100
to
111
000 to
111
000 to
110
Anything
Taking all 3 opcode parts together, this gives us a range of 100000000 to 111111110, which is 255 opcodes.
Class K
For class K, we have this format:
Opcode1 (3 bits) Opcode2 (3 bits) Opcode3 (3 bits) Opcode4 (3 bits)
Opcode1, 2 and 3 must be set to 111111111 to differentiate class K from class J, so we have:
Opcode1 (3 bits) Opcode2 (3 bits) Opcode3 (3 bits) Opcode4 (3 bits)
111 111 111 000 to 111
Unfortunately we have only enough bits for 8 opcodes, but our design states that there should be 16 opcodes in class K. Hence it is not possible to fulfill the requirements of the design.
Question A-3
The machine in this question as 16 bit instructions, with 6 bit addresses, and two classes of instructions:
Class I: n instructions with 2 addresses
Class J: 1 address instructions.
Let’s look at the instruction format for class I:
Class I
Opcode1 (4-bits) Address1 (6-bits) Address2 (6-bits) n opcodes Anything
Note that the number of opcodes here is n , NOT 16!
For class J, our instruction format is as follows:
Class J
Anything
Opcode1 (4 bits)
16 – n opcodes
Opcode2 (6 bits)
64 opcodes
Address1
Anything
4 bits gives us 16 possible opcodes, of which n are used for class I instructions. This gives us (16n ) opcodes left for class J. Opcode2 has a total of 2^6 = 64 opcodes.
Hence the maximum number of opcodes available for class J is just simply:
64(16 – n )
Question A-4
This question is largely a problem of figuring out all the possible opcode values for each class of instructions. This really isn’t as difficult as it sounds.
For this machine, instructions are 12 bits in length. Addresses are 4 bits. There are 3 classes of instructions:
Class I: 2 addresses
Class J: 1 address
Class K: 0 addresses
Part a:
To find the maximum number of instructions in class J, we must minimize classes I and K. The minimum for each class is 1, NOT 0! Setting the minimum to 0 will contradict the requirements for 3 instruction classes.
We will work out the bit patterns for classes I and K first, so that we know what range of bit patterns to eliminate for the possible class J opcodes.
Let’s work on class I first, since it has the most complex instruction format. We want exactly 1 instruction in this class, and we arbitrarily assign the opcode value 000 to
Opcode1 for this instruction.
Class I
Opcode1 (4 bits)
0000
Address1 (4 bits)
Anything
Address2 (4 bits)
Anything
Class K
We move on to class K. Opcode1 can be any value except 0000, and the remaining
Opcode2 and Opcode3 can be any value. We only want 1 instruction for class K, and we arbitrarily take:
Opcode1 (4 bits) Opcode2 (4 bits) Opcode3 (4 bits)
0001 0000 0000
Class J
This is the complicated part. If Opcode1 takes on any value between 0010 and 1111, then Opcode2 can take any value between 0000 and 1111. On the other hand, if
Opcode1 takes the value of 0001, then Opcode2 cannot take the value of 0000, or this instruction becomes a class K instruction. We have these possibilities:
Opcode1 (4 bits)
0010 to 1111
(14 combinations)
0001
Opcode2 (4 bits)
0000 to 1111
(16 combinations)
0001 to 1111
(15 combinations)
Address (4 bits)
Anything
Anything
(1 combination)
Total number of possible class J opcodes is therefore (14 x 16) + (1 x 15) = 239 opcodes.
Part b:
Part b is tackled in a similar manner to Part a, except that this time we minimize classes I and J instead. Again, we use 0000 for Opcode1, for class I
Class I
Opcode1 (4 bits) Address1 (4 bits) Address2 (4 bits)
0000 Anything Anything
For class J, Opcode1 cannot have the value 0000, while Opcode2 can take any value.
We chose 0001 and 0000 for opcode1 and opcode2 respectively:
Class J
Opcode1 (4 bits)
0001
Opcode2 (4 bits)
0000
Address1 (4 bits)
Anything
We can now work out how many opcodes we can have for class K. If Opcode1 takes a value between 0010 and 1111, then Opcode2 can take any value. If Opcode1 takes a value of 0001, then Opcode2 MUST NOT take a value of 0000 (0001 0000 is reserved for class J instructions, and can therefore take any value between 0001 and
1111. In either case, Opcode3 can take any value between 0000 and 1111. So we have these 2 possibilities:
Opcode1 (4 bits) Opcode2 (4 bits) Opcode3 (4 bits)
0010 to 1111
(14 combinations)
0001
(1 combination)
0000 to 1111
(16 combinations)
0001 to 1111
(15 combinations)
0000 to 1111
(16 combinations)
0000 to 1111
(16 combinations)
Total number of possible opcodes is therefore (14 x 16 x 16) + (1 x 15 x 16) = 3824 opcodes.
Part c
To answer this question, we have to understand 2 critical terms: i) Encoding Space fully Maximized
In part a), we maximized the encodings for class J and minimized for class
I and class K. In part b), we maximized the encodings for class K and minimized classes I and J. To fully maximize the encoding space of an instruction word, this means that we want to maximize ALL the classes. ii) Minimum/Maximum total number of instructions
Each class of instructions has a different number of opcodes. Class I has the fewest number of opcodes, while class K has the most, with class J in the middle.
If we maximized class I first, then class J, and finally class K, this will give us the minimum total number of instructions . This is because maximizing class I will give us very few instructions, and will take away possible instruction encodings from classes J and K. So at the end we end up with very few instructions.
If we maximized class K first, then class J and finally class I, we will get the maximum total number of instructions .
For this question, we wish to find the minimum total number of instructions, so we maximize class I first. Opcode1 can take any value between 0000 and 1111, but we must set aside 1 bit-value to identify instructions that are not in class I. We will set aside 0000 for this purpose. Class I instructions will therefore look like this:
Class I
Opcode1 (4 bits) Address1 (4 bits) Address2 (4 bits)
0001 to 1111
(15 opcodes)
Anything Anything
So we have 15 opcodes in class I. For class J, Opcode1 must be 0000, while Opcode2 can take any value between 0000 and 1111. However we must set aside one value to differentiate class K from class J. We will use the value 0000. So Opcode2 can take the values between 0001 and 1111.
Class J
Opcode1 (4 bits) Opcode2 (4 bits) Address1 (4 bits)
0000 0001 to 1111
(15 opcodes)
Anything
Hence we have 15 opcodes for class J.
For class K, Opcode1 and Opcode2 can only take the value 0000, while Opcode3 can take any value between 0000 and 1111. Class K instructions can make full use of this range, as no further differentiation is required:
Class K
Opcode1 (4 bits)
0000
Opcode2 (4 bits)
0000
Opcode3 (4 bits)
0000 to 1111
(16 opcodes)
There are therefore 16 opcodes in class K.
The total number of instructions is now 15 + 15 + 16 = 46 instructions.
Part d
To find the maximum total number of instructions, we must maximize class K, then class J and finally class I. We had maximized class K in part b, and found that there are 3824 class K instructions. To maximize class K, class I and class J were set to have only 1 instruction each. Hence the total number of instruction for is:
1 + 1 + 3824 = 3826 instructions.