2020年2月6日 星期四

數位IC設計入門-Verilog combinational logic 4 bit Comparator 比較器 Behavioral Modeling (& Test Bench)

數位IC設計入門-Verilog combinational logic 
4 bit Comparator 比較器 Behavioral Modeling (& Test Bench) 



//數位IC設計入門-Verilog combinational logic 
// 4 bit Comparator 比較器 Behavioral Modeling (& Test Bench) 
  
module COMP(a, b, gt, eq, lt);
  input [3:0] a, b;
  output gt, eq, lt;
  reg gt, eq, lt;

  always@(a or b)
  begin
        gt = 1'd0;
        eq = 1'd0;
        lt = 1'd0;
        if(a > b)
        begin
              gt = 1'd1;
        end
        
        else if (a == b)
        begin
              eq = 1'd1;
        end
        
        else
        begin
              lt = 1'd1;
        end
  end

  endmodule
  
// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps    
module Test_bench;
  //module COMP(a, b, gt, eq, lt);
  //input [3:0] a, b;
  //output gt, eq, lt;

// Inputs
reg [3:0]a=4'd0, b=4'd0;

// Outputs
wire gt, eq, lt;


// Instantiate the Unit Under Test (UUT)
//DECODER3X8(enable, in, out);

COMP UUT(a, b, gt, eq, lt);

initial begin
 $monitor(a, b, gt, eq, lt);

    // Initialize Inputs
 //#25 a[3:0]=4'd0 ,b[3:0]=4'd0;
 #25 a[3:0]=4'd9 ; b[3:0]=4'd0;
 #25 a[3:0]=4'd9 ; b[3:0]=4'd15;

 #25 a[3:0]=4'd10 ; b[3:0]=4'd10;


end

initial
begin
  #110;   // 模擬終止時間  110 ns
  $stop;
end


endmodule

沒有留言:

張貼留言

習題解答 (5/6)

  第五章 習題解答 一、 錯誤偵測技術 1. 何謂循環冗餘檢查法 (CRC)? 是一種根據傳輸資料產生簡短固定位數校驗碼的演算法。發送端將資料除以一個特定的多項式,得到的「餘數」即為 CRC 碼並隨資料發送;接收端以同樣多項式除之,若餘數為 0 則代表資料傳輸正確。 2. 何...