Here\'s my code so far, I can\'t get proper values for Cout, R,r, Q. module FS(a
ID: 3879414 • Letter: H
Question
Here's my code so far, I can't get proper values for Cout, R,r, Q.
module FS(a,b,Cin,d,Cout);
input a,b,Cin;
output d,Cout;
wire z1,z2,z3;
xor(z1,a,b);
xor(d,z1,Cin);
and(z2,~a,b);
and(z3,~z1,Bin);
or(Cout,z2,z3);
endmodule
module Mux(w0,w1,s,f);
input w0,w1;
input [1:0] s;
output f;
wire f;
not(s[1],s[0]);
and(U1,s[1],w0);
and(U2,s[0],w1);
or(f,U1,U2);
endmodule
module SM(x,y,Cin,d,Cout,r,R,Q);
input [3:0]x,y;
input Cin;
output [12:0] d;
output [3:0]Cout;
output wire [8:0] r;
output wire [0:3] R;
output wire [0:3] Q;
wire [3:0] nowhere;
//FS(a,b,Cin,d,Cout)
//FS(x,y,Cin,d,Cout)
FS FS1(.a(x[3]),.b(y[0]),.Cin(Cin),.d(d[0]),.Cout(Cout[0]));
FS FS2(.a(1'b0),.b(y[1]),.Cin(Cin),.d(d[1]),.Cout(Cout[0]));
FS FS3(.a(1'b0),.b(y[2]),.Cin(Cin),.d(d[2]),.Cout(Cout[0]));
FS FS4(.a(1'b0),.b(y[3]),.Cin(Cin),.d(nowhere[0]),.Cout(Cout[0]));
//Mux(w0,w1,s,f)
Mux a0(.w0(d[0]),.w1(x[3]),.s(Cout[0]),.f(r[0]));
Mux a1(.w0(d[1]),.w1(1'b0),.s(Cout[0]),.f(r[1]));
Mux a2(.w0(d[2]),.w1(1'b0),.s(Cout[0]),.f(r[2])); // don't use r[2] skip one
// First Row Done
FS FS5(.a(x[2]),.b(y[0]),.Cin(Cin),.d(d[3]),.Cout(Cout[1]));
FS FS6(.a(r[0]),.b(y[1]),.Cin(Cin),.d(d[4]),.Cout(Cout[1]));
FS FS7(.a(r[1]),.b(y[2]),.Cin(Cin),.d(d[5]),.Cout(Cout[1]));
FS FS8(.a(r[2]),.b(y[3]),.Cin(Cin),.d(nowhere[1]),.Cout(Cout[1]));
Mux a3(.w0(d[3]),.w1(x[2]),.s(Cout[1]),.f(r[3]));
Mux a4(.w0(d[4]),.w1(r[0]),.s(Cout[1]),.f(r[4]));
Mux a5(.w0(d[5]),.w1(r[1]),.s(Cout[1]),.f(r[5])); //don't use r[5], skip one
// Row 2 is done
FS FS9(.a(x[1]),.b(y[0]),.Cin(Cin),.d(d[6]),.Cout(Cout[2]));
FS FS10(.a(r[3]),.b(y[1]),.Cin(Cin),.d(d[7]),.Cout(Cout[2]));
FS FS11(.a(r[4]),.b(y[2]),.Cin(Cin),.d(d[8]),.Cout(Cout[2]));
FS FS12(.a(r[5]),.b(y[3]),.Cin(Cin),.d(nowhere[2]),.Cout(Cout[2]));
Mux a6(.w0(d[6]),.w1(x[1]),.s(Cout[2]),.f(r[6]));
Mux a7(.w0(d[7]),.w1(r[3]),.s(Cout[2]),.f(r[7]));
Mux a8(.w0(d[8]),.w1(r[4]),.s(Cout[2]),.f(r[8]));
//Row 3 is Done
FS FS13(.a(x[0]),.b(y[0]),.Cin(Cin),.d(d[9]),.Cout(Cout[3]));
FS FS14(.a(r[6]),.b(y[1]),.Cin(Cin),.d(d[10]),.Cout(Cout[3]));
FS FS15(.a(r[7]),.b(y[2]),.Cin(Cin),.d(d[11]),.Cout(Cout[3]));
FS FS16(.a(r[8]),.b(y[3]),.Cin(Cin),.d(d[12]),.Cout(Cout[3]));
Mux a9(.w0(d[9]),.w1(x[0]),.s(Cout[3]),.f(R[0]));
Mux a10(.w0(d[10]),.w1(r[6]),.s(Cout[3]),.f(R[1]));
Mux a11(.w0(d[11]),.w1(r[7]),.s(Cout[3]),.f(R[2]));
Mux a12(.w0(d[12]),.w1(r[8]),.s(Cout[3]),.f(R[3]));
//Row 4 is Done
not(Q[0],Cout[0]);
not(Q[1],Cout[1]);
not(Q[2],Cout[2]);
not(Q[3],Cout[3]);
endmodule
module Divider();
reg [3:0] x,y;
reg Cin;
wire [3:0] Cout;
wire [12:0] r;
wire [3:0] R,Q;
SM uut(x,y,Cin,d,Cout,r,R,Q);
initial
begin
x=10;y=0;Cin=0;
#1 x=12;y=3;
#1 x=10;y=10;
#1 x=4;y=12;
#1 x=15;y=6;
end
endmodule
Thanks for any help.
FS FS FS FS FS FS 0Explanation / Answer
the code has fixed and modified
module FS(a,b,Cin,d,Cout);
input a,b,Cin;
output d,Cout;
wire z1,z2,z3;
xor(z1,a,b);
xor(d,z1,Cin);
and(z2,~a,b);
and(z3,~z1,Bin);
or(Cout,z2,z3);
endmodule
module Mux(w0,w1,s,f);
input w0,w1;
input [1:0] s;
output f;
wire f;
not(s[1],s[0]);
and(U1,s[1],w0);
and(U2,s[0],w1);
or(f,U1,U2);
endmodule
module SM(x,y,Cin,d,Cout,r,R,Q);
input [3:0]x,y;
input Cin;
output [12:0] d;
output [3:0]Cout;
output wire [8:0] r;
output wire [0:3] R;
output wire [0:3] Q;
wire [3:0] nowhere;
//FS(a,b,Cin,d,Cout)
//FS(x,y,Cin,d,Cout)
FS FS1(.a(x[3]),.b(y[0]),.Cin(Cin),.d(d[0]),.Cout(Cout[0]));
FS FS2(.a(1'b0),.b(y[1]),.Cin(Cin),.d(d[1]),.Cout(Cout[0]));
FS FS3(.a(1'b0),.b(y[2]),.Cin(Cin),.d(d[2]),.Cout(Cout[0]));
FS FS4(.a(1'b0),.b(y[3]),.Cin(Cin),.d(nowhere[0]),.Cout(Cout[0]));
//Mux(w0,w1,s,f)
Mux a0(.w0(d[0]),.w1(x[3]),.s(Cout[0]),.f(r[0]));
Mux a1(.w0(d[1]),.w1(1'b0),.s(Cout[0]),.f(r[1]));
Mux a2(.w0(d[2]),.w1(1'b0),.s(Cout[0]),.f(r[2])); // don't use r[2] skip one
// First Row Done
FS FS5(.a(x[2]),.b(y[0]),.Cin(Cin),.d(d[3]),.Cout(Cout[1]));
FS FS6(.a(r[0]),.b(y[1]),.Cin(Cin),.d(d[4]),.Cout(Cout[1]));
FS FS7(.a(r[1]),.b(y[2]),.Cin(Cin),.d(d[5]),.Cout(Cout[1]));
FS FS8(.a(r[2]),.b(y[3]),.Cin(Cin),.d(nowhere[1]),.Cout(Cout[1]));
Mux a3(.w0(d[3]),.w1(x[2]),.s(Cout[1]),.f(r[3]));
Mux a4(.w0(d[4]),.w1(r[0]),.s(Cout[1]),.f(r[4]));
Mux a5(.w0(d[5]),.w1(r[1]),.s(Cout[1]),.f(r[5])); //don't use r[5], skip one
// Row 2 is done
FS FS9(.a(x[1]),.b(y[0]),.Cin(Cin),.d(d[6]),.Cout(Cout[2]));
FS FS10(.a(r[3]),.b(y[1]),.Cin(Cin),.d(d[7]),.Cout(Cout[2]));
FS FS11(.a(r[4]),.b(y[2]),.Cin(Cin),.d(d[8]),.Cout(Cout[2]));
FS FS12(.a(r[5]),.b(y[3]),.Cin(Cin),.d(nowhere[2]),.Cout(Cout[2]));
Mux a6(.w0(d[6]),.w1(x[1]),.s(Cout[2]),.f(r[6]));
Mux a7(.w0(d[7]),.w1(r[3]),.s(Cout[2]),.f(r[7]));
Mux a8(.w0(d[8]),.w1(r[4]),.s(Cout[2]),.f(r[8]));
//Row 3 is Done
FS FS13(.a(x[0]),.b(y[0]),.Cin(Cin),.d(d[9]),.Cout(Cout[3]));
FS FS14(.a(r[6]),.b(y[1]),.Cin(Cin),.d(d[10]),.Cout(Cout[3]));
FS FS15(.a(r[7]),.b(y[2]),.Cin(Cin),.d(d[11]),.Cout(Cout[3]));
FS FS16(.a(r[8]),.b(y[3]),.Cin(Cin),.d(d[12]),.Cout(Cout[3]));
Mux a9(.w0(d[9]),.w1(x[0]),.s(Cout[3]),.f(R[0]));
Mux a10(.w0(d[10]),.w1(r[6]),.s(Cout[3]),.f(R[1]));
Mux a11(.w0(d[11]),.w1(r[7]),.s(Cout[3]),.f(R[2]));
Mux a12(.w0(d[12]),.w1(r[8]),.s(Cout[3]),.f(R[3]));
//Row 4 is Done
not(Q[0],Cout[0]);
not(Q[1],Cout[1]);
not(Q[2],Cout[2]);
not(Q[3],Cout[3]);
endmodule
module Divider();
reg [3:0] x,y;
reg Cin;
wire [3:0] Cout;
wire [12:0] r;
wire [3:0] R,Q;
SM uut(x,y,Cin,d,Cout,r,R,Q);
initial
begin
x=10;y=0;Cin=0;
#1 x=12;y=3;
#1 x=10;y=10;
#1 x=4;y=12;
#1 x=15;y=6;
end
endmodule
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.