help with vhdl coding

Status
Not open for further replies.

ahyuanz

Newbie level 4
Joined
Sep 29, 2009
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
sg
Activity points
1,317
how to i write for

4input (a,b,c,d) and merge into 1 output with 4bits with 'a' as the msb and 'd' as the lsb
 

i just compiled and it pass, but will it work?


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
entity MUX is
    Port ( 
              EN         : in  STD_LOGIC;
           A_IN      : in  STD_LOGIC;
           B_IN      : in  STD_LOGIC;
           C_IN      : in  STD_LOGIC;
           D_IN  : in  STD_LOGIC;
              RES        : in    STD_LOGIC;
           MUX_OUT : out  STD_LOGIC_VECTOR (3 downto 0));
end MUX;
 
architecture Behavioral of MUX is
 
signal INPUT_PROCESS : std_logic_vector(3 downto 0);
 
begin
 
process (EN, RES)
begin
   if RES ='0' then 
      INPUT_PROCESS <= (others => '0');
   elsif EN ='1' then
        INPUT_PROCESS(0) <= D_IN;
        INPUT_PROCESS(1) <= C_IN;
        INPUT_PROCESS(2) <= B_IN;
        INPUT_PROCESS(3) <= A_IN;
   end if;
    
end process;
 
MUX_OUT <= INPUT_PROCESS;


end Behavioral;
 
Last edited by a moderator:

... or you could replace your process with
MUX_OUT <= (others => '0') when RES = '0' else A_In & B_In & C_In & D_In;

Your process doesn't specifiy what should occur when EN = '0', so I've omitted that too...
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…