Fundamentals of VHDL for Digital Design#

Estimated Reading Time: 30–45 minutes

Learning Objectives#

After completing this chapter, you will be able to:

  1. Explain the fundamental difference between sequential software programming languages (such as Python, C, Java, and Rust) and concurrent hardware description (VHDL).

  2. Define and relate the four core concepts of VHDL: Entity, Architecture, Component, and Named Instance.

  3. Write and interpret valid Entity declarations using IEEE 1164 data types (std_logic and std_logic_vector), port modes, legal identifiers, and ESEC naming conventions.

  4. Implement and interpret combinational circuits using all three VHDL architecture styles: Dataflow, Behavioral, and Structural (with explicit component declarations and named port mapping).

  5. Apply the principles of Abstraction and Hierarchy to explain how complex digital systems are constructed from basic logic gates.

Before You Begin#

In the last few lessons, you were introduced to the building blocks of digital systems: binary numbers, logic gates (e.g. AND, OR, XOR, XNOR, etc.), truth tables, and multi-bit buses. You also gained experience writing software programs in previous courses (e.g. CompSci 110). This chapter bridges those two worlds—showing you how to describe digital circuits using text, and helping you shift your mindset from software programmer to hardware designer.


1. Describing Hardware Instead of Writing Software#

In traditional software programming languages—such as Python, C, Java, or Rust—you solve problems by writing algorithms: step-by-step recipes that a processor (CPU) executes one line at a time. For example, in software you might write:

a = 1
b = a + 1

The CPU executes line 1, finishes it, and then executes line 2. This is called sequential execution, and it is how virtually all general-purpose software languages operate.

VHDL (which stands for VHSIC Hardware Description Language) looks a little like a software language on the screen, but it is not a programming language. You are not writing instructions for a CPU to execute. Instead, you are writing a blueprint of a physical electronic circuit.

In this course, specialized software will read your VHDL blueprint and configure an FPGA (Field-Programmable Gate Array)—a reconfigurable chip filled with programmable logic blocks and wires—so the chip physically becomes the circuit you described.

Concurrency: Everything Happens at Once#

Imagine wiring two separate light switches to two separate light bulbs on a circuit board. When you flip both switches, the bulbs do not wait in line for each other—electricity flows through both circuits simultaneously.

Digital hardware works the same way. In VHDL, statements outside of special blocks represent physical hardware circuits that all operate concurrently (at the exact same time). Changing the order of two concurrent statements in a VHDL file does not change the circuit at all—just like drawing Gate A on the top of a schematic and Gate B on the bottom produces the exact same circuit as drawing Gate B on top and Gate A on the bottom.

A Note on “Concurrency”: Software vs. Hardware If you have encountered the term concurrency in a software course, be careful—it means something different there. In software, concurrency typically refers to interleaving: a CPU rapidly switches back and forth between multiple tasks so they appear to run together, even though a single core still executes only one instruction at a time. In hardware, concurrency means true parallelism: every logic gate and wire you describe physically exists on the FPGA at the same time, so all parts of your circuit operate simultaneously.

Concept

Software Languages (e.g., Python, C, Java, Rust)

VHDL (Hardware Description)

Primary Goal

Tell a CPU what steps to run

Describe physical logic gates and wires

Execution Model

Sequential (one line after another)

Concurrent (all hardware runs simultaneously)

Meaning of a name

A variable stored in RAM

A physical wire (signal) carrying voltage (0 or 1)

Hardware Target

Runs on a general-purpose CPU

Synthesized into custom circuitry on an FPGA

Checkpoint 1#

(Check your work against the Checkpoint Answers at the end of the chapter.)

  1. Why is it inaccurate to say that an FPGA “runs VHDL code line by line” the way a computer runs a software program?

  2. If you swap the order of two independent Boolean equations in a VHDL dataflow design, does the resulting physical circuit change? Why or why not?


2. The Four Pillars of VHDL Design#

