Monday, March 24, 2025

Entry 9: Register part 1, binary and hex numbers

Now that the D flip-flop is understood (entry 8), it is time to move on to the register (see entry 1).

Register

Curated answer to "What is a register"

A register in the context of electronics and computing is a small, fast storage unit within a processor (like a CPU) that holds data temporarily during processing. Think of it as a scratchpad the CPU uses to store values it’s actively working with—numbers to add, memory addresses, or instructions being executed. Registers are built from flip-flops (like the D flip-flop we discussed), making them capable of storing bits stably and updating them on clock signals.

Here’s a breakdown:


Key Characteristics

  • Size: Typically matches the CPU’s word size—e.g., 4 bits, 8 bits (1 byte), 16 or 32 or 64 bits.
  • Speed: Registers are the fastest memory in a computer, located inside the CPU, so access is near-instant (no bus delays like RAM).
  • Purpose: Hold data, addresses, or control information during instruction execution.

How It’s Built

A register is essentially a group of flip-flops:

  • 1 bit = 1 flip-flop: A D flip-flop stores one bit, with its D input setting the value and Q output holding it.
  • Multi-bit register: Chain multiple flip-flops together, all clocked simultaneously. For a 4-bit register, you’d use 4 D flip-flops.
  • Clocked: The flip-flops update their stored values on a clock edge (e.g., rising edge), syncing with the CPU’s timing.

Example: 4-Bit Register

  • Structure: 4 D flip-flops, each with:
    • D input (data in).
    • CLK input (shared clock signal).
    • Q output (data out).

-end-

I decided to begin with a 4 bit register, just to make the wiring simpler. I will scale it up to 8 or more bits later.

There is an IC 74LS175/74HC175 with four positive-edge triggered D flip-flops:

It has a common Clock and a common Clear, but the Preset pin on the D flip-flops are unused. I will make Clear active high, so this is what I will build:

The D flip-flops are labeled 0, 1, 2, and 3. The D-input to D flip-flop 0 is denoted D0, Q0 is the output of D flip-flop 0, and so on. This is not quite a full four bit register. Rather, this is part 1 of such a register. I will call it QuadDFlipFlop.

Building the QuadDFlipFlop

Let's build the first version of a four bit register. Instead of using four buttons to control D0 to D3, I will use four DIP-switches. Also, instead of using four LED's to display Q0-Q3, I will use an LED bar. Note that the Clock is connected to all D flip-flops, so there is only one clock-button. I am not using the common clear, but you can add another button for Clear it you like.

Only the four rightmost DIP switches are used (5-8). I want to connect DIP 8 to D0, 7 to D1, 6 to D2 and 5 to D3 (the reason for the reversal of order will be explained later).

For the DIP switches, Up / ON means "1" to ACEL. Down /OFF is floating, which ACEL reads as 0.  In the picture, D3 = D2 = D1 = D0 = 1.

Only the four rightmost LED's are used. The rightmost LED is the output of D flip-flop 0 (Q0), and so on. (Below the LED bar is a 9 pin resistor array. This is necessary for limiting the current to the LED's).

Here are the components and connections:

  //Define chips
  auto* d0 = new DFlipFlop((char*)("D0"));
  auto* d1 = new DFlipFlop((char*)("D1"));
  auto* d2 = new DFlipFlop((char*)("D2"));
  auto* d3 = new DFlipFlop((char*)("D3"));

  //Add all chips to be emulated here
  Chip* chips[] = {
    d0,d1,d2,d3
  };

  //Add all connections here
  ConnectionBase* connections[] = {
    // D3-D0 are on pin 2-5, CLK on pin 6. Q3-Q0 are on pins 22-25
    new Connection(ard, 2, d3->D),
    new Connection(ard, 3, d2->D),
    new Connection(ard, 4, d1->D),
    new Connection(ard, 5, d0->D),
    new Connection(ard, 6, d0->Clock),
    new Connection(ard, 6, d1->Clock),
    new Connection(ard, 6, d2->Clock),
    new Connection(ard, 6, d3->Clock),
    new Connection(d3->Q, ard, 22),
    new Connection(d2->Q, ard, 23),
    new Connection(d1->Q, ard, 24),
    new Connection(d0->Q, ard, 25),
  };

