Comparison Between Memory and Registers

Memory and registers inside an idealized computer

Computer memory consists of a sequence of memory cells, where each cell has a unique address (location). Every cell contains a number. We refer to the contents of a cell as a number, though the contents may not be an actual number but rather a program’s instructions or data.

Since memory accesses are slower than arithmetic instructions, registers are part of the CPU and they speed up complex operations that require memory to store temporary results. We can also think about them as standalone memory cells. The name of a register is its address.

Memory and registers inside the ARM64-bit computer

The addresses for memory locations in the illustration below contain integer values, usually differing by 4 or 8, and we also show two registers called x0 and x1. The first halves of these registers are called w0 and w1.

Since memory cells contain numbers, we start with simple arithmetic and ask a processor to compute the sum of two numbers to see how memory and registers change their values.

In the illustrations above, we use decimal addresses to demonstrate the difference between an idealized computer and an ARM64-bit computer. Generally, we use hexadecimal addresses to represent memory addresses.

Arithmetic example: Memory layout and registers

For our example, we have two memory addresses (locations) that we call a and b. We can think about a and b as names of their respective addresses (locations). Now, we introduce a special notation, where (a) means “contents at the memory address (location) a.” If we use C / C++ language to write our example, we declare and define memory locations a and b as the following:

Press + to interact
static int a, b;

By default, when we load a program, static memory locations are filled with zeroes, and we can depict our initial memory layout after loading the program, as shown below:

Arithmetic example: A computer program

We can think of a computer program as a sequence of instructions for the manipulation of contents of memory cells and registers. For example, in the addition operation, we add the contents of the memory cell No12N^{\underline{o}}12 to the contents of the memory cell No14.N^{\underline{o}}14. In our pseudocode, we can write:

Press + to interact
[14] <- [14] + [12]

Our first program in pseudocode is shown on the left of the table:

In the pseudocodes, we use the following conventional symbols:

  • <— means moving (assigning) the new value to the contents of a memory location (address).
  • // is a comment sign and the rest of line is a comment.
  • = shows the current value at a memory location (address).

A code written in a high-level programming language is translated to a machine language using a compiler. However, the machine language can be readable if its digital codes are represented in some mnemonic system called assembly language:

ADD x1, x1, #1
Increment by 1 in ARM64

The above syntax increments what is stored in the register memory cell, x1, by one.