Byte-lane immediate 2026-10-31
An instruction encoding that stores an eight-bit byte and a two-bit byte-position selector, expanding them to a 32-bit machine word as for . Four such values can construct any 32-bit constant using bitwise OR or addition modulo .
Choose
ToAlu=0 for the input and ToAlu=1 for the expanded immediate operand. Choose ToReg=0 for the arithmetic logic unit result and ToReg=1 for memory read data. The diagram does not label the multiplexer polarities, so these are explicit conventions.Let and denote the six-bit arithmetic logic unit operation codes for addition and bitwise OR. Their numerical codes are not specified by the paper. The opcode needs to distinguish register, immediate, load and store modes;
add and or can share register mode, and addi and ori can share immediate mode, since selects the operation directly. For example, choose , , and . With denoting a field whose bits do not matter, the formats are:The required opcode control table is:
Here
MemRd is irrelevant whenever read data is unused, under the ordinary side-effect-free memory interpretation of the diagram. It is sensible to choose zero for those entries to save activity; memory-mapped devices with read side effects would require that choice. For store, ToReg is irrelevant because ; ToAlu is essential because its output supplies both the second arithmetic logic unit operand and memory write data. For load, the memory address is independently of ToAlu and of .Add zero extension alongside sign extension, and a multiplexer controlled by a new signal
ExtSign to select between them before the existing immediate-input connection. Equivalently, make the extender itself selectable:Decode ori to ExtSign=0, RegDst=0, ALUSrc=1, RegWrite=1 and ALUFunc=OR. The arithmetic logic unit then performs bitwise OR between and the zero-extended immediate operand and writes the result to . Extend the arithmetic logic unit's control decoding if OR was not already available. Decode addi to ExtSign=1; the new signal is irrelevant for MIPS R-type instructions because ALUSrc=0.Zero extension matters even when the most significant immediate bit is one:
ori with 0x8000 must only affect the low half of the destination, whereas sign extension would incorrectly force every high bit to one.[ref]MIPS32 Architecture For Programmers Volume II by MIPS Technologies. ORI instruction entry: the 16-bit immediate is zero-extended before the logical operation