When electrical engineers build a circuit on a physical breadboard, they pick integrated circuit (IC) chips from a parts bin, place them on the board, and connect their metal pins with wires. VHDL uses the exact same mental model, organized around four core concepts:

  1. Entity: The external interface of a design—just like the physical pins sticking out of a black plastic IC chip. An entity tells the rest of the system what inputs go in and what outputs come out, without revealing what is inside.

  2. Architecture: The internal behavior or structure inside that black plastic IC chip (the entity)—describing what actually happens between the entity’s pins.

  3. Component: A reusable “chip” or “building block” that can be placed inside a larger system. Declaring a component in VHDL is like listing a chip in your parts inventory—you cannot place a chip onto your circuit board unless it is in your inventory!

  4. Named Instance: A specific, uniquely labeled copy of a component placed into your circuit. If you need four 2-input XNOR gates in a design, you declare the xnor2 component once in your inventory, and then create four named instances (e.g., u0, u1, u2, u3) in your circuit.

Every standalone VHDL module consists of an Entity/Architecture Pair. An architecture cannot exist on its own—it must always be paired with an entity.


3. The Entity Declaration: Designing the Chip’s Pins#

Standard Libraries and Signal Types (IEEE 1164)#

Out of the box, core VHDL does not include the standard electrical logic types used in modern digital design. To access them, we include two lines at the top of every VHDL file:

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

The std_logic_1164 package defines a 9-valued logic system (capable of representing '0', '1', and seven other hardware states such as uninitialized 'U', unknown 'X', or high-impedance 'Z'). As a beginner, you will work almost exclusively with '0' (logic low) and '1' (logic high), using two data types:

  • std_logic: Represents a single wire carrying 1 bit of information. Single-bit values are written in single quotes: '0' or '1'.

  • std_logic_vector: Represents a multi-bit bus—a group of parallel wires treated as a single bundle.

Digital Logic Refresher — Multi-Bit Buses (DOWNTO vs. TO) & Bit Indexing: Suppose you want to send an 8-bit binary number (like 10110010) into a circuit. Instead of creating eight separate ports named data0, data1, …, data7, digital designers bundle those 8 wires into a single bus, often drawn on schematic diagrams as data[7:0].

In VHDL, you declare this bus as std_logic_vector(7 DOWNTO 0). Why DOWNTO? Because in standard binary notation, the leftmost bit is the Most Significant Bit (MSB, worth \(2^7 = 128\)) and the rightmost bit is the Least Significant Bit (LSB, worth \(2^0 = 1\)). Using DOWNTO keeps each bit’s index aligned with its power of 2.

Note that VHDL also allows ascending ranges using TO, such as std_logic_vector(0 TO 3), where bit 0 is on the left. While we primarily use DOWNTO in this course, knowing that TO exists is helpful if you consult external textbooks or online VHDL references.

Quotes & Single-Wire Indexing: When assigning a value to an entire multi-bit bus, use double quotes, such as o_data_out <= "10110010";. However, you can still read or assign a value to a single wire inside a multi-bit bus using parentheses for indexing—for example, o_data_out(0) <= '1'; (the VHDL equivalent of data[0] on a schematic). Because o_data_out(0) refers to just one wire (std_logic), you must use single quotes ('0' or '1').

ESEC Naming Conventions#

To keep complex hardware designs readable and easy to debug, our department uses the ESEC Naming Conventions—short prefixes (and one suffix) attached to signal and port names to immediately reveal their role. You will see this reference block in the header comments of every starter .vhd file throughout this course.

Used Right Away (Combinational Circuits & Interfaces)#

Prefix / Suffix

Meaning

Example

i_

On-chip input port

i_clk, i_data_in

o_

On-chip output port

o_sum, o_equals

b_

On-chip bidirectional port

b_data_bus

c_

Internal combinational signal

c_bit_match

w_

Internal / top-level wiring signal (connecting components)

w_carry_1, w_bit_match

_n (suffix)

Active-low signal ('0' means active/on)

o_seg_n, w_7SD_EN_n

Preview: Used Later This Semester (Testbenches, Sequential Circuits & FSMs)#

As you progress through the semester’s in-class exercises and labs, starter code templates will introduce a few additional ESEC prefixes—keep this table handy as a reference:

Prefix

Meaning

Example (from later labs/ICEs)

f_

Synchronous / flip-flop signal (updates on a clock edge)

f_Q, f_Q_next, f_sel_n

k_

Constant (fixed value, such as clock period or bus width)

k_clk_period, k_DIV, k_width

sm_

State machine enumerated type definition

sm_floor

s_

State name inside a state machine

s_floor1, s_floor2

A Note on Industry Practice: The ESEC naming convention is a style guide used in our course and department—it is not a universal rule of the VHDL language. When you read external textbooks, datasheets, or industry codebases, you will frequently see VHDL code written without prefixes (e.g., clk, data_in, equals) or using a different company’s naming convention. In this course, however, we will use ESEC prefixes consistently in all examples and labs.

