实现全加器①
根据全加器的功能,可列出功能表如下:
输入 |
输出 |
|||
A |
B |
Ci |
S |
Co |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
1 |
0 |
0 |
1 |
0 |
1 |
0 |
0 |
1 |
1 |
0 |
1 |
1 |
0 |
0 |
1 |
0 |
1 |
0 |
1 |
0 |
1 |
1 |
1 |
0 |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
根据功能表,可得出以下表达式
结合逻辑表达式,可得Verilog代码描述如下:
module add_half( input A , input B , output wire S , output wire C ); assign S = A ^ B; assign C = A & B; endmodule /***************************************************************/ module add_full( input A , input B , input Ci , output wire S , output wire Co ); wire c_1; wire c_2; wire sum_1; add_half add_half_1( .A (A), .B (B), .S (sum_1), .C (c_1) ); add_half add_half_2( .A (sum_1), .B (Ci), .S (S), .C (c_2) ); assign Co = c_1 | c_2;
参考答案
`timescale 1ns/1ns module add_half( input A , input B , output wire S , output wire C ); assign S = A ^ B; assign C = A & B; endmodule /***************************************************************/ module add_full( input A , input B , input Ci , output wire S , output wire Co ); wire c_1; wire c_2; wire sum_1; add_half add_half_1( .A (A), .B (B), .S (sum_1), .C (c_1) ); add_half add_half_2( .A (sum_1), .B (Ci), .S (S), .C (c_2) ); assign Co = c_1 | c_2; endmodule
如果关于此次题单有问题或者反馈意见,欢迎加入牛客用户反馈群沟通~