In this lesson, you will learn how the physical size of an instruction dictates the balance between simple hardware design and efficient memory usage.
Fixed-Length Instructions
In a fixed-length format, every instruction occupies the exact same number of bits (e.g., all instructions are 32 bits). This is the hallmark of RISC architectures.
Hardware Impact: Because the CPU always knows exactly where the next instruction begins, the decoding logic is incredibly fast and simple. There is no need to wait for the first part of an instruction to determine how long it is before fetching the next one. This simplicity makes it easier to implement high-performance features like deep pipelining and superscalar execution, which we’ve discussed previously.
Code Density Impact: The downside is "wasted" space. If you have a simple instruction that only needs 8 bits, but the format requires 32, you end up with 24 bits of padding. This leads to lower code density, meaning your program consumes more memory.
Variable-Length Instructions
In a variable-length format, common in CISC architectures, instructions can be as short as 1 byte or as long as 15 bytes.
Hardware Impact: Decoding becomes significantly more complex. The hardware cannot know where the next instruction starts until it fully decodes the current one. This creates a "bottleneck" at the very front of the pipeline, often requiring complex pre-decoding logic to identify instruction boundaries before they can even be dispatched to execution units.
Code Density Impact: This format is excellent for memory efficiency. If an operation is simple, it uses fewer bytes; if it is complex, it uses more.
Visual Comparison
Imagine we want to increment a register:
- Fixed (RISC):
000001 00010 00000 00000 00000 00000(Always 32 bits) - Variable (CISC):
01000000(Only 8 bits)
While the variable format saves 24 bits of memory, the fixed format allows the CPU to fetch and decode instructions with far less internal logic, facilitating higher clock speeds and more efficient parallel processing.
Key Takeaway: Fixed-length formats prioritize simple, high-speed hardware decoding, while variable-length formats prioritize high code density at the cost of complex instruction decoding logic.