/*
通过实例化全加器模块实现四位加法的功能。
输入:cin,进位
x, y 被加数和加数
s 和
cout 进位
*/
module adder4(cin, x, y,s,cout);
input cin;
input [3:0] x;
input [3:0] y;
output [3:0] s;
output cout;
wire [3:1] c; //内部线网类型信号c,用来存储串行进位
fulladd stage0(.cin(cin),.x(x[0]),.y(y[0]),.s(s[0]),.cout(c[1]));
fulladd stage1(.cin(c[1]),.x(x[1]),.y(y[1]),.s(s[1]),.cout(c[2]));
fulladd stage2(.cin(c[2]),.x(x[2]),.y(y[2]),.s(s[2]),.cout(c[3]));
fulladd stage3(.cin(c[3]),.x(x[3]),.y(y[3]),.s(s[3]),.cout(cout));
endmodule |