We can set D3, D2, D1, and D0 to any combination (1,1,1,1 in picture). When the clock goes high, the D flip-flops in the register "saves" and "remembers" the combination. The combination stored in memory is displayed on the 4 LED's to the right.


You can try this put yourself on Wokwi. Name of the project is "Quad D flip-flops".

ACEL QuadDFlipFlop

The ACEL component QuadDFlipFlop has the following:
  • D-inputs: D[0], D[1], D[2], D[3]
  • Clock input: Clock
  • Clear input (note, active high): Clear
  • Q-outputs: Q[0], Q[1], Q[2], Q[3]

The QuadDFlipFlop does not have complemented Q-output. Here is the symbol for QuadDFlipFlop:

Now, the point is that the four binary bits can be viewed as a number between 0 and 15. For example, set the DIP's to 0101 (D3 = 0, D2 = 1, D1 = 0, D0 = 1) and latch with Clock. Now Q3 = 0, Q2 = 1, Q1 = 0 and Q0 = 1:

We can say that Q = 0101. This four bit binary number can be viewed as the decimal number 5. A "Print" makes this clear:

        (Quad D-flip flop) D: 0101 (5) Q: 0101 (5)

We are in effect storing the number "5" in the QuadDFlipFlop.

Binary and Hex numbers

4 binary bits can be converted to a number between 0 and 15. This is the curated answer from Grok:

A 4-bit binary number is a number represented using exactly 4 bits (binary digits), where each bit is either 0 or 1. In digital systems, like the 4-bit register we built, these numbers are the basic units of data storage and processing. Since there are 4 bits, a 4-bit binary number can represent 2^4 = 16 possible values, ranging from 0 to 15 in decimal. Let’s break it down clearly.


What Are Bits?

  • A bit is the smallest unit of digital information: 0 (off) or 1 (on).
  • In a 4-bit number, you have 4 positions, each representing a power of 2, read from right to left:
    • Bit 0 (rightmost): 2^0 = 1
    • Bit 1: 2^1 = 2
    • Bit 2: 2^2 = 4
    • Bit 3 (leftmost): 2^3 = 8

How It Works

Each bit contributes to the total value if it’s 1, based on its position. Add up the values of the 1s to get the decimal equivalent. Here’s the structure:

  • Format: Bit 3, Bit 2, Bit 1, Bit 0
  • Weights: 8, 4, 2, 1

Examples

  1. 0000:
    • 0×8 + 0×4 + 0×2 + 0×1 = 0 (decimal)
  2. 0001:
    • 0×8 + 0×4 + 0×2 + 1×1 = 1
  3. 0010:
    • 0×8 + 0×4 + 1×2 + 0×1 = 2
  4. 0101:
    • 0×8 + 1×4 + 0×2 + 1×1 = 4 + 1 = 5
  5. 1111:
    • 1×8 + 1×4 + 1×2 + 1×1 = 8 + 4 + 2 + 1 = 15

Full Range

Here’s every 4-bit binary number with its decimal and hexadecimal equivalent:

BinaryDecimalHex
000000
000111
001022
001133
010044
010155
011066
011177
100088
100199
101010A
101111B
110012C
110113D
111014E
111115F
  • Range: 0 to 15 (decimal), 0H to FH (hex).
  • Hexadecimal: Groups 4 bits into one digit (0–F), handy for compact notation.

Tie to the 4-Bit Register

In your breadboard register:

  • D0–D3 (inputs): Set the 4-bit binary number with buttons (e.g., D3 D2 D1 D0 = 1010).
  • Q0–Q3 (LEDs): Show the stored value (e.g., 1010 = 10 decimal, LEDs: on-off-on-off).
  • Pressing CLK latches the D inputs into Q outputs, storing the 4-bit number.

For example:

  • Buttons: D3 = 1, D2 = 0, D1 = 1, D0 = 0 (binary 1010).
  • Clock it: LEDs show Q3 = 1, Q2 = 0, Q1 = 1, Q0 = 0.
  • Value stored: 1×8 + 0×4 + 1×2 + 0×1 = 10.

Why 4 Bits?

  • It’s a nibble (half a byte), a practical size for small circuits.
  • Scales to 8 bits (like the 8085) or 32/64 bits in modern CPUs.
  • Matches your 4-flip-flop register perfectly!

-end-

Example: The register in this picture holds 0101, which is equivalent to decimal 5 and Hex 5.

No comments:

Post a Comment