English / 日本語
← Back to the Fundamentals home Chapter 1: Part 1 · Taking the machine apart

Chapter 1 What a register is — the CPU’s workbench close at hand

The aim of this chapter. For a CPU to compute, it needs a place to set intermediate answers. That is the register — in kitchen terms, a “cell on the workbench.” In this chapter we clearly separate three easily-confused numbers — one workbench, 32 cells, and 32 squares inside one cell — and understand them. Along the way we also look at the cells’ names (addresses), why x0 is always 0, and the difference from the warehouse (memory). This becomes the groundwork, so that when we assemble blocks in Chapter 2 and when instructions flow in Chapter 3, you can picture what is happening.

1.1 Why a “place for intermediate values” is needed at all

As we saw in the reader, a CPU was “a part that computes.” For example, “add 3 and 5, then multiply that answer by 2.” By hand, you first get 3+5 = 8, then keep that 8 in mind for a moment, then compute 8×2 to get 16. Without a place to “keep it in mind for a moment,” you can’t pass the addition’s answer to the multiplication, and the computation can’t advance a single step.

A CPU is exactly the same. It needs a place to set intermediate values, for just an instant, right within reach. That holding place is the register.

1.2 The register as a holding place — the kitchen’s “workbench cell”

If we liken a register to a kitchen, it’s the cell on the workbench at the cook’s hand. A value being computed is set down for a moment on a cell right at hand, without going all the way to a distant warehouse. Take it out at once, rewrite it at once — that is a register’s role. This chapter takes that workbench apart, carefully.

1.3 [Core] Separate the three easily-confused numbers and understand them

This is the most important, and most easily confused, point. In talking about registers, “32” comes up twice, and they are different things. Don’t rush; split it into three layers.

32 cells lined up on the workbench The workbench is one. On it, 32 cells line up from x0 to x31. x0 is fixed at 0. 31 are freely usable. One workbench. On it, 32 cells line up. x0 fixed 0 x1 value x2 value x3 value x31 value Cell names = x0–x31 (32). Since x0 is always 0, 31 are freely usable.
One workbench. On it, 32 cells (x0x31). One cell is a register, and its name points to “which cell.” Only x0’s content is always 0.
Inside one cell: 32 squares Open one cell and 32 squares line up. One square is 0 or 1, binary. The row of 32 represents a single number. This is 32 bits. Open one cell — 32 squares (= 32 bits) 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 One square is 0 or 1 = binary. The row of 32 represents one number (~4.3 billion possibilities).
This is inside one cell (say x1). The name (x1), the content (32 of 0/1), and the base (binary) are each separate matters.

To sum up — one workbench, 32 cells, 32 squares. “1 · 32 · 32” are numbers at different levels. x1 is a name, the content is 32 of 0/1, the base is binary. They mix up easily, so keep these three apart.

1.4 A cell’s name is an “address” — a number pointing to which cell

The cell names x0x31 are actually addresses. When an instruction says “add x1 and x2 into x3,” x1, x2, x3 are numbers pointing to “which cell.” Since there are only 32 cells, the numbers 0–31 suffice (a very small number). So an instruction can name “which cell” in just a few digits. Compared later with the warehouse (memory) addresses, you’ll see this “smallness” ties into a register’s speed.

Now let’s look with a designer’s eye. Why 32 cells? It’s the result of a tug-of-war. Too few, and there aren’t enough places for values, so round trips to the warehouse (memory) increase and it slows down. Too many, and the digits to express a cell’s name (number) increase, so instructions fatten and the circuit grows. With 32, a number can be named in exactly 5 digits (5 bits) and it’s enough as a holding place — around this “just right” spot, RISC-V settles on 32. Design is choosing the balance in such a tug-of-war.

1.5 x0 is always zero — why a fixed 0 pays off

Of the 32 cells, only x0 is special. Its content is fixed at 0 always; whatever you try to write, it doesn’t change, and reading it always gives 0. It looks wasteful at a glance, but having it makes instructions tidy. For example —

Just having one zero-only cell pays off this much. In return, the freely usable ones are 31 of 32. The squares side (a cell’s capacity = 32 bits) can be used in full. “The number of cells is 32, but usable is 31” and “the squares (bit width) are the full 32” — the trick is not to mix these two.

1.6 The difference from the warehouse (memory) — so an instruction becomes “load, compute, store”

“If it’s just placing values, there’s memory (RAM) too — why do we need cells separately?” Because speed and nearness are completely different. The workbench cell is at hand and can be taken in an instant — but there are only 32. The warehouse (memory) can hold any number, but is far, and fetching keeps you waiting several beats. It’s the same for addresses: with 32 cells the number is short and can be named at once; the warehouse has vast shelves, so addresses are long, and fetching is far.

Terms sorted.
· Register = a workbench cell. A very small, very fast holding place right inside the CPU. Just 32 of them.
· Memory (RAM) = the warehouse. A large but “far” holding place outside the CPU. You can put any amount, but fetching is slow.

A CPU’s computation is furiously fast, so if it made a round trip to the warehouse each time, the very hand that computes (the ALU) would end up idle, waiting. So just the few values in use now are kept on the cells at hand. From here, computation naturally takes the following three-beat rhythm.

In the kitchen, it goes like this. Take the instruction “combine x5 and x6, and place it in x7,” and liken it to making stew. Cell x5 already holds prepped onions, cell x6 holds carrots (the 0/1 of the squares note down “which ingredient, and how much”). As the instruction directs, the stove (ALU) reads and combines the contents of x5 and x6, gives it one simmer, and serves the result into the destination cell x7. At this point —

That RISC (and RISC-V) instructions divide roles crisply into this “load / compute / store” is no accident. The physical circumstance that the workbench is small determines the very shape of the instructions. This rhythm shows itself clearly once more in Chapter 3’s “five steps.”

Which decision is this knowledge for. What the designer decides here is mainly the cell width. What — 32-bit (RV32) or 64-bit (RV64). How to decide — from the size of the numbers you handle and the breadth of memory you need. Why — the wider it is, the larger the values it can handle at once and the broader the memory it can point to, but the circuit and the power draw grow accordingly. For small embedded uses, 32 is enough; for large data or broad memory, 64. Together, the premise that “the workbench is small (32 cells)” connects to the next decision, memory layout (how much warehouse to hold, and how to move things in and out). This is the groundwork for “Brain” and “Memory” on the preface’s “decisions map.”