Professional Documents
Culture Documents
Code-
module a l l g a t e ( a , b , c , d , e , f , g , h , i ) ;
inputa,b;outputc,d,
e,f,g,h,i;
and a1 ( c , a , b ) ;
or a2 ( d , a , b ) ; n
o t a3 ( e , a ) ;
nand a4 ( f , a , b ) ;
nor a5 ( g , a , b ) ;
xor a6 ( h , a , b ) ;
xnor a7 ( i , a , b ) ;
endmodule
Department of Electrical Engineering Spring Semester 2024 2
Circuit
2) Q-2.- Design a half adder and verify the performance through verilog code Code-
module Q u e s t i o n 2 ( a , b , s , c ) ; i
n p u t a , b ; o u t p u t s , c ; xor x1 ( s ,
a , b ) ; and a1 ( c , a , b ) ; endmodule
Department of Electrical Engineering Spring Semester 2024 3
Department of Electrical Engineering Spring Semester 2024 4
Department of Electrical Engineering Spring Semester 2024 5
Zedboard
Department of Electrical Engineering Spring Semester 2024 6
3) Question 3- Design a 1-bit full adder and verify the performance through verilog code Code:-
module Q u e s t i o n 3 ( a , b , c in , s , c o u t ) ;
inputa,b,cin;
outputs,cout;
w i r e l , m, n ;
and a1 ( l , a , b ) ; and
a2 (m, b , c i n ) ; and
a3 ( n , c in , a ) ;
or o1 ( cout , l , m, n ) ;
xor x1 ( s , a , b , c i n ) ;
endmodule
Department of Electrical Engineering Spring Semester 2024 7
Department of Electrical Engineering Spring Semester 2024 8
Constraints
Department of Electrical Engineering Spring Semester 2024 9
Circuit
4) Question-4 Develop a 1-bit full adder verilog module using the half adder verilog modules
Code-
module ha ( a , b , s , c ) ; i
nputa,b;outputs,c
; xor x1 ( s , a , b ) ; and a1
( c , a , b ) ; endmodule
module f a h a ( a , b , c in , s , c o u t ) ; i n
puta,b,cin;outputs,cout;wire
s1 , c1 , c2 ;
ha ha1 ( . a ( a ) , . b ( b ) , . s ( s 1 ) , . c ( c1 ) ) ;
ha ha2 ( . a ( s 1 ) , . b ( c i n ) , . s ( s ) , . c ( c2 ) ) ;
or o1 ( c out , c1 , c2 ) ; endmodule
Department of Electrical Engineering Spring Semester 2024 10
Zedboard
Department of Electrical Engineering Spring Semester 2024 11
Department of Electrical Engineering Spring Semester 2024 12
Zedboard
Department of Electrical Engineering Spring Semester 2024 13
Department of Electrical Engineering Spring Semester 2024 14
5) Question5- Design and develop a 16-bit ripple carry adder verilog module using the 4-bit full
adder modules from .
Code-
module F u l l A d d e r (
inputa,in
putb,inpu
t c in , o u t p u
t sum ,
outputcout
);
a s s i g n sum = a ˆ b ˆ c i n ;
a s s i g n c o u t = ( a & b ) | ( b & c i n ) | ( a & c i n ) ; endmodule
module R i p p l e C a r r y A d d e r 1 6 b i t ( i n
p u t [ 1 5 : 0 ] A, i n p u t [ 1 5 : 0 ] B , o u t
p u t [ 1 5 : 0 ] sum
Department of Electrical Engineering Spring Semester 2024 15
Constraints
);
wire[15:0]carry;
F u l l A d d e r FA0 (
. a (A[ 0 ] ) ,
.b(B[0]),
. c i n ( 1 ’ b0 ) ,
. sum ( sum [ 0 ] ) ,
.cout(carry[0])
);
genvari;
generate
for(i=1;i < 16;i= i+1)begin:genf ull addersFullA
d d e r FA(
. a (A[ i ] ) ,
. b ( B[ i ] ) ,
Department of Electrical Engineering Spring Semester 2024 16
.cin(carry[i−1]),
Circuit
. sum ( sum [ i ] ) ,
.cout(carry[i])
);
end
e n d g e n e r a t e endmodule
Testbench Code-
module Q u e s t i o n 5 t e s t b e n c h ;
reg[3:0]a,b;
wire[3:0]s;
wirecout;
Question5uut(.a(a),.b(b),.s(s),.cout(cout));in
itialbegin
$ m o n i t o r ( $time , ” a=%b , b=%b , s=%b , c o u t=%b ” , a , b , s , c o u t ) ;
Department of Electrical Engineering Spring Semester 2024 17
#5 a =4 ’ b0000 ; b =4 ’ b0000 ;
#5 a =4 ’ b0001 ; b =4 ’ b0001 ;
#5 a =4 ’ b0010 ; b =4 ’ b0010 ;
#5 a =4 ’ b0011 ; b =4 ’ b0011 ;
#5 a =4 ’ b1000 ; b =4 ’ b1000 ;
#5 $ f i n i s h ; end
Department of Electrical Engineering Spring Semester 2024 18
Department of Electrical Engineering Spring Semester 2024 19
Zedboard
Department of Electrical Engineering Spring Semester 2024 20
Output
endmodule
6) Question-6 Design a 4-bit prime number detector and write a verilog structural module and
verify it using zedboard
Code-
module p r i m e n u m b e r d e t e c t o r ( a , o u t ) ;
input[3:0]a;o
utputout;wir
e l , m, n ; w i r e p ,
q,r,s;
n o t n1 ( l , a [ 3 ] ) ; n
o t n2 (m, a [ 2 ] ) ; n o
t n3 ( n , a [ 1 ] ) ;
and a1 ( p , l , a [ 0 ] ) ; and a2 (
q , l , m, a [ 1 ] ) ; and a3 ( r , m,
a [ 1 ] , a [ 0 ] ) ; and a4 ( s , n ,
a[1],a[0]);
Department of Electrical Engineering Spring Semester 2024 21
or o1 ( out , p , q , r , s ) ;
endmodule
Constraints
]
Department of Electrical Engineering Spring Semester 2024 22
Circuit
Fig. 15. Circuit Diagram of 1-bit Full Adder using the half adder
7) Question7-Design and verify the 4 × 1 multiplexer function through verilog structural module
and verify it through zedboard.
Code-
module Q u e s t i o n 7 ( y , i , s ) ; i
nput[0:3]i;input[0:1]s;
outputy;
w i r e l , m, p , q , r , t ;
n o t g1 ( l , s [ 1 ] ) ; n o
t g2 (m, s [ 0 ] ) ;
and a1 ( p , s [ 1 ] , s [ 2 ] , i [ 3 ] ) ;
and a2 ( q , l , s [ 0 ] , i [ 2 ] ) ; and a3
( r , m, s [ 0 ] , i [ 1 ] ) ; and a4 ( t , l ,
m, i [ 0 ] ) ;
or o1 ( y , p , q , r , t ) ;
endmodule
Department of Electrical Engineering Spring Semester 2024 23
Zedboard
Department of Electrical Engineering Spring Semester 2024 24
Department of Electrical Engineering Spring Semester 2024 25
Zedboard
Department of Electrical Engineering Spring Semester 2024 26
Department of Electrical Engineering Spring Semester 2024 27
Output
8) Question8- Design a 3 × 8 line decoder and verify the performance through zedboard..
Code
module t h r e e t o e i g h t d e c o d e r ( i n p
utx,y,z,
output [0:7]d
) ; and a1 ( d [ 0 ] , ˜ x , ˜ y , ˜ z
) ; and a2 ( d [ 1 ] , ˜ x , ˜ y , z )
; and a3 ( d [ 2 ] , ˜ x , y , ˜ z ) ;
and a4 ( d [ 3 ] , ˜ x , y , z ) ;
and a5 ( d [ 4 ] , x , ˜ y , ˜ z ) ;
and a6 ( d [ 5 ] , x , ˜ y , ˜ z ) ;
and a7 ( d [ 6 ] , x , y , ˜ z ) ;
and a8 ( d [ 7 ] , x , y , z ) ; endmodule
Department of Electrical Engineering Spring Semester 2024 28
Constraints
Code-
module f u l l s u b t r a c t o r ( a , b , c , d , b out ) ;
inputa,b,c;ou
t p u t d , b out ; w i
r e c1 , c2 , c3 ;
h a l f s u b t r a c t o r hs 1 ( . a ( a ) , . b (
b ) , . d ( c1 ) , . b out ( c2 ) ) ; h a l f s u b t r a
c t o r hs 2 ( . a ( c1 ) , . b ( c ) , . d ( d ) , . b out
( c3 ) ) ;
or o1 ( b out , c3 , c2 ) ;
endmodule
module h a l f s u b t r a c t o r ( a , b , d , b out ) ;
i n p u t a , b ; o u t p u t d , b out ; xor x1
(d,a,b);
Department of Electrical Engineering Spring Semester 2024 29
and a1 ( b out , ˜ a , b ) ; endmodule
Testbencg Code-
module f u l l subtractor tb;
Circuit Diagram
rega,b,c;
w i r e d , b out ;
f u l l s u b t r a c t o r u u t ( . a ( a ) , . b ( b ) , . c ( c ) , . d ( d ) , . b out ( b out ) ) ;
initialbegin
$ m o n i t o r ( $time , ” a=%b , b=%b , c=%b , d=%b , b out=%b ” , a , b , c , d , b out ) ;
#5 a =1 ’ b0 ; b =1 ’ b0 ; c =1 ’ b0 ;
#5 a =1 ’ b0 ; b =1 ’ b0 ; c =1 ’ b1 ;
#5 a =1 ’ b0 ; b =1 ’ b1 ; c =1 ’ b0 ;
#5 a =1 ’ b0 ; b =1 ’ b1 ; c =1 ’ b1 ;
#5 a =1 ’ b1 ; b =1 ’ b0 ; c =1 ’ b0 ;
#5 a =1 ’ b1 ; b =1 ’ b0 ; c =1 ’ b1 ;
#5 a =1 ’ b1 ; b =1 ’ b1 ; c =1 ’ b0 ;
#5 a =1 ’ b1 ; b =1 ’ b1 ; c =1 ’ b1 ;
#5 $ f i n i s h ;
Department of Electrical Engineering Spring Semester 2024 30
end endmodule
Circuit
Diagram
Department of Electrical Engineering Spring Semester 2024 31
10) Q-10 Design a seven segment display and verify the performance through the verilog code with
case statements
Code:-
a lways @( * ) b e g i n c a
s e ( number )
4 ’ b0000 : segments = 7 ’ b1000000 ; // 0
4 ’ b0001 : segments = 7 ’ b1111001 ; // 1
4 ’ b0010 : segments = 7 ’ b0100100 ; // 2
4 ’ b0011 : segments = 7 ’ b0110000 ; // 3
4 ’ b0100 : segments = 7 ’ b0011001 ; // 4
4 ’ b0101 : segments = 7 ’ b0010010 ; // 5
4 ’ b0110 : segments = 7 ’ b0000010 ; // 6
4 ’ b0111 : segments = 7 ’ b1111000 ; // 7
4 ’ b1000 : segments = 7 ’ b0000000 ; // 8
Department of Electrical Engineering Spring Semester 2024 32
Department of Electrical Engineering Spring Semester 2024 33
Zedboard
Department of Electrical Engineering Spring Semester 2024 34
Department of Electrical Engineering Spring Semester 2024 35
Zedboard
Department of Electrical Engineering Spring Semester 2024 36
Department of Electrical Engineering Spring Semester 2024 37
Output
endmodule
Department of Electrical Engineering Spring Semester 2024 38
Constraints
Zedboard
Department of Electrical Engineering Spring Semester 2024 41
Department of Electrical Engineering Spring Semester 2024 42
Zedboard
Department of Electrical Engineering Spring Semester 2024 43
Output
Circuit Diagram
Output
Circuit Diagram
Department of Electrical Engineering Spring Semester 2024 49
Fig. 33. Circuit Diagram of 3 to 8 line decoder
Constraints
Output
Output
Constraints
Department of Electrical Engineering Spring Semester 2024 61