HDLBits (69) — 加法器
2022-03-13 17:08 作者:僚机Wingplane | 我要投稿
本题链接:
https://hdlbits.01xz.net/wiki/Exams/m2014_q4j
实现以下电路:

(“FA”是一个全加法器)

题目
module top_module (
input [3:0] x,
input [3:0] y,
output [4:0] sum);

答案
module top_module (
input [3:0] x,
input [3:0] y,
output [4:0] sum);
assign sum = x + y;
endmodule

当位宽大于 1 时,wire 或 reg 即可声明为向量的形式。
Verillog 还支持指定 bit 位后固定位宽的向量域选择访问。
- [bit+: width] : 从起始 bit 位开始递增,位宽为 width。
- [bit-: width] : 从起始 bit 位开始递减,位宽为 width。
参考内容:
2.3 Verilog 数据类型| 菜鸟教程:
https://www.runoob.com/w3cnote/verilog-data-type.html