Professional Documents
Culture Documents
DATE:30.07.2011
AIM:
To design the program for half adder and full adder using VHDL
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity halfadd is
port(a,b:in std_logic;
s,cout:out std_logic);
end halfadd;
architecture behavioral of halfadd is
begin
s <= a xor b;
cout <= a and b;
end behavioral;
HALF ADDER:
TRUTH TABLE:
OUTPUT:
SUM
CARRY
FULL ADDER:
TRUTH TABLE:
A
SUM
CARRY
OUTPUT:
RESULT:
Thus the program for halfadder & Full adder was simulated by
using VHDL and verified successfully.
EXPT NO:1(b) DESIGN OF HALF ADDER AND FULL ADDER USING VERILOG
DATE:30.07.2011
AIM:
To design the program for half adder and full adder using verilog
HALF ADDER:
TRUTH TABLE:
SUM
CARRY
OUTPUT:
TRUTH TABLE:
SUM
CARRY
OUTPUT:
RESULT:
Thus the program for halfadder & Full adder was simulated by
using VERILOG and verified successfully.
DATE:13.08.2011
VHDL
AIM:
To design the program for half subtractor and full subtractor using VHDL
TRUTH TABLE:
DIFFERENCE
BORROW
OUTPUT:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity fulsub1 is
port(a,b,c:in std_logic;
d, bout:out std_logic);
end fulsub1;
architecture behavioral of fulsub1 is
begin
d <= a xor b xor c;
bout <= ((not a) and b) or ((not (a xor b)) and c) ;
end behavioral;
FULL SUBTRACTOR:
TRUTH TABLE:
DIFFERENCE
BORROW
OUTPUT:
RESULT:
Thus the program for halfsubtractor& Fullsubtractorwas simulated
by using VHDL and verified successfully.
DATE:13.08.2011
VERILOG
AIM:
To design the program for half subtractor and full subtractor using verilog
TRUTH TABLE:
OUTPUT:
DIFFERENCE
BORROW
TRUTH TABLE:
DIFFERENCE
BORROW
OUTPUT:
RESULT:
Thus the program for halfsubtractor& Fullsubtractorwas simulated
by using VERILOG and verified successfully.
DATE:20.08.2011
AIM:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity multip is
port (a,b,c,d,s1,s0:in std_logic;
y :out std_logic);
end multip;
architecture behavioral of multip is
signal e,f,g,h,i,j : std_logic;
begin
y <= g or h or i or j;
e <= not s1;
f <= not s0;
g <= a and e and f;
h <= b and e and s0;
i <= c and s1 and f;
j <= d and s1 and s0;
end behavioral;
MULTIPLEXER
TRUTH TABLE:
S1
S0
OUTPUT
D0
D1
D2
D3
OUTPUT:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity demulti is
port (x,s1,s0:in std_logic;
a,b,c,d :out std_logic);
end demulti;
architecture behavioral of demulti is
signal e,f : std_logic;
begin
e <= not s1;
f <= not s0;
a <= x and e and f;
b <= x and e and s0;
c <= x and s1 and f;
d <= x and s1 and s0;
end behavioral;
DEMULTIPLEXER
TRUTH TABLE:
S1
0
0
0
0
1
1
1
1
S0
0
0
1
1
0
0
1
1
I/P
0
1
0
1
0
1
0
1
D0
0
1
0
0
0
0
0
0
D1
0
0
0
1
0
0
0
0
D2
0
0
0
0
0
1
0
0
D3
0
0
0
0
0
0
0
1
OUTPUT:
RESULT:
Thus the program for Multiplexer& Demultiplexerwas simulated
by using VHDL and verified successfully.
AIM:
To design the program for multiplexer and demultiplexer using verilog
MULTIPLEXER
TRUTH TABLE:
OUTPUT:
S1
S0
OUTPUT
D0
D1
D2
D3
DEMULTIPLEXER:
TRUTH TABLE:
S1
0
0
0
0
1
1
1
1
S0
0
0
1
1
0
0
1
1
I/P
0
1
0
1
0
1
0
1
D0
0
1
0
0
0
0
0
0
D1
0
0
0
1
0
0
0
0
D2
0
0
0
0
0
1
0
0
D3
0
0
0
0
0
0
0
1
OUTPUT:
RESULT:
Thus the program for Multiplexer& Demultiplexerwas simulated
by using Verilog and verified successfully.
AIM:
To design the program for encoder and decoder using VHDL
ENCODER :
TRUTH TABLE:
INPUTS
OUTPUTS
Y0
Y1
Y2
Y3
Y4
Y5
Y6
Y7
OUTPUT:
DECODER:
TRUTH TABLE:
OUTPUT:
D0
D1
D2
D3
RESULT:
Thus the program for encoder& decoderwas simulated by using
VHDL and verified successfully.
DATE:27.08.2011
AIM:
To design the program for encoder and decoder using verilog
PROGRAM FOR ENCODER USING VERILOG:
module encoder8(x,y);
input [7:0]x;
output [2:0]y;
or g1(y[0],x[1],x[3],x[5],x[7]);
or g2(y[1],x[2],x[3],x[6],x[7]);
or g3(y[2],x[4],x[5],x[6],x[7]);
endmodule
ENCODER:
TRUTH TABLE:
INPUTS
OUTPUTS
Y0
Y1
Y2
Y3
Y4
Y5
Y6
Y7
OUTPUT:
input en;
output [3:0]y;
wire c,d;
not g1(c,a);
not g2(d,b);
and g3(y[0],c,d,en);
and g4(y[1],c,b,en);
and g5(y[2],a,d,en);
and g6(y[3],a,b,en);
endmodule
DECODER:
TRUTH TABLE:
D0
D1
D2
D3
OUTPUT:
RESULT:
Thus the program for encoder& decoderwas simulated by using
verilog and verified successfully.
EXPT NO:5(a)DESIGN OF D - FLIP FLOP, T- FLIP FLOP, JK- FLIP FLOP AND SR-
DATE:10.09.2011
AIM:
To design the program for D - Flip Flop, T- Flip Flop, JK- Flip Flop and SRFlip Flop using VHDL
D-FLIPFLOP:
TRUTH TABLE:
D
0
1
Q
X
X
Qn
0
1
OUTPUT:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity tff is
port( t:in std_logic;
clk,rst:in std_logic;
q,qbar: inout std_logic);
end tff;
architecture behavioral of tff is
begin
process(clk)
begin
if rst ='1' then
q <= '0';
qbar <= '1';
else if clk'event and clk = '1' then
if t ='0' then
q <=q;
qbar <= qbar;
else
q <= qbar;
qbar <= q;
end if;
end if
end if;
end process;
end behavioral;
T-FLIP FLOP:
TRUTH TABLE:
OUTPUT:
Commen
t
Hold
state
Hold
state
Qnext
Toggle
Toggle
JK- FLIPFLOP:
TRUTH TABLE:
J
0
0
0
0
1
1
1
1
K
0
0
1
1
0
0
1
1
Q
0
1
0
1
0
1
0
1
Qn
0
1
0
0
1
1
1
0
OUTPUT:
Comment
No Change
No Change
Reset
Reset
Set
Set
Toggle
Toggle
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity SR_ff is
port ( clk, s, r : in std_logic;
q : buffer std_logic);
end SR_ff;
architecture Behavioral of SR_ff is
begin
process( clk)
begin
if (clk'event and clk = '1') then
if (s='0' and r='0')then q<= q;
elsif (s='0' and r='1')then q<= '0';
elsif (s='1' and r='0')then q<= '1';
elsif (s='1' and r='1')then q<= 'Z';
end if ;
end if;
end process ;
end Behavioral;
SR- FLIPFLOP:
TRUTH TABLE:
S
0
0
0
0
1
1
R
0
0
1
1
0
0
Q
0
1
0
1
0
1
Qn
0
1
0
0
1
1
Comment
No Change
No Change
Reset
Reset
Set
Set
Indetermin
e
Indetermiin
e
OUTPUT:
RESULT:
Thus the program for D-flipflop,T-flipflop,JK-flipflop,SR-flipflop
was simulated by using VHDL and verified successfully.
DATE:10.09.2011
AIM:
To design the program for D - Flip Flop, T- Flip Flop, JK- Flip Flop and SRFlip Flop using verilog
TRUTH TABLE:
D
0
1
OUTPUT:
Q
X
X
Qn
0
1
TRUTH TABLE:
OUTPUT:
Commen
t
Hold
state
Hold
state
Qnext
Toggle
Toggle
JK- FLIPFLOP:
TRUTH TABLE:
J
0
0
0
0
1
1
1
1
OUTPUT:
K
0
0
1
1
0
0
1
1
Q
0
1
0
1
0
1
0
1
Qn
0
1
0
0
1
1
1
0
Comment
No Change
No Change
Reset
Reset
Set
Set
Toggle
Toggle
TRUTH TABLE:
S
0
0
0
0
1
1
R
0
0
1
1
0
0
Q
0
1
0
1
0
1
Qn
0
1
0
0
1
1
Comment
No Change
No Change
Reset
Reset
Set
Set
Indetermin
e
Indetermiin
e
OUTPUT:
RESULT:
Thus the program for D-flipflop,T-flipflop,JK-flipflop,SR-flipflop
was simulated by using VHDL and verified successfully.
EXPT NO:6(a)DESIGN OF UP/DOWN SYNCHRONOUS COUNTERUSING VHDL
DATE:24.09.2011
AIM:
To design the program for UP/DOWN synchronous counter using VHDL
PROGRAM FOR SYNCHRONOUS UP COUNTER USING VHDL:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity counter is
port(clk, clr: in std_logic;
q: out std_logic_vector(3 downto 0));
end counter;
architecture archi of counter is
signal tmp: std_logic_vector(3 downto 0);
begin
process(clk,clr)
begin
if(clr ='1') then
tmp <= "0000";
else if clk'event and clk='1' then
tmp <= tmp+1;
end if;
end if;
end process;
q <= tmp;
end archi;
SYNCHRONOUS UP COUNTER:
TRUTH TABLE:
CLK
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
QD
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
QC
0
0
0
0
1
1
1
1
0
0
0
0
1
1
1
1
QB
0
0
1
1
0
0
1
1
0
0
1
1
0
0
1
1
QA
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
OUTPUT:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity counter is
port(clk, clr: in std_logic;
q: out std_logic_vector(3 downto 0));
end counter;
architecture archi of counter is
signal tmp: std_logic_vector(3 downto 0);
begin
process(clk,clr)
begin
if(clr ='1') then
tmp <= "1111";
else if clk'event and clk='1' then
tmp <= tmp-1;
end if;
end if;
end process;
q <= tmp;
end archi;
TRUTH TABLE:
CLK
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
QD
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
QC
1
1
1
1
0
0
0
0
1
1
1
1
0
0
0
0
QB
1
1
0
0
1
1
0
0
1
1
0
0
1
1
0
0
QA
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
OUTPUT:
RESULT:
Thus the program for synchronous UP/DOWN counter simulated
by using VHDL module and verified successfully.
EXPT NO: 6(b)DESIGN OF UP/DOWN SYNCHRONOUS COUNTERUSING VERILOG
DATE:24.09.2011
AIM:
To design the program for UP/DOWN synchronous counter using VHDL
PROGRAM FOR SYNCHRONOUS UP COUNTER USING VERILOG:
module up_counter(q,clk,clr);
output [3:0] q;
input clk, clr;
reg [3:0] q;
always @(posedge clk)
if (clr) begin
q <= 4'b0 ;
end
else
begin
q <= q + 1;
end
endmodule.
SYNCHRONOUS UP COUNTER:
TRUTH TABLE:
CLK
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
QD
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
QC
0
0
0
0
1
1
1
1
0
0
0
0
1
1
1
1
QB
0
0
1
1
0
0
1
1
0
0
1
1
0
0
1
1
QA
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
OUTPUT:
module down_counter(q,clk,clr);
output [3:0] q;
input clk, clr;
reg [3:0] q;
always @(posedge clk)
if (clr)
begin
q <= 4'b1111 ;
end
else
begin
q <= q - 1;
end
endmodule
TRUTH TABLE:
CLK
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
QD
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
QC
1
1
1
1
0
0
0
0
1
1
1
1
0
0
0
0
QB
1
1
0
0
1
1
0
0
1
1
0
0
1
1
0
0
QA
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
OUTPUT:
RESULT:
Thus the program for synchronous UP/DOWN counter simulated
by using verilog module and verified successfully.
EXPT NO:7(a)DESIGN OF 4 BIT RIPPLE COUNTERUSING VHDL
DATE:08.10.2011
AIM:
To design the program for 4 bit Ripple counter using VHDL
TRUTH TABLE:
CLK
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
QD
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
QC
0
0
0
0
1
1
1
1
0
0
0
0
1
1
1
1
QB
0
0
1
1
0
0
1
1
0
0
1
1
0
0
1
1
QA
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
OUTPUT:
RESULT:
Thus the program for 4-bit ripple counter was simulated by using
VHDL module and verified successfully.
EXPT NO:7(b)
DATE:08.10.2011
AIM:
To design the program for 4 bit ripple counter using verilog
PROGRAM FOR 4 BIT RIPPLE COUNTER USING VERILOG:
module co(q,clk,clr);
input clk,clr;
output[3:0]q;
reg[3:0]q;
always@(posedge clr or negedge clk)
begin
if(clr)
q<=4'b0000;
else
q<=q+1;
end
endmodule.
4 BIT RIPPLE COUNTER:
TRUTH TABLE:
CLK
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
QD
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
QC
0
0
0
0
1
1
1
1
0
0
0
0
1
1
1
1
QB
0
0
1
1
0
0
1
1
0
0
1
1
0
0
1
1
QA
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
OUTPUT:
RESULT:
Thus the program for 4-bit ripple counter was simulated by using
Verilog module and verified successfully.
EXPT NO:8(a)
DATE:15.10.2011
AIM:
To design the program for ring counter and BCD counter using VHDL
PROGRAM FOR RING COUNTER USING VHDL:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ringc is
Port ( clk,rst : in STD_LOGIC;
q : out STD_LOGIC_VECTOR (3 downto 0));
end ringc;
architecture Behavioral of ringc is
signal r_reg: std_logic_vector(3 downto 0);
signal r_next: std_logic_vector(3 downto 0);
begin
process(clk,rst)
begin
if(rst='1') then
r_reg<= (0=> '1', others =>'0');
elsif(clk'event and clk='1') then
r_reg<= r_next;
end if;
end process;
r_next<= r_reg(0) & r_reg(3 downto 1);
q<= r_reg;
end Behavioral;
RING COUNTER :
TRUTH TABLE:
CLK
0
1
2
3
4
5
6
7
QD
0
1
0
0
0
0
0
1
QC
0
0
1
0
0
0
1
0
OUTPUT:
QB
0
0
0
1
0
1
0
0
QA
0
0
0
0
1
0
0
0
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Counter2_VHDL is
port( Clock_enable: in std_logic;
Clock: in std_logic;
Reset: in std_logic;
Output: out std_logic_vector(0 to 3));
end Counter2_VHDL;
architecture Behavioral of Counter2_VHDL is
signal temp: std_logic_vector(0 to 3);
begin process(Clock,Reset)
begin
if Reset='1' then
temp <= "0000";
elsif(Clock'event and Clock='1') then
if Clock_enable='0' then
if temp="1001" then
temp<="0000";
else
temp <= temp + 1;
end if;
else
temp <= temp;
end if;
end if;
end process;
Output <= temp;
end Behavioral;
BCD COUNTER:
TRUTH TABLE:
CLK
0
1
2
3
4
5
6
7
8
9
10
QD
0
0
0
0
0
0
0
0
1
1
0
QC
0
0
0
0
1
1
1
1
0
0
0
QB
0
0
1
1
0
0
1
1
0
0
0
QA
0
1
0
1
0
1
0
1
0
1
0
OUTPUT:
RESULT:
Thus the program for ring counter and BCD counter was simulated
by using VHDL and verified successfully.
EXPT NO:8(b)DESIGN OF RING COUNTER AND BCD COUNTER USING VERILOG
DATE:15.10.2011
AIM:
To design the program for ring counter and BCD counter using VHDL
PROGRAM FOR RING COUNTER USING VERILOG:
module ringc(count,load,i,clk,clr,a,c0);
input count,load;
input clk,clr;
input [3:0]i;
output[3:0]a;
output c0;
reg[3:0]a;
assign c0=count&~load&(a==4'b1111);
always@(posedge clk or negedge clr)
if(~clr)
a=4'b0000;
else if(load)
a=i;
else if(count)
a=a+1'b1;
else
a=a;
endmodule
RING COUNTER:
TRUTH TABLE:
CLK
0
1
2
3
4
5
6
7
QD
0
1
0
0
0
0
0
1
QC
0
0
1
0
0
0
1
0
QB
0
0
0
1
0
1
0
0
OUTPUT:
QA
0
0
0
0
1
0
0
0
module bcdcount(clk,clr,e,bcd1,bcd0);
input clk,clr,e;
output[3:0]bcd1,bcd0;
reg[3:0]bcd1,bcd0;
always@(posedge clk)
begin
if(clr)
begin
bcd1<=0;
bcd0<=0;
end
else if(e)
if(bcd0==4'b1001)
begin
bcd0<=0;
if(bcd1==4'b1001)
bcd1<=0;
else
bcd1<=bcd1+1;
end
else
bcd0<=bcd0+1;
end
endmodule
BCD COUNTER:
TRUTH TABLE:
CLK
0
1
2
3
4
5
6
7
8
9
10
QD
0
0
0
0
0
0
0
0
1
1
0
QC
0
0
0
0
1
1
1
1
0
0
0
QB
0
0
1
1
0
0
1
1
0
0
0
QA
0
1
0
1
0
1
0
1
0
1
0
OUTPUT:
RESULT:
Thus the program for ring counter and BCD counter was simulated
by using verilog and verified successfully.
EXPT NO:9(a)DESIGN OF JOHNSON COUNTER USING VHDL
DATE:22.10.2011
AIM:
To design the program for johnson counter using VHDL
PROGRAM FOR JOHNSON COUNTER USING VHDL:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity johnson_counter is
port (q : out unsigned(3 downto 0);
clr,clk : in std_logic; );
end johnson_counter;
architecture Behavioral of johnson_counter is
signal temp : unsigned(3 downto 0):=(others => '0');
begin
q <= temp;
process(clk)
begin
if( rising_edge(clk) ) then
if (clr = '1') then
temp <= (others => '0');
else
temp(1) <= temp(0);
temp(2) <= temp(1);
temp(3) <= temp(2);
temp(0) <= not temp(3);
end if;
end if;
end process;
end Behavioral;
JOHNSON COUNTER:
TRUTH TABLE:
CLK
0
1
2
3
4
5
6
7
8
QD
0
1
1
1
1
0
0
0
0
QC
0
0
1
1
1
1
0
0
0
QB
0
0
0
1
1
1
1
0
0
QA
0
0
0
0
1
1
1
1
0
OUTPUT:
RESULT:
Thus the program for Johnson counter was simulated by using
VHDL module and verified successfully.
EXPT NO:9(b)DESIGN OF JOHNSON COUNTER USING VERILOG
DATE:22.10.2011
AIM:
To design the program for johnson counter using verilog
PROGRAM FOR JOHNSON COUNTER USING VERILOG:
module johnson(count,termcount,clk,resetn);
parameter width=0;
output[width+3:0]count;
output termcount;
input clk, resetn;
reg[width+3:0]count;
reg termcount;
always@(posedge clk or negedge resetn)
begin
if(!resetn)
begin
count<=0;
termcount<=0;
end else
begin
count<={count[width+4:0],~count[width+3]};
termcount<=(count[width+3]==1&count[width+4]==0);
end
end
endmodule
JOHNSON COUNTER:
TRUTH TABLE:
CLK
0
1
2
3
4
5
6
7
8
QD
0
1
1
1
1
0
0
0
0
QC
0
0
1
1
1
1
0
0
0
QB
0
0
0
1
1
1
1
0
0
QA
0
0
0
0
1
1
1
1
0
OUTPUT:
RESULT:
Thus the program for Johnson counter was simulated by using
Verilog module and verified successfully.
EXPT NO:10(a)DESIGN OF 4 BIT SHIFT REGISTERUSING VHDL
DATE:05.11.2011
AIM:
To design the program for 4 bit shift register using VHDL
PROGRAM FOR 4 BIT SHIFT REGISTER USING VHDL:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Shift_register_VHDL is
port( Clock, L,w: in std_logic;
Output: out std_logic_vector(3 downto 0);
Input: in std_logic_vector( 3 downto 0));
end Shift_register_VHDL;
architecture Behavioral of Shift_register_VHDL is
signal temp: std_logic_vector(3 downto 0);
begin
process
begin
wait until Clock'event and Clock='1';
if L='1' then
temp <= Input;
else
for i in 0 to 2 loop
temp(i) <= temp(i+1);
end loop;
temp(3) <= w;
end if; end process;
Output <= temp;
end Behavioral;
TRUTH TABLE:
CLK
DA
1
0
1
1
2
3
INPUTS
DB
DC
0
0
1
1
0
1
DD
1
1
0
QA
1
0
1
OUTPUTS
QB
QC
0
0
1
1
0
1
QD
1
1
0
OUTPUT:
RESULT:
Thus the program for 4 bit shift register was simulated by using VHDL
module and verified successfully.
EXPT NO: 10(b)DESIGN OF 4 BIT SHIFT REGISTER USING VERILOG
DATE:05.11.2011
AIM:
To design the program for 4 bit shift register using verilog
PROGRAM FOR 4 BIT SHIFT REGISTER USING VERILOG:
module shift4(r,l,w,clk,q);
input[3:0]r;
input l,w,clk;
output [3:0]q;
reg [3:0]q;
always@(posedge clk)
if(l)
q<=r;
else
begin
q[0]<=q[1];
q[1]<=q[2];
q[2]<=q[3];
q[3]<=w;
end
endmodule
4 BIT SHIFT REGISTER:
TRUTH TABLE:
CLK
DA
1
0
1
1
2
3
INPUTS
DB
DC
0
0
1
1
0
1
DD
1
1
0
QA
1
0
1
OUTPUTS
QB
QC
0
0
1
1
0
1
QD
1
1
0
OUTPUT:
RESULT:
Thus the program for 4 bit shift register was simulated by using Verilog
module and verified successfully.
AIM:
To design the program for multiplexer using test bench using VHDL
PROGRAM FOR MULTIPLEXER USING TEST BENCH USING VHDL:
module mux1(out,i0,i1,i2,i3,s1,s0);
output out;
input i0,i1,i2,i3;
input s1,s0;
wire s1n,s0n;
wire y0,y1,y2,y3;
not (s1n,s1); not (s0n,s0);
and (y0,i0,s1n,s0n); and (y1,i1,s1n,s0);
and (y2,i2,s1,s0n);
and (y3,i3,s1,s0);
or (out,y0,y1,y2,y3);
endmodule
module stimulus;
reg in0,in1,in2,in3; reg s1,s0;
wire output1; mux1(output1,in0,in1,in2,in3,s1,s0);
initial
begin
in0=1;in1=0;in2=1;in3=0;
#100$display
("in0=%b,in1=%b,in2=%b,in3=%b/n",in0,in1,in2,in3);
s1=0;s0=0;
#100$display
("s1=%b,s0=%b,output1=%b/n", s1,s0,output1);
s1=0;s0=1;
#100$display
("s1=%b,s0=%b,output1=%b/n", s1,s0,output1);
s1=1;s0=0;
#100$display
("s1=%b,s0=%b,output1=%b/n", s1,s0,output1);
s1=1;s0=1;
#100$display
("s1=%b,s0=%b,output1=%b/n", s1,s0,output1);
end
endmodule
OUTPUT:
RESULT:
Thus the program for multiplexer using testbench was simulated by
using VHDL and verified successfully.
EXPT NO:12(a)DESIGN OF ALU USING VHDL
DATE:19.11.2011
AIM:
To design the program for ALU using VHDL
PROGRAM FOR ALU USING VHDL:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity alu1 is
port(code:in std_logic_vector(2 downto 0);
a:in std_logic_vector(3 downto 0);
b:in std_logic_vector(3 downto 0);
c:out std_logic_vector(3 downto 0));
end alu1;
architecture behavioral of alu1 is
begin
process(code,a,b)
begin
case code is
when "000"=>
c <= "0000";
when "001"=>
c <= a+b;
when "010"=>
c <= a-b;
when "011"=>
c <= a and b;
when "101"=>
c <= not a;
when "110"=>
c <= a nand b;
when "111"=>
c <= a or b;
when others=>
c <= "1111";
end case;
end process;
end behavioral;
OUTPUT:
RESULT:
Thus the program for ALU was simulated by using VHDL and verified
successfully.
EXPT NO:11(b)
DATE:19.11.2011
AIM:
To design the program for ALU using verilog
PROGRAM FOR ALU USING VERILOG:
module alu(code,a,b,c);
input[2:0]code;
input[3:0]a,b;
output[3:0]c;
reg[3:0]c;
always@(code,a,b)
case(code)
3'b000: c="0000";
3'b001: c=a+b;
3'b010: c=a-b;
3'b011: c=a/b;
3'b100: c=~(a&b);
3'b101: c=~(a/b);
3'b110: c=a^b;
3'b111: c=~a;
endcase
endmodule
OUTPUT:
RESULT:
Thus the program for ALU was simulated by using Verilog and verified
successfully.