Consider this 4-bit shift register initialized to "0000". On each rising clock edge, it shifts in the input bit '1'. What is the content of the register after 3 clock cycles?
library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity shift_reg is Port ( clk : in STD_LOGIC; reset : in STD_LOGIC; data_in : in STD_LOGIC; data_out : out STD_LOGIC_VECTOR (3 downto 0)); end shift_reg; architecture Behavioral of shift_reg is signal reg : STD_LOGIC_VECTOR(3 downto 0) := (others => '0'); begin process(clk, reset) begin if reset = '1' then reg <= (others => '0'); elsif rising_edge(clk) then reg <= reg(2 downto 0) & data_in; end if; end process; data_out <= reg; end Behavioral;
Each clock cycle shifts the bits left and adds the new input bit at the right end.
Initially, the register is "0000". After 1 clock cycle, it becomes "0001". After 2 cycles, "0011". After 3 cycles, "0111".
Given a shift register that shifts bits to the left on each rising clock edge and inserts a new bit at the right, which of the following best describes its function?
Think about the direction bits move and where the new bit enters.
The register shifts bits left (towards MSB) and inserts the new bit at the right (LSB).
Examine this VHDL code snippet for a shift register. What error will occur when compiling?
process(clk)
begin
if rising_edge(clk) then
reg <= reg(3 downto 1) & data_in;
end if;
end process;Check the vector slice range carefully.
If reg is 4 bits (3 downto 0), slicing reg(3 downto 1) gives 3 bits, but concatenating with data_in (1 bit) results in 4 bits. This is valid. However, if reg is declared differently, or if the slice is out of range, an index error occurs. The question assumes reg is 4 bits (3 downto 0), so this slice is valid. But if reg is declared as (0 to 3), this slice is invalid.
Given the code snippet alone, the most likely error is an index range error if reg is declared (0 to 3).
Choose the correct VHDL signal declaration for a 4-bit shift register named reg with bits indexed from 3 down to 0.
Remember the direction of the index range for descending order.
std_logic_vector(3 downto 0) declares a 4-bit vector with index 3 as the most significant bit and 0 as the least significant bit.
A 5-bit shift register is initialized to all zeros. On each rising clock edge, it shifts left and inserts a '1' at the right. How many clock cycles are required until the register contains all ones?
Each clock cycle inserts one '1' bit at the right end.
Starting from "00000", after 1 cycle: "00001", after 2: "00011", after 3: "00111", after 4: "01111", after 5: "11111".
