20210324Verilog学习笔记:全加器的几个实现方式
程序员文章站
2024-03-02 19:40:46
...
数据流建模
module fulldaaer_behavior(ci, a, b, c, s);
input ci, a, b;
output c, s;
assign c = ((a ^ b) & ci) | (a & b),
s = (a ^ b ^ c);
endmodule
行为级建模
module adder_beha(ci, a, b, s, c);
input ci, a, b;
output s, c;
assign {c, s} = a + b + ci;
endmodule
结构级建模
module halfadder(a, b, c, s);
input a, b;
output c, s;
assign c = a & b,
s = a ^ b;
endmodule
module fulladder(ci, a, b, c, s);
input ci, a, b;
output c, s;
wire w1, w2, w3;
halfadder u1(a, b, w1, w2);
halfadder u2(ci, w2, w3, s);
or (c, w1, w3);
endmodule
对比:行为级建模代码简单易懂,而结构级建模综合结果清晰。
多位加法器:
module adder_beha(ci, a, b, s, c);
input ci;
input [7:0] a, b;
output [7:0] s;
output c;
assign {c, s} = a + b + ci;
endmodule