Simple ALU (Part 2: Instruction Set Implementation)

Description of the Instruction Set

All instructions are 16-bit patterns and have a simple format. The format can be described by grouping the bits by four and denoting them, from left to right, as Op, X, Y and Z. For example

\[\text{0001001000110100} \leadsto \text{0001 0010 0011 0100} \leadsto\text{Op} = \text{0001}, \text{X} = \text{0010}, \text{Y} = \text{0011},\text{Z} = \text{0100}.\]

The bit pattern Op is the opcode of the instruction. It specifies the type of instruction. Because the opcode is a 4-bit pattern we have (only) 16 types of instructions, and the remaining bits are used as operands. The instruction set of the ALU can be described as follows:

\[\begin{array}{ll}\text{Op} & \text{Effect} \\0x0 & u(\text{XY}) \to u(\text{%}Z) \\0x1 & \bigl(u(\text{%}Z)\cdot 2^8 + u(\text{XY})\bigr) \bmod 2^{16} \to u(\text{%}Z) \\0x2 & \bigl( u(\text{%}X) + u(\text{%}Y)\bigr) \bmod 2^{16} \to u(\text{%}Z) \\0x3 & \bigl(-u(\text{%}X) + u(\text{%}Y)\bigr) \bmod 2^{16} \to u(\text{%}Z) \\\end{array}\]

Assignment

Add the following instructions to the ALU:

\[\begin{array}{ll}\text{Op} & \text{Effect} \\0x4 & s(\text{XY}) \to s(\text{%}Z) \\0x5 & \bigl( u(X) + u(\text{%}Y)\bigr) \bmod 2^{16} \to u(\text{%}Z) \\\end{array}\]