Simple ALU (Part 1: Registers and Auxiliary Tools)

Description of the register bank:

  • It contains 16 registers and each of it can store 16 bits. Each registers has a 4-bit id (0x0, ..., 0xF) and we refer to its bit pattern with %0, ..., %F.

  • It supports read and write operations:

    • For Reading two 4-bit inputs src0 and src1 are provided. The content of the selected registers can be accessed with the 16-bit outputs %src0 and %src1 respectively.

    • (Writing) With the 4-bit input dest the destination register can be selected. With a clock signal the destination register gets overwritten with the 16-bit pattern of the input %dest.

  • Special register: Register reg0 is a zero register. It always contains a bit pattern with zeros only, i.e. writing to it simply gets ignored, reading from it gives always the zeros bit bit pattern.

Extending Bit Pattern

Sometimes we might need to extend a \(m\)-bit pattern \(X\) to an \(n\)-bit pattern \(Y\) with \(m < n\). As a constraint the value represented by the bit pattern \(X\) has to be preserved. Here we can distinguish two cases, preserving the unsigned or signed value.

Zero Extension for Preserving the Unsigned Value

The zero extension can be described bitwise for \(X = (x_{m-1},\dots,x_0)\) and \(Y = (y_{n-1}, \dots, y_0)\) through

\[y_j := \begin{cases} x_j, & 0 \leq j < m, \\ 0, & m \leq j < n. \\ \end{cases}\]

More elegant is to describe this extension simply with

\[u(X) \to u(Y)\]

which can be read as for a given bit pattern \(X\) overwrite bit pattern \(Y\) such that \(u(Y)\) equals \(u(X)\). This equivalent to the above definition. Because there is only one way to achieve this and that's described in the above definition for the zero extension.

Sign Extension for Preserving the Unsigned Value

The sign extension can be described bitwise for \(X = (x_{m-1},\dots,x_0)\) and \(Y = (y_{n-1}, \dots, y_0)\) through

\[y_j := \begin{cases} x_j, & 0 \leq j < m, \\ 0, & m \leq j < n \;\land\; x_{m-1} = 0, \\ 1, & m \leq j < n \;\land\; x_{m-1} = 1. \\ \end{cases}\]

This also can be uniquely be expressed with

\[s(X) \to s(Y)\]

Left Shift and Truncation

Let \(X\) and \(Y\) denote two bit patterns with \(n\) bits. Then for \(k\geq 0\) with

\[u(X) \cdot 2^k \bmod 2^n \to u(Y)\]

we can briefly describe that \(Y\) get overwritten with the left shifted bit pattern of \(X\) by \(k\) where the \(k\) new least significant bits are set to zero and the resulting bit pattern with \(n + k\) gets truncated to its \(n\) least significant bits.

What a relief to use a short notation without loosing the precise description. Credits for that go to Donald Knuth who used it in The Art of Computer Programming (and who also developed TeX for typesetting it).