18. MIPS Instruction Encoding, Format Symmetry, and Binary Compatibility

Instruction Set Architecture and MIPS Design Philosophy

  • Word Size and Architectural Evolution:

    • Modern computing architectures frequently utilize 64-bit64\text{-bit} organizations, as seen in modern Intel processors, contrasting with legacy 32-bit32\text{-bit} architectures.

    • In a 64-bit64\text{-bit} architecture, the standard machine word length is expanded to 8 bytes8\,\text{bytes} (64 bits64\,\text{bits}) compared to 4 bytes4\,\text{bytes} (32 bits32\,\text{bits}) in 32-bit32\text{-bit} systems.

    • This expansion alters the underlying bit representation and encoding requirements for instruction words.

  • MIPS Instruction Word Characteristics:

    • MIPS instructions maintain a uniform encoding size of 32 bits32\,\text{bits}, corresponding exactly to a 4 byte4\,\text{byte} instruction word.

    • A central design tenet of MIPS is restricting the instruction set to a very small number of distinct encoding formats.

  • Information Encoded within Instruction Words:

    • Opcode (Operational Code): Encapsulates the specific nature of the operation being executed, identifying commands such as addition, subtraction, or multiplication.

    • Register Addresses: Encodes the explicit hardware register locations accessed as source operands or target destinations.

    • A significant volume of control and address information must be compactly arranged within each 32-bit32\text{-bit} instruction boundary.

  • Impact of Format Simplicity on Hardware Decoding:

    • A direct relationship governs encoding and decoding: simpler instruction formats directly yield simpler decoding hardware.

    • Instruction decoding is the runtime processor phase where the CPU determines the operational type and fetches the requisite operands.

    • Complex or irregular instruction encodings require elevated hardware transistor counts and increased clock cycles for the CPU to decode.

    • Minimizing structural variability across formats allows the processor to reuse decoding logic across multiple instruction classes, eliminating redundant decoding circuits.

  • Component Sharing Analogy from Automotive Manufacturing:

    • In modern industrial manufacturing, automotive companies like Toyota produce distinct vehicle models (such as the Corolla, Camry, minivans, pickup trucks, and SUVs) that share core sub-assemblies.

    • Rather than engineering 1010 to 2020 distinct engines, manufacturers design 22 or 33 modular engine variants.

    • A single shared engine and transmission assembly is commonly deployed across a minivan, a pickup truck, and an SUV of equivalent scale.

    • Similarly, sedans across different model tiers share structural chassis and propulsion systems.

    • Standardizing parts achieves substantial cost efficiencies and simplifies assembly lines, providing the exact engineering rationale for sharing bit fields and decoding structures across instruction formats in CPU design.

MIPS Register Architecture and Conventions

  • Register Address Space:

    • The MIPS architecture incorporates 3232 general-purpose registers, referenced by numerical indices from 00 through 3131.

    • Addressing any single register uniquely within an instruction requires exactly 5 bits5\,\text{bits} (25=322^5 = 32).

  • Designated Register Allocations:

    • Temporary Registers t0t0 to t7t7: Map to physical register numbers 88 through 1515. These registers hold short-lived intermediate values generated during computation.

    • Saved Registers s0s0 to s7s7: Map to physical register numbers 1616 through 2323. These registers hold core operational variables and operands across procedure boundaries.

    • Special Temporary Registers t8t8 and t9t9: Map to physical register numbers 2424 and 2525, providing supplemental temporary storage.