Port Modes#

Every port in an entity must declare a mode, which defines the direction data travels across the boundary of the entity:

  • IN: Data enters the entity only. Inside the architecture, you can read an IN port, but you can never assign a value to it.

  • OUT: Data leaves the entity only. Inside the architecture, you can assign a value to an OUT port, but you cannot read its value back internally.

  • INOUT: Data is bidirectional—it can flow both into and out of the entity (used for shared buses, such as memory data pins). Inside the architecture, you can both read from and assign a value to an INOUT port.

  • BUFFER: Data flows out of the entity and is fed back internally so the architecture can both assign a value to it and read its own output back internally.

Best Practice Note on BUFFER: Although VHDL includes the BUFFER mode, professional FPGA designers generally avoid using BUFFER ports. In hierarchical designs, connecting a BUFFER port to other components can cause strict type/mode mismatch errors. The recommended best practice whenever you need to both output a signal and read it internally is to declare an internal SIGNAL, read and drive that internal signal inside the architecture, and then assign it to a standard OUT port (e.g., o_flag <= c_flag;).

Anatomy of an Entity Declaration#

Here is the general syntax for an entity:

ENTITY entity_name IS
    PORT (
        name      : mode type;
        ...
        last_name : mode type
    );
END entity_name;

Let’s examine a concrete example: a module named black_box with single-bit inputs i_clk and i_reset, an 8-bit input bus i_data_in, an 8-bit output bus o_data_out, and a single-bit carry-out output o_carry_out.

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

ENTITY black_box IS
    PORT (
        i_clk, i_reset : IN  std_logic;
        i_data_in      : IN  std_logic_vector(7 DOWNTO 0);
        o_data_out     : OUT std_logic_vector(7 DOWNTO 0);
        o_carry_out    : OUT std_logic
    );
END black_box;

Watch out for these common beginner syntax pitfalls:

  1. Comma-separated lists: i_clk and i_reset share the exact same mode (IN) and type (std_logic), so they can be declared on the same line separated by a comma.

  2. The missing last semicolon: Notice that o_carry_out : OUT std_logic does not end with a semicolon! In VHDL, semicolons separate port declarations inside PORT (...), and the final semicolon goes outside the closing parenthesis: );. Putting a semicolon on the last port line is the #1 syntax error for new VHDL students.

  3. Matching names: The name after END (black_box) must match the name after ENTITY.

Worked Example 1: Interpreting an Entity Declaration#

Prompt: Examine the following VHDL entity declaration. How many total physical input wires and output wires does this chip have? Describe each port in plain English.

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

ENTITY mux2to1 IS
    PORT (
        i_data_0, i_data_1 : IN  std_logic_vector(3 DOWNTO 0);
        i_select           : IN  std_logic;
        o_mux_out          : OUT std_logic_vector(3 DOWNTO 0)
    );
END mux2to1;

Solution Walkthrough#

  1. Identify the entity name: mux2to1 (a 2-to-1 multiplexer).

  2. Analyze the IN ports:

    • i_data_0 is a 4-bit input bus (3 DOWNTO 0 = bits 3, 2, 1, 0 \(\rightarrow\) 4 wires).

    • i_data_1 is also a 4-bit input bus (4 wires).

    • i_select is a 1-bit input (std_logic \(\rightarrow\) 1 wire) that selects which input bus passes through to the output.

    • Total input wires: \(4 + 4 + 1 = 9\) input wires.

  3. Analyze the OUT ports:

    • o_mux_out is a 4-bit output bus (3 DOWNTO 0 \(\rightarrow\) 4 wires).

    • Total output wires: \(4\) output wires.

Worked Example 2: Writing an Entity Declaration from a Specification#

Prompt: Write a complete VHDL entity declaration for a Half Adder named half_adder. A Half Adder takes two 1-bit binary inputs (a and b) and produces two 1-bit outputs: the binary sum and the carry_out. Follow ESEC naming conventions.

Solution Walkthrough#

  1. Start with the IEEE library declarations so std_logic is available.

  2. Choose ESEC names: Conventional half-adder inputs a and b become i_a and i_b. Outputs become o_sum and o_carry_out.

  3. Assign modes and types: All four ports are single-bit wires (std_logic). i_a and i_b are IN; o_sum and o_carry_out are OUT.

  4. Check punctuation: No semicolon on the last port line inside PORT (...).

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

