Assignment 1 dsd
Assignment 1 dsd
Assignment
Submitted By
NAME Registration Number
Abdullah Ahsan FA20 - EEE-027 /ATD
DSD
Semester Fall 2023
Supervised by:
Dr. Shahid Nawaz Khan
Part b:
module muxbyif( reg [1:0] sel;
input wire [3:0] I, wire out;
input wire [1:0] S, muxbyif Mu(.I(inp),.S(sel),.Y(out));
output reg Y initial
); begin
always @ (I,S) inp=4'b0101;
if (S==2'b00)
Y=I[0]; sel=2'b00;
else if (S==2'b0) #10 sel=2'b01;
Y=I[1]; #10 sel=2'b10;
else if (S==2'b10) #10 sel=2'b11;
Y=I[2]; #10 $stop;
else if(S==2'b11) end
Y=I[3]; endmodule
endmodule
Testbench
module tb_muxbyif;
reg [3:0] inp;
Result:
Part c.
module mux_4to1 initial
( begin
input wire [1:0] a,b, in1= 4'b0000; in2=4'b0000; selec=1'b1;
input wire sel, #15 in1= 4'b0011; in2=4'b1100; selec=1'b1;
output wire [1:0] f #15 in1= 4'b1010; in2=4'b0101; selec=1'b1;
); #15 in1= 4'b1000; in2=4'b0111; selec=1'b1;
#15 in1= 4'b0110; in2=4'b1001; selec=1'b1;
mux_2to1 #15 in1= 4'b1111; in2=4'b1111; selec=1'b1;
m0(.f(f[0]),.sel(sel),.a(a[0]),.b(b[0])); #15 $stop ;
mux_2to1 end
m1(.f(f[1]),.sel(sel),.a(a[1]),.b(b[1]));
endmodule
module tb_4bmux;
reg [3:0] in1,in2;
reg selec;
wire [3:0] out;
mux_4to1
m1(.a(in1),.b(in2),.sel(selec),.f(out));
Result:
Question 3
The binary-coded-decimal (BCD) format uses 4 bits to represent 10 decimal digits.
For example, (259)10 is represented as "0010 _0101_1001" in BCD format. A
BCD incrementor adds 1 to a number in BCD format. For example, after
incrementing, “0010_0101_100 1 " (i.e., 25910) becomes "0010 _0110 _0000"
(i.e., 26010). (CLO-1)
a. Design a three-digit 12-bit incrementor and derive the code.
b. Derive a testbench and use simulation to verify operation of the code.
Code:
module BCD_incrementor( if (in[11:8] < 4'b1001)
input [11:0] in, out[11:8] = in[11:8] + (in[7:4] == 4'b1001);
output reg [11:0] out); else
always @* out[11:8] = 4'b0000;
begin end
if (in[3:0] < 4'b1001) endmodule
out[3:0] = in[3:0] + 4'b0001;
else
out[3:0] = 4'b0000; module BCD_incrementor_tb;
if (in[7:4] < 4'b1001) reg [11:0] in;
out[7:4] = in[7:4] + (in[3:0] == 4'b1001); wire [11:0] out;
else BCD_incrementor DUT ( .in(in),.out(out));
out[7:4] = 4'b0000; initial begin
#15 in = 12'b001010010001; // Test case 1
#15 $stop in = 12'b001001011001;
Result