Fundamentals 9 min read

How Memory, Variables, and Pointers Work from First Principles

This article explains how to read and write a tiny 8‑byte memory without any high‑level language or OS, introduces the concept of variables as named memory addresses, shows how pointers store addresses instead of copying data, and demonstrates indirect addressing and linked‑list structures.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How Memory, Variables, and Pointers Work from First Principles

Memory as Indexed Boxes

Imagine an 8‑byte memory where each byte is a small box numbered from 0 upward. Without a high‑level language or operating system, you must manipulate these boxes directly.

Storing Values and Addresses

To place the number 1 into box 6 you would use a store 1 6 instruction. The two numbers have different meanings: the first is the value, the second is the memory address.

Reading works similarly: load r1 6 loads the content of address 6 into register r1. The same numeric token can represent either a value or an address, which can cause ambiguity.

Disambiguating with Immediate Notation

Prefixing a value with $ marks it as an immediate value, while plain numbers are treated as addresses. For example:

store $1 6
load r1 6

Now the instruction meanings are clear.

Introducing Variables

When address 6 holds the value 1, we can give that address a name, say a. The assignment a = 1 creates the variable a, which represents the address 6 that stores the value 1.

Thus a variable carries two pieces of information:

It represents the numeric value 1.

That value is stored at memory address 6.

Copying vs. Referencing

Creating another variable b and assigning b = a could be done by copying the data, which would require another 5‑byte block if a occupied 5 bytes. Since the total memory is only 8 bytes, copying would overflow.

Instead, store the address of a in b. If a resides at address 3, then b simply holds the number 3. This is the essence of a pointer.

Pointers as Higher‑Level Abstractions

A pointer is a variable whose value is a memory address. It abstracts away the indirect addressing required in assembly. In assembly you would need two steps:

load r1 1        # load value at address 1 (which is 3)
load r1 @1       # treat the loaded value as an address and load again

In a high‑level language you can write b -> data a directly, letting the compiler handle the indirection.

Building Data Structures

Because pointers can reference other memory locations, they enable the construction of linked structures such as linked lists. The diagram below illustrates a simple singly‑linked list built from nodes that contain a data field and a pointer to the next node.

linked list diagram
linked list diagram

Historical Note

The pointer concept first appeared in the PL/I language to support linked‑list processing. Multics, the first OS written in a high‑level language, used PL/I and influenced the later development of Unix and the C language, which inherited pointers as a core feature.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Assemblylow‑level programmingMemoryfundamentalsVariables
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.