verilog中全加器行為級別(+ verilog中會自動新增進位)
阿新 • • 發佈:2020-12-27
module top_module ( input [3:0] x, input [3:0] y, output [4:0] sum ); // This circuit is a 4-bit ripple-carry adder with carry-out. assign sum = x+y; // Verilog addition automatically produces the carry-out bit. // Verilog quirk: Even though the value of (x+y) includes the carry-out, (x+y) is still considered to be a 4-bit number (The max width of the two operands). // This is correct: // assign sum = (x+y); // But this is incorrect: // assign sum = {x+y}; // Concatenation operator: This discards the carry-out endmodule
如果想分離cout 和 sum
assign {cout,sum} = x + y + cin;
就可將最後結果的cout和sum分離開