Comparison Between Memory and Registers

Learn about the structure of memory and registers in a computer.

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, there are registers to 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.

Inside an Intel 64-bit PC

In an Intel 64-bit PC, addresses for memory locations containing integer values usually differ by 44 or 88 bytes depending on the PC’s architecture. This system also has two registers called %RAX and %RDX. The first halves of these registers are called %EAX and %EDX.

Because memory cells contain numbers, we’ll start with a simple arithmetic operation. For example, we may ask a PC to compute the sum of two numbers to see how memory and registers change their values.

In the image above, we use decimal addresses to demonstrate the difference between an idealized PC and a 64-bit Intel PC. Generally, we use hexadecimal addresses to represent memory addresses.

Memory layout and registers

Our project has two memory addresses (locations) called a and b. We can think about a and b as the names of their respective addresses. Now, we introduce a special notation that (a) means “contents at the memory address a.” If we use C or C++ to write our project, we declare and define memory locations a and b as:

static int a, b;

By default, when we load a program, static memory locations are filled with zeroes. The figure below depicts our initial memory layout after loading the program:

A computer program

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

(14) + (12) -> (14)

Our first pseudocode program is shown on the left side of the table below. It describes the assignment, addition, increment, and multiplication of cells 1212 and 1414.

In the pseudocode, we use the following conventional symbols:

  • -> moves (or assigns) the new value to the contents of a memory location (address).

  • ; the comment sign, makes the rest of the line a comment.

  • = shows the current value at a memory location (address).

Remember that code written in a high-level programming language is translated into a machine language by a compiler. However, the machine language can be readable if its digital codes are represented in a mnemonic system called an assembly language. For example, INC a is increment by one of what is stored at a memory location a