Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

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

Status
Not open for further replies.

navienavnav

Member level 1
Joined
Dec 12, 2011
Messages
36
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
India.
Activity points
1,627
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.

Please help. :sad:
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,871
Helped
14,125
Reputation
28,507
Reaction score
12,808
Trophy points
1,393
Location
Bochum, Germany
Activity points
277,832
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
Joined
May 15, 2012
Messages
18
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,400
the statement is basically internal=x"0000" which means internal equals zero.
Edit: internal="0000"
 

navienavnav

Member level 1
Joined
Dec 12, 2011
Messages
36
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
India.
Activity points
1,627
Thanks you.

And what about this one :

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
Joined
May 15, 2012
Messages
18
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,400
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
Joined
Jan 22, 2008
Messages
47,871
Helped
14,125
Reputation
28,507
Reaction score
12,808
Trophy points
1,393
Location
Bochum, Germany
Activity points
277,832
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);
Already clear? Otherwise read about the meaning of the concatenation operator "&".
 

navienavnav

Member level 1
Joined
Dec 12, 2011
Messages
36
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
India.
Activity points
1,627
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);
Already clear? Otherwise read about the meaning of the concatenation operator "&".
Yes, I got it now! Thank you so much!!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top