9
\$\begingroup\$

I racked my brain through my comp-arch class and reread wiki’s article on hardware registers (they’re flip-flops, I get that), but one year later and I still don’t understand what a register physically is, other than that detail. Where on a processor is it? What do they look like? How big are they?

Tentatively (assuming this isn’t worthy of a second question), I also ask: how does a datum from the rest of the system make its way to the register?

\$\endgroup\$
  • 6
    \$\begingroup\$ If you know what a flip flop is then you are 99% of the way there. Make a latch out of it so you can choose when to change the state of the flip flop and you are all the way there. put 8 or 16 or 32 of them together on a bus, use the same control signal and clock, done, you have a register. \$\endgroup\$ – old_timer Jan 15 at 23:22
  • \$\begingroup\$ There are countless simplified examples that can be found in minutes not years. simple addition operation, use control signals to enable the value of two registers into two inputs of an alu. think of each input to the alu being wired to all of the registers, on a common bus, but only one is enabled to drive the bus at a time. control signals into the alu set the operation to add, one or more clocks later, the output is wired to all of the register inputs but only one is latched. r0 = r1 + r2. for example. all of this is built from elementary gates or can be. \$\endgroup\$ – old_timer Jan 15 at 23:26
  • \$\begingroup\$ can build the whole thing out of a big box of nand gates. \$\endgroup\$ – old_timer Jan 15 at 23:26
  • \$\begingroup\$ how does your car make its way to work/school? there are paved roads, with barriers usually that prevent or discourage offroading. there are gates (lights) that control who can move through an intersection, when and how, what lanes you have to be in to properly work through those gates and so on, plus directions that indicate each of the decisions that have to be made at each of the decision points. a computer is no different other than it is very very dumb, extremely simple. zero, one, and, or, not is all you have to know. \$\endgroup\$ – old_timer Jan 15 at 23:29
  • 2
    \$\begingroup\$ Have you seen en.wikipedia.org/wiki/Register_file ? The implementation on modern superscalar processors is extraordinarily complex (and will be quite different than the simplified flip-flop model). But at a high level, they are just memory cells connected to (very complex) buses that move data to/from functional units. \$\endgroup\$ – user1850479 Jan 16 at 2:01
38
\$\begingroup\$

I still don’t understand what a register physically is... Where on a processor is it? What do they look like? How big are they?

Physically it is made from the same structures that make up all the other logic in the processor. Depending on the implementation that could be transistors created on a silicon wafer, or discrete transistors, or vacuum tubes, neon lamps, electromechanical relays etc..

A modern CPU may have billions of tiny transistors and multiple cores which make it tricky to spot individual registers and their relationship to other parts. However the same principles apply to simpler CPUs such as the Intel 8080A, shown below.

enter image description here

The area marked '16 bit register array' contains the flip flops that make up the BC, DE, HL, SP and PC registers. They are located close to the ALU and Address buffer for fast communication with these subsections. A register can be connected to the internal 8 bit bus via tri-state buffers for access to the accumulator, ALU and external data bus, or to the address buffer for addressing external memory.

The chip dimensions are 4.28 mm x 4.18 mm, so the entire register array takes up an area of ~1.2 mm2.

After removing the metallization layer and zooming in we see the fine structure of the registers. From this it should be possible to identify individual transistors and derive the equivalent electronic circuit of each register.

enter image description here

Of course this pattern is specific to the structure and layout of this particular chip - another CPU could look quite different. But what doesn't change is the functionality. No matter how it is implemented physically, a register still does the same job logically.

\$\endgroup\$
  • 4
    \$\begingroup\$ "left as an exercise for the reader" \$\endgroup\$ – OrangeDog Jan 16 at 11:11
  • \$\begingroup\$ The register file is normally an array of SRAM that also includes addressing logic, so the CPU's instruction-decode logic (or microcode on early CPUs) can fetch the right register based on the encoding of the instruction. But yes the data is just flip flops. en.wikipedia.org/wiki/Register_file \$\endgroup\$ – Peter Cordes Jan 16 at 21:11
30
\$\begingroup\$

You've got most of it down. Let's start here: there are billions of transistors inside a computer's processor. Many of those transistors are used to create registers. Here's a basic description of the building-blocks of a register, from smallest to largest:

Transistor:

There are many different types of transistors. For the sake of simplicity, the following descriptions will simply use MOSFETs. A MOSFET is a voltage-controlled switch - you probably have a basic idea of what they are already.

enter image description here

NAND Gate:

A NAND gate is one type of "universal" logic gate. By "universal" I mean that you can use them to build any other type of logic gate. A NAND gate is made up of MOSFETs as shown below:

enter image description here enter image description here

