= Solution
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:
$$
\boxed{\mathrm{extended}_{15:0}=n,\qquad \mathrm{extended}_{31:16}=\begin{cases}n_{15}\cdots n_{15},&\mathrm{ExtSign}=1,\\0\cdots0,&\mathrm{ExtSign}=0.\end{cases}}
$$
Decode `ori` to `ExtSign=0`, `RegDst=0`, `ALUSrc=1`, `RegWrite=1` and `ALUFunc=OR`. The <arithmetic logic unit> then performs <bitwise OR> between $y$ and the zero-extended <immediate operand> and writes the result to $x$. 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.<MIPS32 Architecture For Programmers Volume II by MIPS Technologies>[ORI instruction entry: the 16-bit immediate is zero-extended before the logical operation]{ref}
Back to article page