ENTITY half_adder IS
    PORT (
        i_a, i_b    : IN  std_logic;
        o_sum       : OUT std_logic;
        o_carry_out : OUT std_logic
    );
END half_adder;

Checkpoint 2#

(Check your work against the Checkpoint Answers at the end of the chapter.)

  1. Identify which of the following VHDL identifiers are illegal, and state the rule each one violates: i_reset_n, 4_bit_adder, o_sum_, w_bus__a, out

  2. Suppose o_leds is declared as OUT std_logic_vector(3 DOWNTO 0). Write a single VHDL statement that sets only bit 2 of o_leds to logic high (1). Should you use single quotes or double quotes?

  3. You are designing a circuit where an output port o_flag needs to be sent to an external LED and checked internally by another logic gate inside the same architecture. Which port mode technically allows this, and what is the recommended best practice alternative?

  4. Spot the two syntax errors in the following entity declaration:

    ENTITY my_gate IS
        PORT (
            i_in_a, i_in_b : IN  std_logic;
            o_result       : OUT std_logic;
        );
    END gate;
    

4. The Architecture Body: What Happens Inside the Black Box#

While the entity defines the pins on the outside of the IC chip, the architecture defines what happens inside it. Here is the general template:

ARCHITECTURE arch_name OF entity_name IS
    -- Declarative region: optional local signals and component declarations
BEGIN
    -- Architecture body: VHDL statements describing the circuit's function
END arch_name;

Notice the declarative region between IS and BEGIN. This is where you declare anything internal to the chip—such as local wires (SIGNAL) or sub-chips (COMPONENT)—that does not connect directly to the outside world.

Digital Logic Refresher: A 4-Bit Equality Comparator#

To see how the exact same hardware can be described in three different VHDL styles, let’s build a 4-bit equality comparator named compare. It has two 4-bit input buses (i_bus_a and i_bus_b) and a single-bit output (o_equals). It outputs '1' if i_bus_a and i_bus_b are identical, and '0' otherwise.

How do we build this out of basic logic gates?

  1. First, compare each pair of corresponding bits (i_bus_a(0) with i_bus_b(0), i_bus_a(1) with i_bus_b(1), etc.) using a 2-input XNOR gate. Remember the truth table for an XNOR gate—it outputs 1 whenever both inputs are equal:

i_in1

i_in2

i_in1 XNOR i_in2

0

0

1

0

1

0

1

0

0

1

1

1

  1. Next, feed all four XNOR outputs into a 4-input AND gate. An AND gate outputs 1 only when all of its inputs are 1. Therefore, o_equals will be 1 if and only if all four pairs of bits match!

Below is the schematic diagram of our compare entity and its internal gates. Notice how the dashed box represents the Entity boundary (its pins), while everything inside the box represents the Architecture:

ENTITY: compare i_bus_a(0) i_bus_b(0) u0 xnor2 i_bus_a(1) i_bus_b(1) u1 i_bus_a(2) i_bus_b(2) u2 i_bus_a(3) i_bus_b(3) u3 c_bit_match(0) c_bit_match(1) c_bit_match(2) c_bit_match(3) u4 and4 o_equals

All three architectures below share this exact same entity:

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

ENTITY compare IS
    PORT (
        i_bus_a, i_bus_b : IN  std_logic_vector(3 DOWNTO 0);
        o_equals         : OUT std_logic
    );
END compare;

Style 1: Dataflow Architecture#

Dataflow style describes a circuit directly using Boolean equations (with logic operators like AND, OR, NOT, XOR, and XNOR), showing how signals flow through combinational logic from inputs to outputs. (VHDL dataflow also supports conditional signal assignments such as WHEN ... ELSE, which you will encounter in upcoming labs, though Boolean equations give the clearest picture of how dataflow mirrors logic gates.)

Here is our 4-bit equality comparator written in Dataflow style using Boolean equations and an internal combinational signal c_bit_match:

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

ENTITY compare IS
    PORT (
        i_bus_a, i_bus_b : IN  std_logic_vector(3 DOWNTO 0);
        o_equals         : OUT std_logic
    );
END compare;

ARCHITECTURE dataflow OF compare IS
    SIGNAL c_bit_match : std_logic_vector(3 DOWNTO 0);
