Professional Documents
Culture Documents
AIM: Design and simulation of half and full subtractor using various modelling.
TRUTH TABLE:
Inputs Outputs
a b diff bor
0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0
VERILOGCODE:
1)Gate level modelling
module hs(
input a,
input b,
output diff,
output bor
);
xor fordiff(diff,a,b);
and forbor(bor,~a,b);
endmodule
b) data flow level modelling
module hs(
input a,
input b,
output diff,
output bor
);
assign diff=a^b;
assign bor=~a&b;
endmodule
c) behavioral modelling
module hs(
input a,
input b,
output reg diff,
output reg bor
);
always@(a or b)
begin
case({a,b})
2'b00:begin diff=0; bor=0;end
2'b01:begin diff=1; bor=1;end
2'b10:begin diff=1; bor=0;end
2'b11:begin diff=0; bor=0;end
endcase
end
endmodule
// Inputs
reg a;
reg b;
// Outputs
wire diff;
wire bor;
initial begin
// Initialize Inputs
a = 0;
b = 0;
end
endmodule
RTL SCHEMATICS:
1.RTL schematics using gate and data flow modelling.
OUTPUT WAVEFORM:
TRUTH TABLE:
Inputs Output
a b c diff bor
0 0 0 0 0
0 0 1 1 1
0 1 0 1 1
0 1 1 0 1
1 0 0 1 0
1 0 1 0 0
1 1 0 0 1
1 1 1 1 1
endmodule
b)data flow level modelling
module fs(
input a,
input b,
input c, //c is input borrow
output diff,
output bor
);
wire t1,t2,t3;
assign t1=a^b;
assign diff=t1^c;
assign t2=~a&b;
assign t3=~t1&c;
assign bor=t2|t3;
endmodule */
c)behavioral level modelling
module fs(
input a,
input b,
input c, //c is input borrow
output reg diff,
output reg bor
);
always@(a or b or c)
begin
case({a,b,c})
3'b000:begin diff=0; bor=0; end
3'b001:begin diff=1; bor=1; end
3'b010:begin diff=1; bor=1; end
3'b011:begin diff=0; bor=1; end
3'b100:begin diff=1; bor=0; end
3'b101:begin diff=0; bor=0; end
3'b110:begin diff=0; bor=0; end
3'b111:begin diff=1; bor=1; end
endcase
end
endmodule
TESTBENCH CODE:
`timescale 1ps / 1ps
module fs_test;
// Inputs
reg a;
reg b;
reg c;
// Outputs
wire diff;
wire bor;
initial begin
// Initialize Inputs
a = 0;
b = 0;
c = 0;
// Wait 100 ns for global reset to finish
#100;
// Add stimulus here
#5 a = 0;
b = 0;
c = 1;
#5 a = 0;
b = 1;
c = 0;
#5 a = 0;
b = 1;
c = 1;
#5 a = 1;
b = 0;
c = 0;
#5 a = 1;
b = 0;
c = 1;
#5 a = 1;
b = 1;
c = 0;
#5 a = 1;
b = 1;
c = 1;
end
endmodule
RTL SCHEMATICS:
1)RTL schematics using gate and data flow level modelling.
OUTPUT WAVEFORM:
RESULT:
In this experiment half and full subtractor were implemented using various modelling technique.
The simulation were observed using Xilinxs 14.7 and found to correct and in accordance with
design.
\