[SOLVED]Need help understanding a step in VHDL code for Shift Register

Status
Not open for further replies.

navienavnav

Member level 1
The following is the code given for a shift register in my textbook :

Code:
ENTITY shiftreg IS
GENERIC (n: INTEGER := 4); -- # of stages
PORT (d, clk, rst: IN STD_LOGIC;
q: OUT STD_LOGIC);
END shiftreg;

ARCHITECTURE behavior OF shiftreg IS
SIGNAL internal: STD_LOGIC_VECTOR (n-1 DOWNTO 0);
BEGIN
PROCESS (clk, rst)
BEGIN
IF (rst='1') THEN
internal <= (OTHERS => '0');
ELSIF (clk'EVENT AND clk='1') THEN
internal <= d & internal(internal'LEFT DOWNTO 1);
END IF;
END PROCESS;
q <= internal(0);
END behavior;
I can't understand the statement :
internal <= (OTHERS => '0');
What is this statement doing exactly? I have seen the use of the '=>' operator in CASE but I don't what and how it is doing here.

FvM

Super Moderator
Staff member
It's a specific syntax used in bit vector and array aggregates. Because no elements besides OTHERS are assigned, the expression simply means: set all elements to '0'.

ashes35

Junior Member level 1
the statement is basically internal=x"0000" which means internal equals zero.
Edit: internal="0000"

navienavnav

Member level 1
Thanks you.

internal <= d & internal(internal'LEFT DOWNTO 1);
It is pushing the bit stored in d into internal but i don't understand the rest of it, that is internal(internal'LEFT DOWNTO 1)...what is this doing (syntactically) ?

ashes35

Junior Member level 1
left is maximum bit number of internal so i think d means 1-bit data .The statement push first order bit to zero order bit and secondly change most significant bit with d in ever cycle.

FvM

Super Moderator
Staff member
internal<="0000" is correct but only valid for n=4. It should work for n value of n.

internal'LEFT is an attribute expression and gives 3 (n-1) in this case. So you can rewrite the assignment for n=4 as
Code:
internal <= d & internal(3 DOWNTO 1);

navienavnav

Member level 1
internal<="0000" is correct but only valid for n=4. It should work for n value of n.

internal'LEFT is an attribute expression and gives 3 (n-1) in this case. So you can rewrite the assignment for n=4 as
Code:
internal <= d & internal(3 DOWNTO 1);