Professional Documents
Culture Documents
VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity and1 is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
c : out STD_LOGIC);
end and1;
begin
c<= a AND b;
end Behavioral;
module and2;
reg a;
reg b;
// Outputs
wire c;
// Instantiate the Unit Under Test (UUT)
and1uut (
.a(a),
.b(b),
.c(c)
);
initial begin
// Initialize Inputs
a = 0;b = 0;#100;
a = 0;b = 1;#100;
a = 1;b = 0;#100;
a = 1;b = 1;#100;
end
endmodule
OR
VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity or1 is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
c : out STD_LOGIC);
end or1;
begin
c <= a OR b;
end Behavioral;
VERILOG
module or2;
// Inputs
reg a;
reg b;
// Outputs
wire c;
// Instantiate the Unit Under Test (UUT)
or1uut (
.a(a),
.b(b),
.c(c)
);
initial begin
// Initialize Inputs
a = 0;b = 0;#200;
a = 0;b = 1;#200;
a = 1;b = 0;#200;
a = 1;b = 1;#200;
// Add stimulus here
end
endmodule
NAND GATE
VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity and1 is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
c : out STD_LOGIC);
end and1;
begin
c<= a NAND b;
end Behavioral;
module and2;
reg a;
reg b;
// Outputs
wire c;
// Instantiate the Unit Under Test (UUT)
and1uut (
.a(a),
.b(b),
.c(c)
);
initial begin
// Initialize Inputs
a = 0;b = 0;#100;
a = 0;b = 1;#100;
a = 1;b = 0;#100;
a = 1;b = 1;#100;
end
endmodule
AND GATE
VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity and1 is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
c : out STD_LOGIC);
end and1;
begin
c<= a NOR b;
end Behavioral;
module and2;
reg a;
reg b;
// Outputs
wire c;
// Instantiate the Unit Under Test (UUT)
and1uut (
.a(a),
.b(b),
.c(c)
);
initial begin
// Initialize Inputs
a = 0;b = 0;#100;
a = 0;b = 1;#100;
a = 1;b = 0;#100;
a = 1;b = 1;#100;
end
endmodule
XOR
VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity xor1 is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
c : out STD_LOGIC);
end xor1;
begin
c <= a XOR b;
end Behavioral;
endmodule
XNOR
VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity xor1 is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
c : out STD_LOGIC);
end xor1;
begin
c <= a XNOR b;
end Behavioral;
endmodule
BOOLEAN EXPRESSION 1
VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity boolean1 is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
c : in STD_LOGIC;
d : out STD_LOGIC);
end boolean1;
begin
d <= ((not a)and b and c)or(a and(b or c))or (a and (not b) and c);
end Behavioral;
TEXT FIXTURE
module boolean_1;
// Inputs
reg a;
reg b;
reg c;
// Outputs
wire d;
initial begin
// Initialize Inputs
a = 0;
b = 0;
c = 0;
a = 0;
b = 1;
c = 0;
a = 0;
b = 1;
c = 1;
BOOLEAN EXPRESSION 2
VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity boolean2 is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
c : in STD_LOGIC;
d : out STD_LOGIC);
end boolean2;
begin
d <= ((not a)and (not b)and (not c)) or (b and(a or (not c)));
end Behavioral;
TEXT FIXTURE
module boolean_2;
// Inputs
reg a;
reg b;
reg c;
// Outputs
wire d;
initial begin
// Initialize Inputs
a = 0;
b = 0;
c = 0;
a = 0;
b = 1;
c = 0;
a = 0;
b = 1;
c = 1;
BOOLEAN EXPRESSION 3
VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity boolean3 is
Port ( x : in STD_LOGIC;
y : in STD_LOGIC;
z : in STD_LOGIC;
a : out STD_LOGIC);
end boolean3;
begin
a <= (x and y and (not z)) or ((not x) and y and z) or (x and (not y) and z);
end Behavioral;
TEXT FIXTURE
module boolean_3;
// Inputs
reg x;
reg y;
reg z;
// Outputs
wire a;
initial begin
// Initialize Inputs
x = 0;
y = 0;
z = 0;
HALF ADDER
VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity half1 is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
s : out STD_LOGIC;
c : out STD_LOGIC);
end half1;
begin
s<=a xor b;
c<= a and b;
end Behavioral;
endmodule
FULL ADDER
VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity FULLADDER1 is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Cin : in STD_LOGIC;
Cout : out STD_LOGIC;
S : out STD_LOGIC);
end FULLADDER1;
begin
S<=A XOR B XOR Cin;
Cout<=(A AND B) OR (Cin AND A) OR (Cin AND B);
end Behavioral;
entity fulladder1 is
Port ( a1 : in STD_LOGIC;
b1 : in STD_LOGIC;
cin : in STD_LOGIC;
s1: out STD_LOGIC;
cout : out STD_LOGIC);
end fulladder1;
architecture Behavioral of fulladder1 is
componenthalfadder is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
s : out STD_LOGIC;
c : out STD_LOGIC);
end component;
signal s2,x,y: STD_LOGIC;
begin
l1: halfadder port map(a1,b1,s2,x);
l2: halfadder port map(s2,cin,s1,y);
cout<=x or y;
begin
cout(0)<= m;
l1: for I in 3 downto 0 generate
x1: Xo_gate port map (m,b(i),sum(i));
end generate;
c<=cout(4);
end Behavioral;
end
endmodule
3: 8 DECODER
VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Decoder is
Port ( a : in STD_LOGIC_VECTOR (2 downto 0);
y : out STD_LOGIC_VECTOR (7 downto 0));
end Decoder;
begin
y<= "10000000" when a="000" else
"01000000" when a="001" else
"00100000" when a="010" else
"00010000" when a="011" else
"00001000" when a="100" else
"00000100" when a="101" else
"00000010" when a="110" else
"00000001" when a="111" ;
end Behavioral;
begin
m<= (a and s) or (b and (not s));
end Behavioral;
// Inputs
reg a;
reg b;
reg s;
// Outputs
wire m;
initial begin
// Initialize Inputs
a = 0;b = 0;s = 0;#100;
a = 0;b = 1;s = 0;#100;
a = 1;b = 0;s = 0;#100;
a = 1;b = 1;s = 0;#100;
a = 0;b = 0;s = 1;#100;
end
endmodule
4:1 MUX
VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity MUX_4_1 is
Port ( s : in STD_LOGIC_VECTOR (1 downto 0);
d : in STD_LOGIC_VECTOR (3 downto 0);
y : out STD_LOGIC);
end MUX_4_1;
begin
y<= d(0) when s="00" else
d(1) when s="01" else
d(2) when s="10" else
d(3) when s="11" ;
end Behavioral;
module MUX_41;
// Inputs
reg [1:0] s;
reg [3:0] d;
// Outputs
wire y;
initial begin
// Initialize Inputs
s = 2'b 00;
d =4'b 0001;
end
endmodule
D FLIP FLOP
VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity dff is
Port ( d : in STD_LOGIC;
clk : in STD_LOGIC;
qn : out STD_LOGIC;
q_n : out STD_LOGIC);
end dff;
begin
process (clk)
variable temp,temp1:STD_LOGIC;
begin
if(clk='1') then
if(d='0') then
temp:='0';
temp1:='1';
else
temp:='1';
temp1:='0';
end if;
end if;
qn<=temp;
q_n<=temp1;
end process;
end Behavioral;
TEXT BENCH
module dff_;
// Inputs
reg d;
reg clk;
// Bidirs
wire qn;
wire q_n;
initial begin
// Initialize Inputs
d = 0;
clk = 1;
end
endmodule
begin
process(clk,rst)
begin
if (rst='1') then
s<="0000";
elsif (clk='1') then
if (d='1') then
s<=s+1;
else
s<=s-1;
end if;
end if;
end process;
count<=s;
end Behavioral;
TEXT BENCH
begin
d<='1';
rst<='0';
4 BIT ALU
VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_arith.ALL;
use IEEE.STD_LOGIC_unsigned.ALL;
entity ALU4 is
Port ( a : in STD_LOGIC_VECTOR (3 downto 0);
b : in STD_LOGIC_VECTOR (3 downto 0);
scl : in STD_LOGIC_VECTOR (2 downto 0);
outputs : out STD_LOGIC_VECTOR (3 downto 0));
end ALU4;
begin
process(a,b,scl)
begin
case scl is
when "000"=>
outputs<=a+b;
when "001" =>
outputs<=a-b;
when "010" =>
outputs<=a - 1;
when "011" =>
outputs<=a + 1;
when "100" =>
outputs<=a and b;
when "101" =>
outputs<=a or b;
when "110" =>
outputs<=not(a) ;
when "111" =>
outputs<=a xor b;
when others =>
outputs<="0000";
end case;
end process;
end Behavioral;
TEST BENCH
initial begin
// Initialize Inputs
a = 4'b1111;
b = 4'b1010;
scl = 000;
endmodule