2021年4月24日 星期六

HBLbits_Verilog Basic_Bcdadd4

HBLbits_Verilog Basic_Bcdadd4 

with a BCD (binary-coded decimal) one-digit adder named bcd_fadd that adds two BCD digits and carry-in, and produces a sum and carry-out.

module bcd_fadd {
    input [3:0] a,
    input [3:0] b,
    input     cin,
    output   cout,
    output [3:0] sum );

Instantiate 4 copies of bcd_fadd to create a 4-digit BCD ripple-carry adder. 



module top_module( 

    input [15:0] a, b,
    input cin,
    output cout,
    output [15:0] sum );
    
    wire [2:0]ctmp;
    bcd_fadd u0(a[3:0],b[3:0],cin,ctmp[0],sum[3:0]);
    bcd_fadd u1(a[7:4],b[7:4],ctmp[0],ctmp[1],sum[7:4]);
    bcd_fadd u2(a[11:8],b[11:8],ctmp[1],ctmp[2],sum[11:8]);
    bcd_fadd u3(a[15:12],b[15:12],ctmp[2],cout,sum[15:12]);
 endmodule



沒有留言:

張貼留言

2026 作業3 RFID+ Telegram 練習

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