Assign 5
Assign 5
1.FACTORIAL
PROGRAM:
module Factorial4bitin_32bitout(
input [3:0] num,
output reg [31:0] result
);
always @(*) begin
case (num)
4'd0: result = 32'd1;
4'd1: result = 32'd1;
4'd2: result = 32'd2;
4'd3: result = 32'd6;
4'd4: result = 32'd24;
4'd5: result = 32'd120;
4'd6: result = 32'd720;
4'd7: result = 32'd5040;
4'd8: result = 32'd40320;
4'd9: result = 32'd362880;
4'd10: result = 32'd3628800;
4'd11: result = 32'd39916800;
4'd12: result = 32'd479001600;
4'd13: result = 32'd6227020800;
4'd14: result = 32'd87178291200;
4'd15: result = 32'd1307674368000;
default: result = 32'd0;
endcase
end
endmodule
RTL SCHEMATIC:
TEST BENCH
initial begin
$display("num\tfactorial");
num = 0; #10 $display("%d\t%d", num, result);
num = 1; #10 $display("%d\t%d", num, result);
num = 2; #10 $display("%d\t%d", num, result);
num = 3; #10 $display("%d\t%d", num, result);
num = 4; #10 $display("%d\t%d", num, result);
num = 5; #10 $display("%d\t%d", num, result);
num = 6; #10 $display("%d\t%d", num, result);
num = 7; #10 $display("%d\t%d", num, result);
num = 8; #10 $display("%d\t%d", num, result);
num = 9; #10 $display("%d\t%d", num, result);
num = 10;#10 $display("%d\t%d", num, result);
$finish;
end
endmodule
TIMING DIAGRAM:
2.8 Bit ALU
PROGRAM:
module ALU8bit(
input [3:0] a, b,
input [2:0] sel,
output reg [4:0] out
);
initial begin
$display("sel\ta\tb\tout");
a = 4'd10; b = 4'd2;
$finish;
end
end module
RTL SCHEMATIC:
TIMING DIAGRAM:
3. EvenParity-16BitNumber
PROGRAM:
module EvenParity_16bit(
input clk,
input start,
input [15:0] data,
output reg parity
);
task compute_parity;
input [15:0] in_data;
output reg result;
integer i;
begin
result = 0;
for (i = 0; i < 16; i = i + 1) begin
result = result ^ in_data[i];
end
result = ~result;
end
endtask
RTL SCHEMATIC:
TEST BENCH:
// Clock generation
initial begin
clk = 0;
start = 0;
data = 16'b0;
#10;
start = 1; #10;
start = 0;
#40; // Wait for 3 posedges
start = 1; #10;
start = 0;
#40;
$finish;
end
endmodule
TIMING DIAGRAM:
4.XOR_Using Cmos
PROGRAM:
(i)
module XOR_Gate(
output Y,
input A, B
);
wire notA, notB;
wire n1, n2;
not (notA, A);
not (notB, B);
cmos #(4) (n1, A, notB, B);
cmos #(4) (n2, notA, B, notB);
or (Y, n1, n2);
endmodule
(ii)
module switch_delays;
$finish;
end
initial begin
$monitor("time=%0t | data=%b ctrl=%b | pmos=%b nmos=%b cmos=%b tranif1=%b tranif0=%b",
$time, data, ctrl, out_pmos, out_nmos, out_cmos, out_tranif1, out_tranif0);
end
endmodule
CMOS DESIGN:
TEST BENCH
module tb_switch_delays;
wire out_pmos, out_nmos, out_cmos, out_tranif1, out_tranif0;
reg data, ctrl;
switch_delays uut (
.out_pmos(out_pmos),
.out_nmos(out_nmos),
.out_cmos(out_cmos),
.out_tranif1(out_tranif1),
.out_tranif0(out_tranif0),
.data(data),
.ctrl(ctrl)
);
initial begin
$display("time=%0t | data=%b ctrl=%b | pmos=%b nmos=%b cmos=%b tranif1=%b tranif0=%b",
$time, data, ctrl, out_pmos, out_nmos, out_cmos, out_tranif1, out_tranif0);
data = 0; ctrl = 0; #10;
data = 1; ctrl = 1; #10;
data = 0; ctrl = 1; #10;
data = 1; ctrl = 0; #10;
$finish;
end
endmodule
TIMING DIAGRAM: