Skip to main content

VHDL entity, architecture; D flip-flop

Short answer

An entity declares the design's interface (name, ports with mode and type); an architecture defines its internal behavior using behavioral, dataflow, or structural code. A D flip-flop with asynchronous active-high reset uses a process sensitive to clk and rst: if rst='1' then q<='0'; elsif rising_edge(clk) then q<=d; end if.

Explain entity and architecture of VHDL declaration. Write VHDL code for a D flip-flop using process.

Entity

The entity declaration defines the external interface of a design unit: its name, and its ports (name, direction in/out/inout/buffer, and type). It is like the symbol or black box of the circuit.

entity name is
  port ( signal_name : mode type; ... );
end entity name;

Architecture

The architecture body defines what the entity does, using behavioral, dataflow or structural description. It has a declarative part (signals, components, types) and a statement part between begin and end. One entity can have several architectures.

architecture arch_name of entity_name is
  -- declarations (signals, components, constants)
begin
  -- concurrent statements, processes, component instances
end architecture arch_name;

D flip-flop using a process

The flip-flop copies D to Q at the rising edge of the clock; an asynchronous active-high reset clears Q.

library ieee;
use ieee.std_logic_1164.all;

entity dff is
  port (
    clk : in  std_logic;
    rst : in  std_logic;       -- asynchronous reset, active high
    d   : in  std_logic;
    q   : out std_logic
  );
end entity dff;

architecture behavioral of dff is
begin
  process (clk, rst)
  begin
    if rst = '1' then
      q <= '0';                         -- reset overrides the clock
    elsif rising_edge(clk) then
      q <= d;                           -- store D on the rising edge
    end if;
  end process;
end architecture behavioral;

The process is sensitive to clk and rst. When rst = '1' the output is cleared at once; otherwise on rising_edge(clk) the value of d is stored. Between edges q keeps its value, which makes the process infer a flip-flop. The code was checked with GHDL.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Embedded System chapter 9 questions →