Fundamentals of VHDL for Digital Design#
Estimated Reading Time: 30–45 minutes
Learning Objectives#
After completing this chapter, you will be able to:
Explain the fundamental difference between sequential software programming languages (such as Python, C, Java, and Rust) and concurrent hardware description (VHDL).
Define and relate the four core concepts of VHDL: Entity, Architecture, Component, and Named Instance.
Write and interpret valid Entity declarations using IEEE 1164 data types (
std_logicandstd_logic_vector), port modes, legal identifiers, and ESEC naming conventions.Implement and interpret combinational circuits using all three VHDL architecture styles: Dataflow, Behavioral, and Structural (with explicit component declarations and named port mapping).
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 ( |
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.)
Why is it inaccurate to say that an FPGA “runs VHDL code line by line” the way a computer runs a software program?
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:
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.
Architecture: The internal behavior or structure inside that black plastic IC chip (the entity)—describing what actually happens between the entity’s pins.
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!
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
xnor2component 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 (
DOWNTOvs.TO) & Bit Indexing: Suppose you want to send an 8-bit binary number (like10110010) into a circuit. Instead of creating eight separate ports nameddata0,data1, …,data7, digital designers bundle those 8 wires into a single bus, often drawn on schematic diagrams asdata[7:0].In VHDL, you declare this bus as
std_logic_vector(7 DOWNTO 0). WhyDOWNTO? 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\)). UsingDOWNTOkeeps each bit’s index aligned with its power of 2.Note that VHDL also allows ascending ranges using
TO, such asstd_logic_vector(0 TO 3), where bit 0 is on the left. While we primarily useDOWNTOin this course, knowing thatTOexists 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 ofdata[0]on a schematic). Becauseo_data_out(0)refers to just one wire (std_logic), you must use single quotes ('0'or'1').
Legal VHDL Identifiers#
Every entity, port, signal, and architecture needs a name (an identifier). VHDL enforces four strict rules:
Only letters (
A–Z,a–z), digits (0–9), and underscores (_) are allowed.The first character must be a letter.
The last character cannot be an underscore, and two underscores in a row (
__) are not allowed.Reserved words (keywords like
entity,port,in,out,case,end) cannot be used as names.
Additionally, VHDL is case-insensitive (i_Clk, I_CLK, and i_clk all refer to the exact same identifier), though staying consistent makes your code much easier to read.
Legal Identifiers |
Illegal Identifiers |
Reason Illegal |
|---|---|---|
|
|
Starts with an underscore |
|
|
Starts with a digit |
|
|
Contains an invalid character ( |
|
|
Reserved VHDL keyword |
|
|
Two consecutive underscores |
|
|
Ends with an underscore |
Best Practice — Choose Descriptive Identifiers: Just because an identifier is legal in VHDL does not mean it is a good name. Always choose descriptive names that make a signal’s function immediately obvious to a human reader—for example,
i_data_in,o_carry_out, ando_suminstead of cryptic abbreviations likei_x,o_c, oro_s. Short, single-letter names are acceptable only when they are universally recognized standard notation for a specific component (such asi_dando_qon a D flip-flop, ori_aandi_bon a half adder).
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 |
|---|---|---|
|
On-chip input port |
|
|
On-chip output port |
|
|
On-chip bidirectional port |
|
|
Internal combinational signal |
|
|
Internal / top-level wiring signal (connecting components) |
|
|
Active-low signal ( |
|
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) |
|---|---|---|
|
Synchronous / flip-flop signal (updates on a clock edge) |
|
|
Constant (fixed value, such as clock period or bus width) |
|
|
State machine enumerated type definition |
|
|
State name inside a state machine |
|
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 anINport, but you can never assign a value to it.OUT: Data leaves the entity only. Inside the architecture, you can assign a value to anOUTport, 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 anINOUTport.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 theBUFFERmode, professional FPGA designers generally avoid usingBUFFERports. In hierarchical designs, connecting aBUFFERport 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 internalSIGNAL, read and drive that internal signal inside the architecture, and then assign it to a standardOUTport (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:
Comma-separated lists:
i_clkandi_resetshare the exact same mode (IN) and type (std_logic), so they can be declared on the same line separated by a comma.The missing last semicolon: Notice that
o_carry_out : OUT std_logicdoes not end with a semicolon! In VHDL, semicolons separate port declarations insidePORT (...), 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.Matching names: The name after
END(black_box) must match the name afterENTITY.
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#
Identify the entity name:
mux2to1(a 2-to-1 multiplexer).Analyze the
INports:i_data_0is a 4-bit input bus (3 DOWNTO 0= bits 3, 2, 1, 0 \(\rightarrow\) 4 wires).i_data_1is also a 4-bit input bus (4 wires).i_selectis 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.
Analyze the
OUTports:o_mux_outis 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#
Start with the IEEE library declarations so
std_logicis available.Choose ESEC names: Conventional half-adder inputs
aandbbecomei_aandi_b. Outputs becomeo_sumando_carry_out.Assign modes and types: All four ports are single-bit wires (
std_logic).i_aandi_bareIN;o_sumando_carry_outareOUT.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.)
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,outSuppose
o_ledsis declared asOUT std_logic_vector(3 DOWNTO 0). Write a single VHDL statement that sets only bit 2 ofo_ledsto logic high (1). Should you use single quotes or double quotes?You are designing a circuit where an output port
o_flagneeds 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?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?
First, compare each pair of corresponding bits (
i_bus_a(0)withi_bus_b(0),i_bus_a(1)withi_bus_b(1), etc.) using a 2-input XNOR gate. Remember the truth table for an XNOR gate—it outputs1whenever both inputs are equal:
|
|
|
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Next, feed all four XNOR outputs into a 4-input AND gate. An AND gate outputs
1only when all of its inputs are1. Therefore,o_equalswill be1if 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:
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. Wheneveri_bus_aori_bus_bchanges, 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, thePROCESSblock as a whole still runs concurrently with everything else in the architecture, and when synthesized onto an FPGA, thisIF/ELSEblock 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:
Declare Components (Stock Your Inventory): Between
ISandBEGIN, list every building-block component you plan to use, copying its exactPORTlist.Declare Internal Wiring Signals: Still between
ISandBEGIN, declare any internalSIGNALwires needed to connect the components to each other (using thew_ESEC prefix).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 toxnor2): Thexnor2component’si_in1pin (left) is wired to bit 0 ofcompare’si_bus_ainput bus (right). Even though data flows intoi_in1, the component’s pin still goes on the left.o_xnor_out => w_bit_match(0)(an output fromxnor2): Thexnor2component’so_xnor_outpin (left) is wired to our internal wirew_bit_match(0)(right).Then, in
u4(and4),i_in1 => w_bit_match(0)wires that exact same internal wirew_bit_match(0)to theand4component’si_in1pin—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 |
|
Behavioral |
High-level, algorithmic decision-making |
|
Structural |
Connecting existing modules into a larger system |
|
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
1wheni_aandi_bare different (i_a XOR i_b).The carry-out bit is
1only when bothi_aandi_bare1(i_a AND i_b).
Solution Walkthrough#
Header: Match the entity name:
ARCHITECTURE dataflow OF half_adder IS.Internal signals: None are needed since both outputs can be driven directly from the inputs.
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) addsi_bit_aandi_bit_b, outputting partial sumw_partial_sumand partial carryw_carry_1.u1(half_adder) addsw_partial_sumandi_carry_in, outputting the finalo_full_sumand partial carryw_carry_2.u2(or2) ORsw_carry_1andw_carry_2to produceo_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#
TODO 1 (Component Declaration): Declare
or2component with:i_in1, i_in2 : IN std_logic;o_or_out : OUT std_logic(no trailing semicolon).
TODO 2 (Internal Signals): Use
SIGNALkeyword to declare for followingstd_logicinternal signals:w_partial_sumw_carry_1w_carry_2
TODO 3 (Instantiations): Instantiate the following components, remembering to always keep the component’s port on the left of
=>and thefull_addersignal/port on the right:For
u1, maphalf_adder’s:i_atow_partial_sumi_btoi_carry_ino_sumtoo_full_sumo_carry_outtow_carry_2.
For
u2, mapor2’s:i_in1tow_carry_1i_in2tow_carry_2o_or_outtoo_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.)
In VHDL, what is the difference between
=,<=, and=>?Look at the Behavioral architecture of
compare. Why arei_bus_aandi_bus_blisted inPROCESS (i_bus_a, i_bus_b)?In a Structural architecture, why is it an error to instantiate a component (like
u0 : xnor2 PORT MAP (...)) without first writing aCOMPONENT 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.)
Once you have built and verified your
full_adderentity/architecture pair, how does abstraction help you when you move on to building a 32-bit adder?Give an example of hierarchy from the
comparecircuit 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 usestd_logic(1-bit wire, single quotes'0'/'1') andstd_logic_vector(multi-bit bus, double quotes"...", typicallyDOWNTO, indexed with parentheses likei_bus_a(0)).Port Modes:
IN(read only),OUT(assign only, cannot read internally),INOUT(bidirectional—can both read and assign), andBUFFER(output that can also be read internally—though using an internalSIGNALassigned to anOUTport is preferred).Three Architecture Styles:
Dataflow: Concurrent Boolean equations (and conditional assignments).
Behavioral: Algorithmic descriptions inside a
PROCESSblock.Structural: Explicit
COMPONENTdeclarations, internalSIGNALwires, and uniquely Named Instances connected via namedPORT 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#
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.
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#
i_reset_nis 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.
o_leds(2) <= '1';You must use single quotes ('1') becauseo_leds(2)selects a single wire (std_logic) from the 4-bit bus.BUFFERtechnically allows data to go out of the entity and be read back internally. However, the recommended best practice is to declare an internalSIGNAL, read and drive it inside the architecture, and assign it to a standardOUTport.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 saysEND gate;, which does not match the entity namemy_gate(it should beEND my_gate;).
Checkpoint 3 Answers#
=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).(i_bus_a, i_bus_b)is the sensitivity list. It tells VHDL that the logic inside the process depends oni_bus_aandi_bus_b, so the process should re-evaluate whenever either input changes.Declaring a
COMPONENTputs that building block into your architecture’s “parts inventory.” Without the declaration, VHDL does not know what pins thexnor2chip has when you try to instantiate and wire it.
Checkpoint 4 Answers#
Because
full_adderis 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).In the structural
comparecircuit, the higher-level 4-bitcompareentity is built hierarchically out of lower-levelxnor2andand4gate components.