BEGIN
    -- Compare each pair of bits using XNOR
    c_bit_match(0) <= i_bus_a(0) XNOR i_bus_b(0);
    c_bit_match(1) <= i_bus_a(1) XNOR i_bus_b(1);
    c_bit_match(2) <= i_bus_a(2) XNOR i_bus_b(2);
    c_bit_match(3) <= i_bus_a(3) XNOR i_bus_b(3);

    -- Output '1' only if ALL four bit pairs match
    o_equals <= c_bit_match(0) AND c_bit_match(1) AND c_bit_match(2) AND c_bit_match(3);
END dataflow;

Key Concept — The Signal Assignment Operator (<=): In many software programming languages, = assigns a value to a variable and == tests for equality. In VHDL, = is only used for equality comparison. To drive a value onto a wire/signal, VHDL uses <=. Read c_bit_match(0) <= i_bus_a(0) XNOR i_bus_b(0); as: “Wire c_bit_match(0) to the XNOR of i_bus_a(0) and i_bus_b(0).” Because all five statements are concurrent, their order in the file does not matter.

Style 2: Behavioral Architecture#

Behavioral style describes what the circuit does at a higher, algorithmic level—without writing out individual gate equations. To use high-level constructs like IF ... THEN ... ELSE, we place them inside a PROCESS block.

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

ENTITY compare IS
    PORT (
        i_bus_a, i_bus_b : IN  std_logic_vector(3 DOWNTO 0);
        o_equals         : OUT std_logic
    );
END compare;

ARCHITECTURE behavior OF compare IS
BEGIN
    comp : PROCESS (i_bus_a, i_bus_b)
    BEGIN
        IF i_bus_a = i_bus_b THEN
            o_equals <= '1';
        ELSE
            o_equals <= '0';
        END IF;
    END PROCESS comp;
END behavior;

Understanding PROCESS and the Sensitivity List:

  • comp : is an optional label naming the process.

  • (i_bus_a, i_bus_b) is called the sensitivity list. It tells VHDL which input signals can trigger a change in this circuit. Whenever i_bus_a or i_bus_b changes, the logic inside the process re-evaluates.

  • Software vs. Hardware Caution: Inside a PROCESS, statements are evaluated in order from top to bottom (which looks very similar to traditional software code!). However, the PROCESS block as a whole still runs concurrently with everything else in the architecture, and when synthesized onto an FPGA, this IF/ELSE block becomes physical combinational logic gates—not software instructions executed by a CPU.

Style 3: Structural Architecture#

Structural style describes a circuit just like the schematic diagram shown above. Instead of writing equations or IF statements, you explicitly place pre-built components (chips) and wire them together.

Building a structural architecture always follows three steps:

  1. Declare Components (Stock Your Inventory): Between IS and BEGIN, list every building-block component you plan to use, copying its exact PORT list.

  2. Declare Internal Wiring Signals: Still between IS and BEGIN, declare any internal SIGNAL wires needed to connect the components to each other (using the w_ ESEC prefix).

  3. Instantiate Components (Place and Wire the Chips): After BEGIN, create uniquely named instances (u0, u1, etc.) and wire their pins using named port mapping (PORT MAP).

Notice below how each component has its own distinct port names (i_in1, i_in2, o_xnor_out on xnor2; i_in1–i_in4, o_and_out on and4), which makes it easy to distinguish the component’s pins from the compare entity’s signals (i_bus_a, i_bus_b, c_bit_match, o_equals):

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

ENTITY compare IS
    PORT (
        i_bus_a, i_bus_b : IN  std_logic_vector(3 DOWNTO 0);
        o_equals         : OUT std_logic
    );
END compare;

ARCHITECTURE structure OF compare IS

    -- Step 1: Declare components ("stocking the inventory")
    COMPONENT xnor2 IS
        PORT (
            i_in1      : IN  std_logic;
            i_in2      : IN  std_logic;
            o_xnor_out : OUT std_logic
        );
    END COMPONENT xnor2;

    COMPONENT and4 IS
        PORT (
            i_in1     : IN  std_logic;
            i_in2     : IN  std_logic;
            i_in3     : IN  std_logic;
            i_in4     : IN  std_logic;
            o_and_out : OUT std_logic
        );
    END COMPONENT and4;

    -- Step 2: Declare internal wiring signals
    SIGNAL w_bit_match : std_logic_vector(3 DOWNTO 0);

