Half Subtractor and Full Subtractor :
reg [1:0]d1;
reg [1:0]s1;
endmodule
(a) Dataflow modelling
`timescale 1ns / 1ps
module half_subtractor_dataflow(a,b,d,bo);
input a,b;
module half_subtractor_dataflow(a,b,d,bo);
input a,b;
output d,bo;
assign d=a^(~b);
assign bo=(a&(~b));
assign d=a^(~b);
assign bo=(a&(~b));
endmodule
(b) Behavioral Modeling
`timescale 1ns / 1ps
module half_subtractor_behav(a,b,d,bo);
input a,b;
module half_subtractor_behav(a,b,d,bo);
input a,b;
output reg d,bo;
reg [1:0]d1;
reg [1:0]s1;
always@*
begin
d1[0]<=b;
d1[1]<=a;
begin
d1[0]<=b;
d1[1]<=a;
case(d1)
2'b00: s1<=2'b00;
2'b01: s1<=2'b11;
2'b10: s1<=2'b10;
2'b00: s1<=2'b00;
2'b01: s1<=2'b11;
2'b10: s1<=2'b10;
2'b11: s1<=2'b00;
default: s1<=2'b00;
endcase
default: s1<=2'b00;
endcase
d<=s1[1];
bo<=s1[0];
end
endmodule
bo<=s1[0];
end
endmodule
(c) Structural Modeling
`timescale 1ns / 1ps
module half_subtractor_struct(a,b,d,bo);
input a,b;
output d,bo;
module half_subtractor_struct(a,b,d,bo);
input a,b;
output d,bo;
xor21 u1(a,b,d);
not1 u2(b,b1);
and21 u3(a,b1,bo);
endmodule
not1 u2(b,b1);
and21 u3(a,b1,bo);
endmodule
module not1(a,y);
input a;
input a;
output y;
assign y=~a;
endmodule
assign y=~a;
endmodule
module and21(a,b,y);
input a,b;
output y;
input a,b;
output y;
assign y=a&b;
endmodule
endmodule
module xor21(a,b,y);
input a,b;
output y;
assign y=a^b;
endmodule
output y;
assign y=a^b;
endmodule
(ii) Full Subtractor (Structural Modeling)
`timescale 1ns / 1ps
module full_subtractor_struct(a,b,bin,d,bo);
input a,b,bin;
output d,bo;
module full_subtractor_struct(a,b,bin,d,bo);
input a,b,bin;
output d,bo;
wire c1,c2,c3;
half_subtractor_behav u1(a,b,c1,c2);
half_subtractor_behav u2(c1,bin,d,c3);
half_subtractor_behav u1(a,b,c1,c2);
half_subtractor_behav u2(c1,bin,d,c3);
or21 u3(c2,c3,bo);
endmodule
module or21(a,b,y);
input a,b;
output y;
assign y=a|b;
input a,b;
output y;
assign y=a|b;
endmodule
Comments
Post a Comment