Flip-Flop:

A flip-flop is a type of device which, in its simplest form, is made up of two NAND gates:

enter image description here

Adding another NAND gate connected to behave as an inverter as well as two more NAND gates to allow an enable signal turns the above "Set-Reset" flip-flop into a "D-type" flip-flop:

enter image description here enter image description here

This is a basic latch which latches the current state of input "D" at the output "Q" whenever the "clock" (or "enable") pin is switched. This D-type flip-flop is a 1-bit register, meaning it can store one bit of data on its output.

Register:

A register is simply a collection of these flip-flops, as shown below:

enter image description here

The above image shows 4 flip-flops, which means 4-bits of data can be stored. This is a 4-bit register. The data bus consists of the four inputs, D0 through D3. When the signals D0 through D3 are applied to the inputs and the "CP" (clock pulse) input is switched, the output of the flip-flops (the register) remain(s) in the same state as D0 through D3 were when the clock pulse was applied, even after the inputs are changed. They will stay in the latched state until the "CP" is switched again with new values at the D0 through D3 inputs.

You can put as many of these flip-flops together as you like to create different sizes of registers. Two common sizes for computers nowadays are 32-bit (meaning there are 32 flip-flops in each register within the processor) and 64-bit (64 flip-flops per register).

There is quite a bit more involved but hopefully this gives you a basic understanding of what a register is in the physical world. If you are interested in delving deeper and investing some real time in learning, I very strongly recommend Ben Eater's "Building an 8-bit Breadboard Computer" series on YouTube.

\$\endgroup\$
4
\$\begingroup\$

Others have already done what strikes me as a reasonable job of answering your first question, so I'm going to concentrate on your second question. Here's a rough idea of one way to structure a CPU.

enter image description here

This is assuming a CPU on the general order of an x86, where many operations specify a source and a destination register, where the source field really specifies both a source and a destination. That is, you take the specified source and destination registers as inputs, modify them as specified in the instruction, and deposit the result in the specified destination.

So in this picture, I haven't tried to show the instruction decoder, just the three primary fields: the source, destination, and op-code fields. The source and destination fields each choose a register to read from, and feed into all the functional units. The op-code field then chooses which of those results to keep. The destination field is also fed to a demultiplexer to choose which register to write the result to.

For a CPU that has separate fields for source 1, source 2, and destination, the destination field would connect to the demultiplexer, and the source 1 and source 2 fields would connect to the first two multiplexers.

Side note: the technique of feeding the operands to all the execution units and using a multiplexer to choose which of those to keep is used primarily in relatively small CPUs, at least in my experience. For a couple of examples, this is used in both the 6502 and (at least some versions of) the Xilinx Picoblaze.

For "larger" CPUs, you could use a demux connected to the op-code field, feeding an enable line for each execution unit. In this case, you could use pull-downs on the outputs, and wire-or the results.

Of course, a modern high-end CPU has a considerably more complex structure. In particular, with multiple instructions executing concurrently, your results will normally be written to a large bank of rename registers, with a separate demux for each execution unit1, so in one cycle you might do an addition that deposits its result in one register and also a multiplication that deposits its result in a different register.

Oh, and of course, this is only showing a subset of the real instructions. In a real CPU, you'd typically have a fair number more. Likewise you might easily have more than 8 registers. This doesn't really affect the structure though, just the widths of the mux/demuxers.


1. Well, since those wide muxes and demuxes can be fairly expensive, you typically don't actually have a separate demux for each execution unit. Rather, you might have, say, half a dozen or so groups of execution units, each with a demux to choose its destination, allowing up to six instructions to execute in parallel.

\$\endgroup\$
  • \$\begingroup\$ And some registers will be extended to handle the double word that is the product of two single words. \$\endgroup\$ – richard1941 Jan 17 at 4:31
  • \$\begingroup\$ @richard1941: there are a number of choices there. Some extend a register, others produce output in two registers, still others have a register dedicated to the high word of a multiplication result. \$\endgroup\$ – Jerry Coffin Jan 17 at 5:53
1
\$\begingroup\$

Have a look at Ben Eater's YouTube series on building an 8-bit computer from logic gates. I found it very interesting and I think you might too.

https://www.youtube.com/playlist?list=PLowKtXNTBypGqImE405J2565dvjafglHU

The computer he builds contains two registers and he explains how it all works starting from logic gates. There's another video on his channel that takes it a step further: how to build logic gates from transistors (going by the title; I haven't watched it yet):

https://www.youtube.com/watch?v=sTu3LwpF6XI

The computer build series stands dipping in and out just watching the bits you're interested in; that's how I watched it, although in the end I'd seen all of it. You don't have to watch it end to end if you don't want.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.