BEGIN

    -- Step 3: Instantiate components and wire them using named port mapping
    u0 : xnor2
        PORT MAP (
            i_in1      => i_bus_a(0),
            i_in2      => i_bus_b(0),
            o_xnor_out => w_bit_match(0)
        );

    u1 : xnor2
        PORT MAP (
            i_in1      => i_bus_a(1),
            i_in2      => i_bus_b(1),
            o_xnor_out => w_bit_match(1)
        );

    u2 : xnor2
        PORT MAP (
            i_in1      => i_bus_a(2),
            i_in2      => i_bus_b(2),
            o_xnor_out => w_bit_match(2)
        );

    u3 : xnor2
        PORT MAP (
            i_in1      => i_bus_a(3),
            i_in2      => i_bus_b(3),
            o_xnor_out => w_bit_match(3)
        );

    u4 : and4
        PORT MAP (
            i_in1     => w_bit_match(0),
            i_in2     => w_bit_match(1),
            i_in3     => w_bit_match(2),
            i_in4     => w_bit_match(3),
            o_and_out => o_equals
        );

END structure;

Understanding Named Port Mapping (=>): One of the most common mistakes beginners make in structural VHDL is thinking the => symbol shows which way data flows. It does not! The => symbol is the association operator—always read it simply as “is wired to,” following this fixed rule:

   pin_on_the_component   =>   signal_in_this_architecture
        (LEFT side)                     (RIGHT side)

Let’s trace two lines from u0 (xnor2) to see why the direction of data does not change the order:

  • i_in1 => i_bus_a(0) (an input to xnor2): The xnor2 component’s i_in1 pin (left) is wired to bit 0 of compare’s i_bus_a input bus (right). Even though data flows into i_in1, the component’s pin still goes on the left.

  • o_xnor_out => w_bit_match(0) (an output from xnor2): The xnor2 component’s o_xnor_out pin (left) is wired to our internal wire w_bit_match(0) (right).

  • Then, in u4 (and4), i_in1 => w_bit_match(0) wires that exact same internal wire w_bit_match(0) to the and4 component’s i_in1 pin—completing the physical connection shown in the schematic!

Comparing the Three Styles#

All three architectures above describe the exact same 4-bit comparator. In fact, a single VHDL architecture can even mix styles (for example, combining dataflow equations with structural component instances).

Style

Best Used For

Key Syntax

Dataflow

Boolean equations and combinational logic

<=, AND, OR, XNOR, NOT

Behavioral

High-level, algorithmic decision-making

PROCESS (...), IF ... THEN ... ELSE

Structural

Connecting existing modules into a larger system

COMPONENT, SIGNAL, PORT MAP (... => ...)

Worked Example 3: Writing a Dataflow Architecture#

Prompt: Write a Dataflow architecture named dataflow for the half_adder entity you saw in Worked Example 2. Digital Logic Refresher: In binary addition of two 1-bit numbers i_a and i_b:

  • The sum bit is 1 when i_a and i_b are different (i_a XOR i_b).

  • The carry-out bit is 1 only when both i_a and i_b are 1 (i_a AND i_b).

Solution Walkthrough#

  1. Header: Match the entity name: ARCHITECTURE dataflow OF half_adder IS.

  2. Internal signals: None are needed since both outputs can be driven directly from the inputs.

  3. Concurrent equations: After BEGIN, write the two Boolean equations using <=. Remember that because VHDL is concurrent, the order of these two lines does not matter.

ARCHITECTURE dataflow OF half_adder IS
BEGIN
    o_sum       <= i_a XOR i_b;
    o_carry_out <= i_a AND i_b;
END dataflow;

Worked Example 4: Completing a Structural Architecture#

Prompt: A Full Adder adds three 1-bit inputs (i_bit_a, i_bit_b, and i_carry_in) to produce o_full_sum and o_carry_out. It can be built structurally from two half_adder components and one 2-input or2 gate:

  • u0 (half_adder) adds i_bit_a and i_bit_b, outputting partial sum w_partial_sum and partial carry w_carry_1.

  • u1 (half_adder) adds w_partial_sum and i_carry_in, outputting the final o_full_sum and partial carry w_carry_2.

  • u2 (or2) ORs w_carry_1 and w_carry_2 to produce o_carry_out.

Complete the missing parts of the structural architecture below (the or2 component declaration, the internal signals, and the u1 and u2 instantiations).

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

