//半加器 module add(a,b,c,g,p,s); input a,b,c;//C为进位信号 output g,p,s; assign s = a^b^c; //计算和 assign g = a & b; //进位传递函数p72 assign p = a | b; //进位生成函数p72 endmodule //进位的生成函数和传递函数,在超前进位加法器中使用。 module g_p (g,p,c_in,g_out,p_out,c_out); input [1:0] g,p; input c_in; output g_out, p_out, c_out;//c_out为进位 assign g_out = g[1] | p[1] & g[0]; assign p_out = p[1] & p[0]; assign c_out = g[0] | p[0] & c_in; endmodule //全加器 module cla_2 (a,b,c_in,g_out,p_out,s); input [1:0] a,b; //输入信号:a和b的位宽都是2位。从高位1到低位0 input c_in; //进位信号 output g_out,p_out; //输出:g和p辅助函数 output [1:0] s; //输出信号:a、b的和 wire [1:0] g,p; //wire使用在连续赋值语句中,而reg使用在过程赋值语句(initial ,always)中。 wire c_out; add add0 (a[0],b[0],c_in,g[0],p[0],s[0]); add add1