0% found this document useful (0 votes)
41 views6 pages

Assignment6 Tranngoctu

The document contains two Verilog modules: 1. A 4-to-1 multiplexer module that uses assign statements to select one of 4 input bits (a[3:0]) based on the 2-bit selection input (s[1:0]) and output the result. 2. A 4-bit carry lookahead adder module that uses assign statements and logic operators to calculate the propagate, generate and intermediate carry signals to implement carry lookahead addition of two 4-bit inputs (a, b) and a carry in (cin) and output the 5-bit sum. Testbenches are provided to simulate and verify the functionality of both modules.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views6 pages

Assignment6 Tranngoctu

The document contains two Verilog modules: 1. A 4-to-1 multiplexer module that uses assign statements to select one of 4 input bits (a[3:0]) based on the 2-bit selection input (s[1:0]) and output the result. 2. A 4-bit carry lookahead adder module that uses assign statements and logic operators to calculate the propagate, generate and intermediate carry signals to implement carry lookahead addition of two 4-bit inputs (a, b) and a carry in (cin) and output the 5-bit sum. Testbenches are provided to simulate and verify the functionality of both modules.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Problem 1: 4-to-1 Muxtiplexer using Data Flow

module mux41_rtl(
input [3:0] a,
input [1:0] s,
output o);
assign o = s[1]?(s[0]?a[3]:a[2]):(s[0]?a[1]:a[0]);
endmodule
//Testbench
module mux41_rtl_tb;
reg [3:0] a;
reg [1:0] s;
wire o;
integer i;
mux41_rtl Mux(a,s,o);
initial begin
a<=4'b1010;
for(i=0;i<4;i=i+1) begin
#5;
s<=i;
end
end
initial
$monitor("s=%b output=%b",s,o);
Endmodule

Problem 2:4-bit Carry Lookahead Adder using Data Flow


module carrylook_adder
(input [3:0] a,b,
input cin,
output [4:0] sum);
wire [3:0] p; // Carry Propagate
wire [3:0] g; //Carry Generate
wire [4:0] c; // Intermediate Carry

assign p[3:0] = a[3:0] ^ b[3:0];


assign g[3:0] = a[3:0] & b[3:0];

assign c[0] = cin;

assign c[1] = g[0] | (p[0] & c[0]);

assign c[2] = g[1] | (p[1] & g[0]) | (p[1] & p[0] & c[0]);

assign c[3] = g[2] | (p[2] & g[1]) | (p[2] & p[1] & g[0])
| (p[2] & p[1] & p[0] & cin);

assign c[4] = g[3] | (p[3] & g[2]) | (p[3] & p[2] & g[1])
| (p[3] & p[2] & p[1] & g[0])
| (p[3] & p[2] & p[1] & p[0] & cin);
assign sum[4:0] = {1'b0, p[3:0]} ^ c[4:0];
endmodule
//Testench
module carrylook_adder_tb;
reg [3:0] a,b;
reg cin;
wire [4:0] sum;
carrylook_adder CLA(a,b,cin,sum);
initial begin
a<=4'b1010;
b<=4'b1101;
cin<=0;
#10;
a<=4'b1111;
b<=4'b1000;
cin<=1;
end
initial
$monitor("Output=%b",sum);
endmodule

Problem 3:
1.Describe the statement assign: The assignment syntax starts with the keyword assign followed by the
signal name which can be either a single signal or a concatenation of different signal nets. The drive
strength and delay are optional and are mostly used for dataflow modeling than synthesizing into real
hardware.
The expression of signal on the right hand side is evaluated and assigned to the net or expression of nets
on the left hand side.
Expression: assign <net_expression> = [drive_strength] [delay] <expression of different signals or
constant value>
*Verilog Arithmetic Opertators

Operator Description

a+b a plus b

a -b a minus b

a*b a multiplied by b

a/b a divided by b

a%b a modulo b
a ** b a to the power of b

*Verilog Relational Operators

Operator Description

a<b a less than b

a>b a greater than b

a <= b a less than or equal to b

a >= b a greater than or equal to b

*Verilog Equality Operators

Operator Description

a === b a equal to b, including x and z

a !== b a not equal to b, including x and z

a == b a equal to b, result can be unknown

a != b a not equal to b, result can be unknown

*Verilog Logical Operators

Operator Description
a && b evaluates to true if a and b are true

a || b evaluates to true if a or b are true

!a Converts non-zero value to zero, and vice versa

*Verilog Bitwise Operators

& 0 1 x z

0 0 0 0 0

1 0 1 x x

x 0 x x x

z 0 x x x

| 0 1 x z

0 0 1 x x

1 1 1 1 1

x x 1 x x

z x 1 x x

*Verilog Shift Operator


There are two kinds of shift operators
• Logical shift operator: << and >>
• Arithmetic shift operator : <<< and >>>

You might also like