ENTITY full_adder IS
    PORT (
        i_bit_a, i_bit_b, i_carry_in : IN  std_logic;
        o_full_sum, o_carry_out      : OUT std_logic
    );
END full_adder;

ARCHITECTURE structure OF full_adder IS

    COMPONENT half_adder IS
        PORT (
            i_a, i_b    : IN  std_logic;
            o_sum       : OUT std_logic;
            o_carry_out : OUT std_logic
        );
    END COMPONENT half_adder;

    -- TODO 1: Declare the or2 component (ports: i_in1, i_in2, o_or_out)

    -- TODO 2: Declare internal wiring signals w_partial_sum, w_carry_1, and w_carry_2

BEGIN

    u0 : half_adder
        PORT MAP (
            i_a         => i_bit_a,
            i_b         => i_bit_b,
            o_sum       => w_partial_sum,
            o_carry_out => w_carry_1
        );

    -- TODO 3: Instantiate u1 (half_adder) and u2 (or2)

END structure;

Solution Walkthrough#

  1. TODO 1 (Component Declaration): Declare or2 component with:

    • i_in1, i_in2 : IN std_logic;

    • o_or_out : OUT std_logic (no trailing semicolon).

  2. TODO 2 (Internal Signals): Use SIGNAL keyword to declare for following std_logic internal signals:

    • w_partial_sum

    • w_carry_1

    • w_carry_2

  3. TODO 3 (Instantiations): Instantiate the following components, remembering to always keep the component’s port on the left of => and the full_adder signal/port on the right:

    • For u1, map half_adder’s:

      • i_a to w_partial_sum

      • i_b to i_carry_in

      • o_sum to o_full_sum

      • o_carry_out to w_carry_2.

    • For u2, map or2’s:

      • i_in1 to w_carry_1

      • i_in2 to w_carry_2

      • o_or_out to o_carry_out.

ARCHITECTURE structure OF full_adder IS

    COMPONENT half_adder IS
        PORT (
            i_a, i_b    : IN  std_logic;
            o_sum       : OUT std_logic;
            o_carry_out : OUT std_logic
        );
    END COMPONENT half_adder;

    COMPONENT or2 IS
        PORT (
            i_in1, i_in2 : IN  std_logic;
            o_or_out     : OUT std_logic
        );
    END COMPONENT or2;

    SIGNAL w_partial_sum, w_carry_1, w_carry_2 : std_logic;

BEGIN

    u0 : half_adder
        PORT MAP (
            i_a         => i_bit_a,
            i_b         => i_bit_b,
            o_sum       => w_partial_sum,
            o_carry_out => w_carry_1
        );

    u1 : half_adder
        PORT MAP (
            i_a         => w_partial_sum,
            i_b         => i_carry_in,
            o_sum       => o_full_sum,
            o_carry_out => w_carry_2
        );

    u2 : or2
        PORT MAP (
            i_in1    => w_carry_1,
            i_in2    => w_carry_2,
            o_or_out => o_carry_out
        );

END structure;

Checkpoint 3#

(Check your work against the Checkpoint Answers at the end of the chapter.)

  1. In VHDL, what is the difference between =, <=, and =>?

  2. Look at the Behavioral architecture of compare. Why are i_bus_a and i_bus_b listed in PROCESS (i_bus_a, i_bus_b)?

  3. In a Structural architecture, why is it an error to instantiate a component (like u0 : xnor2 PORT MAP (...)) without first writing a COMPONENT xnor2 ... END COMPONENT; declaration?


5. Designing Big Systems: Abstraction and Hierarchy#

You just saw how two Half Adders and an OR gate can be wired together to create a Full Adder. Now imagine trying to design an entire computer processor—containing millions of logic gates—by writing every single gate in one massive file. It would be impossible to read, test, or debug.

Digital engineers tame this complexity using two foundational concepts:

1. Abstraction#

Once an entity/architecture pair (like full_adder) has been designed and thoroughly tested, you no longer need to think about the gates inside it. You can treat it as a trusted “black box” and think of it strictly from the “what do these pins do?” point of view. That is abstraction.

2. Hierarchy#

Hierarchy means building complex systems in layers out of increasingly complex, abstracted entities. Instead of jumping straight from basic gates to a 32-bit adder, you build step by step:

  Level 1 (Gate Level):      XOR, AND, OR gates
                                   │
                                   ▼
  Level 2 (Half Adder):      Built from 1 XOR gate + 1 AND gate
                                   │
                                   ▼
  Level 3 (Full Adder):      Built from 2 Half Adders + 1 OR gate
                                   │
                                   ▼
  Level 4 (32-bit Adder):    Built from 32 Full Adders chained together

