Introduction To Verilog Lab-2
Introduction To Verilog Lab-2
Lab-2
1. Write a Verilog code to implement A + B. Assume that A and B are 4 Bit
Binary numbers. There are two outputs, SUM of 4 bits and OVERFLOW
of 1 bit. The overflow bit denotes the cases when the sum is greater
than 15.
input [3:0] a;
input [3:0] b;
output [3:0] sum;
output reg overflow;
wire [4:0] tempadd;
module two_com(
input [3:0] a,
output [3:0] out
);
assign out = ~b + 1;
endmodule
3. Write a Verilog code to implement A – B. Assume that A and B are 4 Bit
Binary numbers given as inputs and A > B. You cannot directly use
subtraction in the code. Compute the substation using 2’s complement
representation.
module two_compadder(
input [3:0] a,
input [3:0] b,
output [3:0] out
);