20210330HDLBits学习笔记:Circuits - Combinational Logic

Ring or vibrate

根据逻辑表达式得到:

module top_module (
    input ring,
    input vibrate_mode,
    output ringer,       // Make sound
    output motor         // Vibrate
);
    assign ringer = ring & ~(vibrate_mode);
    assign motor = ring & vibrate_mode;
endmodule

也可以根据真值表进行always case

256to1 multiplexer

怎么理解?说不上来,读者有感受的评论交流下。

module top_module( 
    input [255:0] in,
    input [7:0] sel,
    output out );
    assign out = in[sel];
endmodule

256to1 4bit mux

-: 从此处开始的低四位, +:从此处开始的高四位

module top_module( 
    input [1023:0] in,
    input [7:0] sel,
    output [3:0] out );
    assign out = in[(sel *4) +: 4];
endmodule

3bit binary adder

always中不可以例化,例化与always,always与always之间都是并行关系。

module top_module( 
    input [2:0] a, b,
    input cin,
    output [2:0] cout,
    output [2:0] sum );
    wire [3:0] cout_mid;
    assign cout_mid[0] = cin;
    generate
    genvar i;
            for (i = 0; i < 3; i = i + 1)
                begin:loop
                    add x (a[i], b[i], cout_mid[i], cout_mid[i + 1], sum[i]);
                end
    endgenerate
    
    assign cout = cout_mid[3:1];
endmodule

module add(
	input a,
    input b,
    input cin,
    output cout,
    output sum
);
    assign {cout, sum} = a + b + cin;
endmodule

Signed addition overflow

两个正数相加符号位为1,或两个负数相加符号位为0,说明溢出了。

module top_module (
    input [7:0] a,
    input [7:0] b,
    output [7:0] s,
    output overflow
); //
    assign s = a + b;
    assign overflow = ((~ a[7] && ~ b[7]) && s[7]) | ((a[7] && b[7]) && (~s[7]));
endmodule

minimum SOP POS

SOP:(sum of product) 最小项的和(圈1)
POS(p… of sum) 最大项的积(圈0取反)
最终代表同一逻辑。

module top_module (
    input a,
    input b,
    input c,
    input d,
    output out_sop,
    output out_pos
); 
    assign out_sop = (c & d) | (~a & ~b & c);
    assign out_pos = ~((~c) | (a & c & ~d) | (b & c & ~d));

endmodule

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值