set in A vector to the B-th bit value of '1'

M

Merlyn

Guest
I have three inputs and one output in my enity:
entity TEST is
Port ( a : in STD_LOGIC_VECTOR (3 downto 0); --4 bit input
b : in STD_LOGIC_VECTOR (3 downto 0); -- 4 bit input
c : in STD_LOGIC_VECTOR (1 downto 0); --2 bit input
out_0 : out STD_LOGIC_VECTOR (3 downto 0)); --4 bit output
end TEST;


I need to do something like this:
if c = "10" then
if b=("--00") then a_1<= ('---1'); --b(3,4=0 in decimal), a(0)=1
elsif
b_1=("--01") then a_1 <= ("--1-"); --b(3,4=1 in decimal), a(1)=1
elsif
b_1=("--10") then a_1 <= ("-1--"); --b(3,4=2 in decimal), a(2)=1
elsif
b_1=("--11) then a_1 <= ("1---"); end if;--b(3,4=3 in decimal), a(3)=1
end if;
out_3 <= a_1;
--(--bits don't care 0 or 1)

Must I convert STD_LOGIC_VECTOR something else or how can i do that?
 
Am Dienstag, 19. Januar 2016 21:44:39 UTC+1 schrieb Merlyn:
I have three inputs and one output in my enity:
entity TEST is
Port ( a : in STD_LOGIC_VECTOR (3 downto 0); --4 bit input
b : in STD_LOGIC_VECTOR (3 downto 0); -- 4 bit input
c : in STD_LOGIC_VECTOR (1 downto 0); --2 bit input
out_0 : out STD_LOGIC_VECTOR (3 downto 0)); --4 bit output
end TEST;


I need to do something like this:
if c = "10" then
if b=("--00") then a_1<= ('---1'); --b(3,4=0 in decimal), a(0)=1
elsif
b_1=("--01") then a_1 <= ("--1-"); --b(3,4=1 in decimal), a(1)=1
elsif
b_1=("--10") then a_1 <= ("-1--"); --b(3,4=2 in decimal), a(2)=1
elsif
b_1=("--11) then a_1 <= ("1---"); end if;--b(3,4=3 in decimal), a(3)=1
end if;
out_3 <= a_1;
--(--bits don't care 0 or 1)

Must I convert STD_LOGIC_VECTOR something else or how can i do that?

Hi,
you can make use of some type conversion like this:

use numeric_std.all;

a(to_integer(unsigned(b(1 downto 0))) <= '1'
--if you want to do everything in one line add this:
when c="10" else null;

Have a nice synthesis
Eilert
 

Welcome to EDABoard.com

Sponsor

Back
Top