================================================== Simple ALU (Part 1: Registers and Auxiliary Tools) [TOC] ================================================== 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. ---- VIDEO ------------------------------ https://www.youtube.com/embed/SmuM2tXyZZ4 ----------------------------------------- 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 ---- LATEX --------------------------------------------------------------------- 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 ---- LATEX --------------------------------------------------------------------- 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 ---- LATEX --------------------------------------------------------------------- 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 ---- LATEX --------------------------------------------------------------------- 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 ---- LATEX ---------------------- 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). :links: Donald Knuth -> https://en.wikipedia.org/wiki/Donald_Knuth The Art of Computer Programming -> https://en.wikipedia.org/wiki/The_Art_of_Computer_Programming TeX -> https://en.wikipedia.org/wiki/TeX