Notice how VHDL’s Structural architecture directly supports both principles: you declare a tested lower-level entity as a COMPONENT (relying on abstraction so you only care about its pins), and then instantiate multiple copies of it inside a higher-level architecture (building hierarchy).

Checkpoint 4#

(Check your work against the Checkpoint Answers at the end of the chapter.)

  1. Once you have built and verified your full_adder entity/architecture pair, how does abstraction help you when you move on to building a 32-bit adder?

  2. Give an example of hierarchy from the compare circuit we built earlier in this chapter.


Chapter Summary & Quick Reference#

  • Concurrent Hardware: VHDL describes physical digital circuits that run simultaneously on an FPGA, not sequential software instructions.

  • Entity/Architecture Pair: Every VHDL module has an Entity (the external pins/ports of the IC chip) and an Architecture (the internal structure/behavior inside that chip).

  • Libraries & Types: Include LIBRARY ieee; USE ieee.std_logic_1164.ALL; to use std_logic (1-bit wire, single quotes '0'/'1') and std_logic_vector (multi-bit bus, double quotes "...", typically DOWNTO, indexed with parentheses like i_bus_a(0)).

  • Port Modes: IN (read only), OUT (assign only, cannot read internally), INOUT (bidirectional—can both read and assign), and BUFFER (output that can also be read internally—though using an internal SIGNAL assigned to an OUT port is preferred).

  • Three Architecture Styles:

    • Dataflow: Concurrent Boolean equations (and conditional assignments).

    • Behavioral: Algorithmic descriptions inside a PROCESS block.

    • Structural: Explicit COMPONENT declarations, internal SIGNAL wires, and uniquely Named Instances connected via named PORT MAP (component_pin => signal_in_this_architecture).

  • Abstraction & Hierarchy: Hide tested internal details behind an entity’s pins, and assemble small building blocks into complex systems.


Checkpoint Answers#

Checkpoint 1 Answers#

  1. VHDL is a hardware description language, not a software programming language. When synthesized for an FPGA, VHDL creates physical logic gates and wires that all operate concurrently (at the same time), rather than instructions executed one by one on a CPU.

  2. No. Because dataflow statements represent independent physical circuits operating concurrently, the order in which they are written in the file does not change the hardware created.

Checkpoint 2 Answers#

  1. i_reset_n is legal. The illegal ones are:

    • 4_bit_adder: Starts with a digit (must start with a letter).

    • o_sum_: Ends with an underscore.

    • w_bus__a: Contains two consecutive underscores.

    • out: Reserved VHDL keyword.

  2. o_leds(2) <= '1'; You must use single quotes ('1') because o_leds(2) selects a single wire (std_logic) from the 4-bit bus.

  3. BUFFER technically allows data to go out of the entity and be read back internally. However, the recommended best practice is to declare an internal SIGNAL, read and drive it inside the architecture, and assign it to a standard OUT port.

  4. Error 1: There is an extra semicolon after o_result : OUT std_logic; (the last port before ); must not have a semicolon). Error 2: The closing line says END gate;, which does not match the entity name my_gate (it should be END my_gate;).

Checkpoint 3 Answers#

  1. = tests for equality (like == in many software languages). <= is the signal assignment operator (drives a value onto a wire/signal). => is the port mapping association operator (wires a component’s pin on the left to a local signal on the right).

  2. (i_bus_a, i_bus_b) is the sensitivity list. It tells VHDL that the logic inside the process depends on i_bus_a and i_bus_b, so the process should re-evaluate whenever either input changes.

  3. Declaring a COMPONENT puts that building block into your architecture’s “parts inventory.” Without the declaration, VHDL does not know what pins the xnor2 chip has when you try to instantiate and wire it.

Checkpoint 4 Answers#

  1. Because full_adder is already designed and tested, abstraction lets you ignore its internal Half Adders and OR gate and think of it purely as a black box with three input pins (i_bit_a, i_bit_b, i_carry_in) and two output pins (o_full_sum, o_carry_out).

  2. In the structural compare circuit, the higher-level 4-bit compare entity is built hierarchically out of lower-level xnor2 and and4 gate components.