These three questions come from a Texas Instruments (TI) Bangalore fresher interview, as shared with this blog in November 2007. For each one you only need to give the relevant VHDL code fragment, that is, the process that drives the flop. You may assume that any signals you need or want to use are defined appropriately. Use obvious labels like d, q, cs_select, reset and so on.
- Give a VHDL code fragment to implement a standard D flip-flop.
- Give a VHDL code fragment to implement a flip-flop with a multiplexer on its input (assume two inputs: a and b).
- Give a VHDL code fragment to implement a flip-flop with a chip select line and an asynchronous reset.
Difficulty: Easy
What the interviewer is checking
These look simple, and they are, which is the point. A fresher who writes them cleanly shows three things: that they know how a flip-flop is described in VHDL, that they know the difference between logic that happens on the clock edge and logic that happens at any time, and that they write code a synthesis tool will turn into the hardware they meant.
The ideas behind the three answers
- A D flip-flop copies its input d to its output q at the rising edge of the clock and holds that value until the next edge. In VHDL, you describe it with a process that waits for the clock and assigns q only inside a rising-edge test.
- A mux in front of a flop is just a choice of which value to capture. The select decides whether a or b reaches the D input; the flop still only updates on the clock edge.
- A chip select here acts as a clock enable: when it is low, the flop keeps its old value. An asynchronous reset clears the flop at once, without waiting for a clock edge, so it must be checked before the clock test and must appear in the process sensitivity list.
The answers
Sol 1: a standard D flip-flop.
process(clk)
begin
if rising_edge(clk) then
q <= d;
end if;
end process;
Sol 2: a flip-flop with a two-input multiplexer on its input.
process(clk)
begin
if rising_edge(clk) then
if (sel = '1') then
q <= a;
else
q <= b;
end if;
end if;
end process;
Sol 3: a flip-flop with a chip select and an asynchronous reset.
process(clk, reset)
begin
if (reset = '1') then
q <= '0';
elsif rising_edge(clk) then
if (cs_select = '1') then
q <= d;
end if;
end if;
end process;
Deep dive: the numbers and details
This part holds full compilable code, a cycle-by-cycle trace, what the synthesis tool builds, timing numbers and the follow-up questions. Skip it if the answers are all you need.
A complete, compilable version
Interviewers sometimes ask you to wrap the fragment in an entity. Here is Sol 3 as a full design unit using the IEEE std_logic_1164 package, where rising_edge is defined.
library ieee;
use ieee.std_logic_1164.all;
entity dff_cs_ar is
port (
clk : in std_logic;
reset : in std_logic; -- active-high, asynchronous
cs_select : in std_logic; -- acts as clock enable
d : in std_logic;
q : out std_logic
);
end entity;
architecture rtl of dff_cs_ar is
begin
process(clk, reset)
begin
if reset = '1' then
q <= '0';
elsif rising_edge(clk) then
if cs_select = '1' then
q <= d;
end if;
end if;
end process;
end architecture;
Cycle-by-cycle trace of Sol 3
| Event | reset | cs_select | d | q after the event | Why |
|---|---|---|---|---|---|
| Reset asserted between edges | 1 | x | x | 0 | Asynchronous: no clock edge needed |
| Rising edge 1 | 0 | 1 | 1 | 1 | Enabled, captures d |
| Rising edge 2 | 0 | 0 | 0 | 1 | Not selected, holds old value |
| Rising edge 3 | 0 | 1 | 0 | 0 | Enabled, captures d |
| Reset asserted mid-cycle | 1 | 1 | 1 | 0 | Reset wins over everything |
What synthesis builds
- Sol 1: one D flip-flop, no extra logic.
- Sol 2: a 2-to-1 multiplexer (q_next = sel AND a OR NOT sel AND b) feeding a D flip-flop.
- Sol 3: a flip-flop with asynchronous clear and a clock enable. If the library has an enable flop, the tool uses it; otherwise it builds a 2-to-1 mux that feeds q back to D when cs_select is low. FPGA logic slices typically have both the enable and the asynchronous clear built into each register, so this costs no extra logic there.
Note that "chip select" in a memory or peripheral normally gates a whole device. In this question it simply enables one flop, which is why the clock-enable reading is the expected answer. Say so in the interview; it shows you thought about the wording.
Timing numbers to quote
For the flop to capture d correctly, d (and the select or enable path in front of it) must settle a setup time t_su before the clock edge and stay stable a hold time t_h after it. The fastest clock the circuit can run at is:
f_max = 1 / (t_clk2q + t_mux + t_su)
With illustrative values t_clk2q = 0.15 ns, t_mux = 0.10 ns and t_su = 0.05 ns for a path from one flop through the mux of Sol 2 into the next flop, f_max = 1 / 0.30 ns, about 3.3 GHz for that path alone. Real designs have much more logic between flops, so the mux is rarely the limit; the point is to show you know the equation.
For the asynchronous reset, the important timing is not when it asserts but when it is released. The release must meet recovery and removal times relative to the clock, which are the setup and hold checks for asynchronous control pins. The usual fix is a reset synchronizer: assert asynchronously, release synchronously through two flops.
Common mistakes
- Missing
then.if (sel = '1')withoutthenis a syntax error in VHDL. Interviewers notice. - Leaving reset out of the sensitivity list in Sol 3. Simulation then only reacts to reset at a clock edge, while synthesis still builds an asynchronous reset, so simulation and hardware disagree.
- Putting the reset test inside the clock test. That gives a synchronous reset, which is a valid design but not what the question asked.
- Using
clk'event and clk = '1'with std_logic. It also fires on a change from X or Z to 1.rising_edge(clk)only fires on a real 0 to 1 transition, which is why it is preferred. - Adding an
else q <= q;or similar. It is harmless inside the clock test but unnecessary; outside the clock test, missing assignments in a combinational process create latches. - Driving q from two processes. With std_logic this creates a resolved multiple-driver signal that simulates as X and will not synthesize as intended.
- Reading an output port. In VHDL-93 you cannot read a port of mode
outinside the architecture; use an internal signal and assign it to q. VHDL-2008 relaxes this.
Follow-up questions to expect
- "Rewrite Sol 3 with a synchronous reset." Move the reset test inside
rising_edge(clk)and remove reset from the sensitivity list. - "Write the same three in Verilog." For example:
always @(posedge clk or posedge reset) if (reset) q <= 1'b0; else if (cs_select) q <= d; - "What happens if reset is released close to the clock edge?" The flop can go metastable or different flops can leave reset in different cycles; use a reset synchronizer.
- "Why is a clock enable better than gating the clock with cs_select?" Gating the clock with ordinary logic creates glitches and skew; an enable keeps the clock clean. When clock gating is wanted for power, use an integrated clock gating cell.
- "Make it an 8-bit register." Declare d and q as
std_logic_vector(7 downto 0)and reset with(others => '0'); the process body does not change.
For more on what goes wrong around the clock edge, see the setup and hold time explainer on this blog.


Your comments will be moderated before it appears here.