DSD Verilog Observation
DSD Verilog Observation
NAME : Sheshadri D B
USN : 24TMPLEL05
1) Write Verilog code for the design of 8-bit Carry Ripple Adder
module ripple_carry_adder(
input [7:0] a, b,
input cin,
output [7:0] sum,
output cout
);
wire [7:0] c;
endmodule
module full_adder(
input a, b, cin,
output sum, cout
);
assign sum = a ^ b ^ cin;
assign cout = (a & b) | (b & cin) | (a & cin);
endmodule
`timescale 1ns / 1ps
module ripple_carry_adder_tb;
reg [7:0] a, b;
reg cin;
wire [7:0] sum;
wire cout;
ripple_carry_adder uut (
.a(a), .b(b), .cin(cin),
.sum(sum), .cout(cout)
);
initial begin
$dumpfile("ripple_carry_adder.vcd");
$dumpvars(0, ripple_carry_adder_tb);
$finish;
end
endmodule
Waveform :
2) Write a Verilog code for the design of 8 bit Booth’s Multiplier
module booth_multi(p, a, b, clk);
input clk;
input signed [7:0] a, b;
output reg signed [15:0] p;
reg signed [15:0] ans;
integer i;
integer operate;
initial begin
clk = 0;
end
always begin
#10 clk = ~clk;
end
initial begin
#100 $stop;
end
endmodule
Waveform
3) Write Verilog code for the design of 8-bit Carry look ahead Adder
module carry_lookahead_adder(
input [7:0] A, B,
input Cin,
output [7:0] Sum,
output Cout
);
wire [7:0] G, P, C;
assign G = A & B;
assign P = A ^ B;
assign C[0] = Cin;
assign Cout = G[7] | (P[7] & G[6]) | (P[6] & P[7] & G[5]) | (P[7] & P[5] & P[6] & G[4])
| (P[4] & P[5] & P[6] & P[7] & G[3]) | (P[7] & P[6] & P[4] & P[3] & G[5])
| (P[7] & P[6] & P[5] & P[4] & P[3] & P[2] & G[1])
| (P[7] & P[6] & P[5] & P[4] & P[3] & P[2] & P[1] & G[0])
| (P[7] & P[6] & P[5] & P[4] & P[3] & P[2] & P[1] & P[0] & G[0]);
assign Sum = P ^ C;
endmodule
//Testbench code
module carry_lookahead_adder_tb;
reg [7:0] A, B;
reg Cin;
wire [7:0] Sum;
wire Cout;
carry_lookahead uut (
.A(A), .B(B), .Cin(Cin),
.Sum(Sum), .Cout(Cout)
);
initial begin
initial begin
$monitor("Time = %0t | A = %b | B = %b | Cin = %b | Sum = %b | Cout = %b",
$time, A, B, Cin, Sum, Cout);
end
endmodule
Waveform
4) Write Verilog code to design a 8 bit Magnitude comparator
module compar_8bit (A, B, clk, a_eq_b, a_less_b, a_grt_b);
parameter N = 8;
input clk;
input [N-1:0] A;
input [N-1:0] B;
output reg a_eq_b;
output reg a_less_b;
output reg a_grt_b;
//Testbench code
module compr_tb;
// Inputs
reg [7:0] A;
reg [7:0] B;
reg clk;
// Outputs
wire a_eq_b;
wire a_less_b;
wire a_grt_b;
always begin
#5 clk = ~clk; // Generate clock signal
end
initial begin
#100 $stop; // Stop simulation after all test cases
end
endmodule
Waveform
5) Write a Verilog code to design a 4bit Universal shift register
module universal_shift_reg(
input clk, rst_n,
input [1:0] select, // select operation
input [3:0] p_din, // parallel data in
input s_left_din, // serial left data in
input s_right_din, // serial right data in
output reg [3:0] p_dout, //parallel data out
output s_left_dout, // serial left data out
output s_right_dout // serial right data out
);
always@(posedge clk) begin
if(!rst_n) p_dout <= 0;
else begin
case(select)
2'h1: p_dout <= {s_right_din,p_dout[3:1]}; // Right Shift
2'h2: p_dout <= {p_dout[2:0],s_left_din}; // Left Shift
2'h3: p_dout <= p_din; // Parallel in - Parallel out
default: p_dout <= p_dout; // Do nothing
endcase
end
end
assign s_left_dout = p_dout[0];
assign s_right_dout = p_dout[3];
endmodule
//Testbench code
module TB;
reg clk, rst_n;
reg [1:0] select;
reg [3:0] p_din;
reg s_left_din, s_right_din;
wire [3:0] p_dout; //parallel data out
wire s_left_dout, s_right_dout;
p_din = 4'b1101;
s_left_din = 1'b1;
s_right_din = 1'b0;
$finish;
end
// To enable waveform
initial begin
$dumpfile("dump.vcd"); $dumpvars;
end
endmodule
Waveform
6) Write a Verilog code to design a 8bit parity generator
module parity_gen_8bit(
input [7:0] parity_in,
output parity_even,
output parity_odd
);
endmodule
//Testbench code
module parity_gen_8bit_tb;
// Inputs
reg [7:0] parity_in;
// Outputs
wire parity_even;
wire parity_odd;
initial begin
// Display the values
$monitor("Time=%0t | Input=%b | Even Parity=%b | Odd Parity=%b",
$time, parity_in, parity_even, parity_odd);
// Initialize Inputs
parity_in = 8'b00000000; #100;
parity_in = 8'b01100001; #100;
parity_in = 8'b01100011; #100;
parity_in = 8'b10110101; #100;
parity_in = 8'b00000001; #100;
parity_in = 8'b01111111; #100;
parity_in = 8'b11111111; #100;
// Finish simulation
$finish;
end
endmodule
Waveform
7) Design and develop a Verilog model for an accumulator that calculates
the sum of a sequence of fixed-point numbers. Each input number is signed
with 6 pre-binary-point and 12 post-binary-point bits. The accumulated sum
has 8 pre-binary-point and 12 post-binary-point bits. A new number arrives
at the input during a clock cycle when data_en control input is ‘1’. The
accumulated sum is cleared to ‘0’ when the rest counter 1 input is ‘1’. Both
control inputs are synchronous.
8) Design and develop a Verilog code for a dual port, 4k x 32-bit flow through
SSRAM (Synchronous Static Random-Access Memory), and one port allows
data to be written & read, while the other port allows only data to be read.