|

楼主 |
发表于 2011-7-10 22:23:49
|
显示全部楼层
程序附上
模块代码:
- module adder16(a,b,cin,clk,sum,cout);
- input[15:0] a,b;
- input cin;
- input clk;
- output[15:0] sum;
- output cout;
- reg[15:0] sum;
- reg cout;
- reg[15:0] temp_a,temp_b;
- reg temp_cin;
- reg[7:0] first_sum;
- reg first_cout;
- reg[7:0] first_a,first_b;
- always @(posedge clk)
- begin
- temp_a<=a;temp_b<=b;temp_cin<=cin;
- end
- always @(posedge clk)
- begin
- {first_cout,first_sum}<={1'b0,temp_a[7:0]}+{1'b0,temp_b[7:0]}+temp_cin;
- first_a<=temp_a[15:8];
- first_b<=temp_b[15:8];
- end
- always @(posedge clk)
- begin
- {cout,sum}<={first_a,8'b0}+{first_b,8'b0}+{first_cout,first_sum};
- end
- endmodule
复制代码 |
|