Skip to main content

Behavioral modeling; 2-input multiplexer

Short answer

Behavioral modeling describes function with a process and sequential statements, not gates. A 2-to-1 multiplexer: process(d0,d1,sel) checks sel; if sel='0' then y<=d0 else y<=d1.

What is behavioral modeling? Write VHDL code for 2-input multiplexer.

Behavioral modeling

Behavioral modeling describes the circuit by its function or algorithm, using a process with sequential statements (if, case, loop), without stating gates or connections. The designer writes what output should result for given inputs and the synthesis tool decides the structure. It is closest to high-level programming, quick to write and good for sequential circuits and FSMs.

2-input (2:1) multiplexer

A 2-to-1 multiplexer selects one of two data inputs d0, d1 using the select line sel: y = d0 when sel = 0 and y = d1 when sel = 1.

sely
0d0
1d1
library ieee;
use ieee.std_logic_1164.all;

entity mux2 is
  port (
    d0, d1 : in  std_logic;     -- data inputs
    sel    : in  std_logic;     -- select line
    y      : out std_logic      -- output
  );
end entity mux2;

architecture behavioral of mux2 is
begin
  process (d0, d1, sel)
  begin
    if sel = '0' then
      y <= d0;
    else
      y <= d1;
    end if;
  end process;
end architecture behavioral;

The process is sensitive to d0, d1 and sel, so y updates whenever any input changes. The code was analysed and simulated with GHDL.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Embedded System chapter 9 questions →