R-Format (Register Format) Encoding

  • Functional Scope:

    • The R-format (register format) represents the most common instruction structure in MIPS.

    • Virtually all standard Arithmetic Logic Unit (ALU) instructions adhere strictly to the R-format layout.

  • Field Layout of the 32-bit32\text{-bit} Word:

    • opcode (6 bits6\,\text{bits}): Operational code designating the general instruction category.

    • rs (5 bits5\,\text{bits}): First source register operand specifying the primary input register.

    • rt (5 bits5\,\text{bits}): Second source register operand specifying the secondary input register.

    • rd (5 bits5\,\text{bits}): Destination register operand where the computed result is stored.

    • shamt (5 bits5\,\text{bits}): Shift amount field.

      • Specifies the number of bit positions to shift an operand (e.g., executing arithmetic multiplications by powers of two).

      • Encodes shift magnitudes from 00 to 3131.

      • A value of 00 represents zero shift displacement (the default state for basic ALU operations).

      • A shift magnitude of 3131 clears the entire 32-bit32\text{-bit} register content to the left or right.

    • funct (6 bits6\,\text{bits}): Function code field providing an extension to the opcode.

  • Opcode Expansion and Architectural Capacity:

    • The funct field differentiates specific functional variants of an overarching operation.

    • For addition, variations include standard signed integer addition, unsigned integer addition, single-precision floating-point addition, and double-precision floating-point addition.

    • The combination of a 6-bit6\text{-bit} opcode (26=642^6 = 64 base categories) and a 6-bit6\text{-bit} funct field (26=642^6 = 64 variations per category) enables 64×64=212=409664 \times 64 = 2^{12} = 4096 (≈4 K\approx 4\,\text{K}) distinct operational encodings.

    • Standard commercial microprocessors typically define between 100100 and several thousand instructions.

    • Advanced 64-bit64\text{-bit} processors often broaden instruction opcodes to 16 bits16\,\text{bits} or 24 bits24\,\text{bits} to accommodate modern workloads, including streaming media processing, image filtering, vector mathematics, and voice processing.

  • Concrete Machine Encoding Example (add $t0, $s1, $s2):

    • Instruction: add $t0, $s1, $s2 adds the contents of register s1s1 and s2s2, placing the result in t0t0.

    • Register Mapping:

      • Destination register rd=t0rd = t0: Register number 88 (01000201000_2).

      • First source register rs=s1rs = s1: Register number 1717 (10001210001_2).

      • Second source register rt=s2rt = s2: Register number 1818 (10010210010_2).

    • Control Field Mapping:

      • opcode: Special integer base value of 00 (0000002000000_2).

      • shamt: Shift amount of 00 (00000200000_2).

      • funct: Integer addition code of 3232 (1000002100000_2).

    • Assembled Binary Bit String:

      • [opcode: 000000] [rs: 10001] [rt: 10010] [rd: 01000] [shamt: 00000] [funct: 100000]

      • Full 32-bit32\text{-bit} concatenation: 00000010001100100100000000100000.

    • Decoding Execution: The CPU takes this 32-bit32\text{-bit} sequence at runtime, splits it according to the standardized 6-5-5-5-5-66\text{-}5\text{-}5\text{-}5\text{-}5\text{-}6 bit boundary grid, routes the register indices to the register file, and activates the ALU addition circuitry designated by function code 3232.

Hexadecimal Representation and Conversion

  • Structural Purpose:

    • Binary strings of 32 bits32\,\text{bits} or 64 bits64\,\text{bits} are verbose and error-prone to transcribe.

    • Hexadecimal notation (base-1616) provides a compressed, shorthand representation for binary strings.

    • Each hexadecimal digit directly maps to a distinct cluster of 4 bits4\,\text{bits}.

    • A 32-bit32\text{-bit} machine instruction condenses into exactly 88 hexadecimal digits; a 64-bit64\text{-bit} instruction condenses into 1616 hexadecimal digits.

  • Binary-to-Hexadecimal Equivalence:

    • 0000 = 0

    • 0001 = 1

    • 0010 = 2

    • 0011 = 3

    • 0100 = 4

    • 0101 = 5

    • 0110 = 6

    • 0111 = 7

    • 1000 = 8

    • 1001 = 9

    • 1010 = a (decimal 1010)

    • 1011 = b (decimal 1111)

    • 1100 = c (decimal 1212)

    • 1101 = d (decimal 1313)

    • 1110 = e (decimal 1414)

    • 1111 = f (decimal 1515)

  • Conversion Example:

    • Hexadecimal sequence: eca86420.

    • Converting via direct table lookup:

      • e = 1110

      • c = 1100

      • a = 1010

      • 8 = 1000

      • 6 = 0110

      • 4 = 0100

      • 2 = 0010

      • 0 = 0000

    • Concatenated 32-bit32\text{-bit} representation: 11101100101010000110010000100000.

    • Converting from binary back to hexadecimal involves partitioning the 32-bit32\text{-bit} string into 88 groups of 4 bits4\,\text{bits} from left to right and substituting the corresponding hexadecimal character.

