用vivado實現4比特加法器


 1 `timescale 1ns / 1ps
 2 module add_4_beha(
 3     a,
 4     b,
 5     cin,
 6     sum
 7     );
 8     input [3:0] a;
 9     input [3:0] b;
10     input cin;
11     output sum;
12     wire [3:0]a; 
13     wire [3:0]b;
14     wire  cin;
15     reg [4:0] sum;
16     
17     always @ (a or  b or cin)
18         begin
19             sum = a + b + cin;
20         end
21 endmodule

測試testbench:

`timescale 1ns / 1ps
module add_4_beha_tb;

reg [3:0] a,b;
reg cin;
wire [4:0] sum;

initial
$monitor ("a = %b, b = %b, cin = %b, sum = %b",a, b, cin, sum);

initial
begin
    #0      a = 4'b1100;
            b = 4'b0100;
            cin = 1'b0;
    #10     a = 4'b1100;
            b = 4'b0110;
            cin = 1'b1;
    #10     a = 4'b0010;
            b = 4'b0101;
            cin = 1'b1;
     #10    a = 4'b1000;
            b = 4'b1010;
            cin = 1'b0;
     #10    $stop;
 end
 
 add_4_beha inst(
    .a(a),
    .b(b),
    .cin(cin),
    .sum(sum)
 );
endmodule

不知道你有沒有發現規律,這里的電路很復雜,但是描述語言不管內部結構,直接描述出其行為。

在測試單元中,直接簡單的賦值,似乎更簡單。我抓不到硬件的奧秘!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM