0
\$\begingroup\$
entity TestRun01 is
 Port ( Clk : in STD_LOGIC;
 Din : in STD_LOGIC;
 Dout : out STD_LOGIC_vector(11 downto 0));
end TestRun01;
architecture Behavioral of TestRun01 is
 signal regr : std_logic_vector(11 downto 0) :="000000000010"; 
 signal reg : std_logic;
begin
 process(Clk,reg)
 begin
 if falling_edge(CLK) then
 if Din ='1' then
 reg <='1';
 elsif Din='0' then
 reg <='0';
 else
 reg <= reg;
 end if;
 regr(0)<=reg; 
 regr<=regr(10 downto 0) & '0';
 end if;
 end process;
 Dout<=regr;
end Behavioral;

why only shift '0' to the shift register?

why only shift '0' to the shift register?

if I change the code from

regr(0)<=reg; 
regr<=regr(10 downto 0) & '0';

to

regr<=regr(10 downto 0) & '0';
regr(0)<=reg;

the bench mark shows enter image description here

asked Mar 22, 2017 at 16:35
\$\endgroup\$
1
  • 1
    \$\begingroup\$ process(Clk,reg): reg is not required: the fully synchronous process only has to trigger on Clk \$\endgroup\$ Commented Mar 22, 2017 at 19:34

1 Answer 1

2
\$\begingroup\$

Looking at the following two lines of code:

regr(0)<=reg; 
regr<=regr(10 downto 0) & '0';

Since regr has a width of 12 bits, the second line assigns every bit in this signal. Since the last assignment to a particular signal takes priority, your initial assignment to regr(0) is effectively ignored.

In the second example with the two lines swapped, the last assignment to regr(0)<=reg; takes priority over the assignment to '0' on the previous line.

The more readable version would look like this:

regr <= regr(10 downto 0) & reg;

thus performing the whole assignment in one line without potential for confusion.

In your second example, you are seeing 'U' being shifted through, because your signal reg is not initialised. You could initialise your signal to '0' using:

signal reg : std_logic := '0'
answered Mar 22, 2017 at 16:43
\$\endgroup\$
3
  • \$\begingroup\$ Thanks for your help! why the last assignment to a particular signal takes priority? \$\endgroup\$ Commented Mar 22, 2017 at 21:07
  • 1
    \$\begingroup\$ @YuanCao, it is part of the VHDL standard that the final assignment in a succession of assignments to a single destination takes priority. \$\endgroup\$ Commented Mar 22, 2017 at 22:02
  • \$\begingroup\$ IEEE Std 1076-2008 10.5.2.2 Executing a simple assignment statement. See paragraph 8 rules 1) thru 5). Not so much 'takes priority' as deletes the old transactions from the projected output waveform. \$\endgroup\$ Commented Mar 23, 2017 at 10:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.