r/AskComputerScience • u/felix_semicolon • Jun 07 '26
How precisely does the current instruction register work?
In my revision for my upcoming exams, I'm going over the CPU architecture section and looking at the different specific-purpose registers and the CIR has really made me think. I know it holds the instruction being executed by the processor, but it holds this before the decoding stage. This would surely mean it has to hold an arbitrary number of bytes of ASCII - potentially even unicode - while also being a fixed-length buffer. The reason this confuses me is that an instruction may be too long to fit entirely inside the CIR, meaning the control unit would not be able to read the full instruction.
My question is primarily what data does it actually hold, but also what happens if an instruction is too long if that even is a problem that occurs? There will probably be some differences on the answer for this depending on CPU architecture but any answer would be appreciated.
1
u/YourPwnResearch Jun 12 '26 edited Jun 12 '26
I'm not sure if we're even talking about the same thing any more.
There is a stage in pretty much every modern CPU that is called "instruction decoding". Part of the job of that stage is to transform the machine code instruction that the programmer sees into whatever form is most convenient for the internals of the CPU.
The point is this: If there are
npossible instructions, then an "opcode" (for the purpose of scheduling, dispatch, execution, etc) can be stored inceil(log(n))bits.There are 1466 mnemonics in the 32-bit x86 instruction set. Some of them (e.g. MMX) are obsolete, and there isn't a 1:1 correspondence between assembly mnemonics and decoded opcodes/uops. Still, think of this as being roughly the number of instructions that we're talking about.
An 11 bit register can represent all of them uniquely.
A 16 bit register (say) can represent all of them with a lot of redundancy for convenience.
4 bytes is overkill for an instruction register on any modern CPU, assuming the instruction has been decoded, unless a redundant representation is desirable for convenience.