jamesegg
Newbie level 2
- Joined
- Nov 16, 2013
- Messages
- 2
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 24
Hi guy, I'm getting stuck in a rut here. I'm very new to VHDL so please be paitent
How can I alter mid to allow for varied bit lengths? If I alter the value from (3 downto 0) it throws up errors of unexpected bit lengths! Any explanation would be much apreciated, thanks in Advance.
How can I alter mid to allow for varied bit lengths? If I alter the value from (3 downto 0) it throws up errors of unexpected bit lengths! Any explanation would be much apreciated, thanks in Advance.
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 32 33 34 35 36 37 38 39 40 41 Library IEEE; Use IEEE.STD_LOGIC_1164.ALL; Use IEEE.NUMERIC_STD.ALL; use ieee.std_logic_unsigned.all; Entity ALU is Port ( A, B : in STD_LOGIC_vector (3 downto 0); Sel : in STD_LOGIC_vector (3 downto 0); Z: out STD_LOGIC_vector (3 downto 0)); End ALU; Architecture job of ALU is signal Mid: STD_LOGIC_vector (3 downto 0); Begin Process (sel,A,B) Begin if (sel="000") then Mid <= A or B; elsif (sel="001") then Mid <= A and B; elsif (sel="010") then Mid <= A nor B; elsif (sel="011") then Mid <= A nand B; elsif (sel="100") then Mid <= A xor B; elsif (sel="101") then Mid <= A nand B; elsif (sel="110") then Mid <= A xnor B; else Mid <= std_logic_vector(unsigned(A) + unsigned(B)); end if; End process; Process (sel,mid) Begin if (sel="111") and (mid <"00101") then Z <= "1000" ; elsif (sel="111") and (mid <"01001") then Z <= "0100" ; elsif (sel="111") and (mid <"01101") then Z <= "0010" ; elsif (sel="111") and (mid <"10001") then Z <= "0001" ; else Z <="0000"; end if; End process; End job;
Last edited by a moderator: