2021年4月20日 星期二

HBLbits_Verilog Basic_Always if

 HBLbits_Verilog Basic_Always if



always @(*) begin if (condition) begin out = x; end else begin out = y; end end


assign out = (condition) ? x : y;





Build a 2-to-1 mux that chooses between a and b. Choose b if both sel_b1 and sel_b2 are true. Otherwise, choose a. Do the same twice, once using assign statements and once using a procedural if statement.
sel_b1sel_b2out_assign
out_always
00a
01a
10a
11
b


// synthesis verilog_input_version verilog_2001
module top_module(
    input a,
    input b,
    input sel_b1,
    input sel_b2,
    output wire out_assign,
    output reg out_always   ); 
    //assign out = (condition) ? x : y;
    assign out_assign = (sel_b1&sel_b2) ? b : a;
    always@(*)
        if (sel_b1&sel_b2) 
            out_always=b;
        else 
            out_always=a;
endmodule

沒有留言:

張貼留言

2026 作業3 RFID+ Telegram 練習

 2026 作業3  RFID+ Telegram  練習 (Wokwi 與 Telegram 二者溝通訊息反映比較慢 ) 歡迎 Alex 使用 RFID 控制系統 /on : 開啟 LED /off : 關閉 LED /flash : 閃爍模式 /timer : 開啟 5 秒 ...