In: Electrical Engineering
Using full adders and some other gates, design subtractor that subtracts an 8-bit binary number [Y7 …. Y0] from 8-bit binary number [X7 … X0]. Write necessary equations. Draw detailed circuit diagram and explain steps & write verilog code
the blocks here are full adders:
verilog code for 8-bit adder subtractor:
hierarchical
Half adder
then using HA to make full adder
module HA(a,b,s,cout);
input a,b;
output s,cout;
assign s=a^b;
assign cout=a & b;
endmodule
module FA(a,b,cin,s,cout);
input a,b,cin;
output s,cout;
wire s1,c1,c2;
HA h1(a,b,s1,c1);
HA h2(cin,s1,s,c2);
or rrr1(cout,c1,c2);
endmodule
module four_bit_adder(a,b,cin,s,cout);
input [3:0] a,b;
input cin;
output [3:0] s;
output cout;
wire c0,c1,c2;
FA f0(a[0],b[0],cin,s[0],c0);
FA f1(a[1],b[1],c0,s[1],c1);
FA f2(a[2],b[2],c1,s[2],c2);
FA f3(a[3],b[3],c2,s[3],cout);
endmodule
module four_bit_add_Sub(a,b,M,sum_diff,carry);
input [7:0] a,b;
input M;
output [7:0] sum_diff;
output carry;
wire [7:0] b_out;
wire c1;
xor x1(b_out[0],b[0],M);
xor x2(b_out[1],b[1],M);
xor x3(b_out[2],b[2],M);
xor x4(b_out[3],b[3],M);
xor x5(b_out[4],b[4],M);
xor x6(b_out[5],b[5],M);
xor x7(b_out[6],b[6],M);
xor x8(b_out[7],b[7],M);
four_bit_adder f111(a[3:0],b_out[3:0],M,sum_diff[3:0],c1);
four_bit_adder f121(a[7:4],b_out[7:4],M,sum_diff[7:4],carry);
endmodule