I-Format (Immediate Format) and Field Sharing

  • Field Layout of the I-Format Word:

    • opcode (6 bits6\,\text{bits}): Specifies the instruction category.

    • rs (5 bits5\,\text{bits}): Base register or source register.

    • rt (5 bits5\,\text{bits}): Target register, serving as a destination register for immediate arithmetic/loads, or as a source register for memory stores.

    • immediate / address (16 bits16\,\text{bits}): Encodes either a numeric immediate constant or a memory displacement address offset.

  • Operational Roles:

    • Immediate Arithmetic Instructions: Operations such as addi (add immediate) place small signed constants directly inside the instruction word. The 16-bit16\text{-bit} field accommodates values in the range from −215-2^{15} to +215−1+2^{15} - 1.

    • Load and Store Instructions: Used for accessing memory. Register rs points to a base address, while the 16-bit16\text{-bit} field provides a signed byte offset added to that base address to construct the effective memory address.

  • Structural Alignment Between R-Format and I-Format:

    • The leading 16 bits16\,\text{bits} of both the R-format and I-format are identical: a 6-bit6\text{-bit} opcode, a 5-bit5\text{-bit} rs field, and a 5-bit5\text{-bit} rt field (6+5+5=16 bits6 + 5 + 5 = 16\,\text{bits}).

    • Maintaining identical positions for opcode, rs, and rt across formats permits the hardware designer to connect the register file read lines and initial instruction decoding stages to uniform physical bit lines.

    • Decoders do not need distinct circuitry to discover register inputs for R-type vs. I-type instructions, reducing hardware gate counts and avoiding decoding latency.

Stored-Program Concept and Memory Structure

  • Data and Instruction Homogeneity in Memory:

    • Memory hardware treats all stored information as unformatted sequences of binary digits (00s and 11s).

    • Physical memory cannot distinguish between machine instructions and application data; semantic meaning is imposed strictly by CPU execution context.

  • Memory Inhabitants:

    • Compiled System and User Binaries: Machine language executables for accounting software, text editors, C/C++ compilers (GCC, g++), and productivity suites (such as Microsoft Office).

    • Data Payloads: Structured alphanumeric records like payroll files containing character names, Social Security numbers, and numeric compensation fields.

    • Text and Source Files: C source programs and manuscript text represented as sequences of ASCII characters, where each character occupies an 8-bit8\text{-bit} binary byte.

  • Software Processing Hierarchy:

    • Compilers: Functional programs (e.g., GCC) that consume user source code written in high-level ASCII text and emit executable binary code.

    • Editors: Interactive utilities that read, modify, and store text files composed of ASCII bytes.

    • Linkers: Operating system utilities that aggregate independently compiled machine code files with shared precompiled library binaries (such as standard mathematical libraries containing optimized sine and cosine implementations included via math.h or <cmath>), generating a consolidated binary executable.

Binary Compatibility and Architecture Evolution

  • Principles of Binary Compatibility:

    • Binary compatibility denotes the capability of a compiled, immutable machine binary to execute without modification, recompilation, or translation across distinct microprocessors within the same architectural line.

    • Facilitated by standardizing the Instruction Set Architecture (ISA) across processor generations.

    • Demonstrated across Apple Silicon processors (M1, M2, M3, M4, M5), Intel processors (i7, i9, i12), and standardized lineages in ARM and MIPS.

  • ISA Superset Hierarchies:

    • Processor architectural roadmaps maintain compatibility by ensuring the instruction set of each successive generation constitutes a strict superset of preceding iterations:         ISAM2⊂ISAM3⊂ISAM4⊂ISAM5\text{ISA}_{M2} \subset \text{ISA}_{M3} \subset \text{ISA}_{M4} \subset \text{ISA}_{M5}

    • Every instruction defined within the Apple M2 specification remains supported in the M3, M4, and M5 processors.

  • Commercial and Operational Value:

    • Simplifies software distribution for vendors.

    • Preserves end-user investments: A user purchasing an application suite (e.g., Microsoft Office) compiled for an Apple M2 computer can upgrade hardware to an Apple M5 system years later and execute the original binary directly without repurchasing software licenses or paying for upgrade patches.

Questions & Discussion

  • Question / Prompt: Why is binary compatibility considered an advantageous design goal across a family of microprocessors?

    • Response: Distributing software programs becomes significantly more convenient. It allows a single precompiled binary to run across multiple hardware iterations, ensuring customers do not have to repurchase or update software when migrating between systems.

  • Question / Prompt: What must occur if two processor generations are not binary compatible?

    • Response: The software must be entirely recompiled from the original source code for the new architecture. When source code is unavailable (as with closed commercial binaries like Microsoft Office), the user must acquire or repurchase an updated binary explicitly built for the target processor.

  • Question / Prompt: What is the technical downside of running an older legacy binary on a modern processor architecture?

    • Response: Executing a legacy binary forfeits the use of newly introduced architectural features. While the legacy binary executes correctly, it cannot exploit the new vector engines, expanded multimedia operations, image processing accelerators, or specialized gaming instructions embedded in the newer processor. To achieve optimal performance, the software must be recompiled to target the newer instruction set.