The value of a bit can be stored in a building block called D flip-flop.
A D flip-flop stores one bit of data. A new value can be stored when a clock signal changes value. A component which can change its stored value only when a clock signal changes is called a synchronous component.
A D flip-flop implementation in VHDL is shown in Figure 2.
library ieee; use ieee.std_logic_1164.all; entity d_ff is port( clk: in std_logic; data_in: in std_logic; data_out: out std_logic); end d_ff; architecture rtl of d_ff is signal reg_value: std_logic; begin update: process(clk) begin if rising_edge(clk) then reg_value <= data_in; end if; end process; data_out <= reg_value; end rtl;
Figure 2. A D flip-flop in VHDL.
The code in Figure 2 starts with a reference to a library. We use the library to get access to a data type called std_logic. Variables of this data type represent binary data.
The architecture block, which is called rtl, for register-transfer level, defines a variable called reg_value. The variable reg_value is defined using the keyword signal.
The variable reg_value will contain the actual value stored in the D flip-flop.
A VHDL process called update defines actions to be taken at every rising edge of the clock signal. We see that the only action taken is to assign the value of the input data_in to the state variable reg_value. This assignment ensures that the state variable reg_value is updated at every rising edge of the clock.
An assignment of the variable data_out is done, outside of the process update. This assignment ensures that the output data_out has the same value as the current value of the state variable reg_value.