Circuits--Verification--Finding Bug

  1. MUX

    module top_module (
    input sel,
    input [7:0] a,
    input [7:0] b,
    output [7:0] out );

    复制代码
     assign out = sel ? a : b;

    endmodule

2.NAND

复制代码
module top_module (input a, input b, input c, output out);//

    wire t;
    andgate inst1 (t,a,b,c,1'b1,1'b1);
    assign out = ~t;

endmodule
  1. 4-1MUX

    module top_module (
    input [1:0] sel,
    input [7:0] a,
    input [7:0] b,
    input [7:0] c,
    input [7:0] d,
    output [7:0] out ); //

    复制代码
     wire [7:0]m0, m1;
     mux2 mux0 ( sel[0],    a,    b, m0 );
     mux2 mux1 ( sel[0],    c,    d, m1 );
     mux2 mux2 ( sel[1], m0, m1,  out );

    endmodule

4.Add/Sub

复制代码
module top_module ( 
    input do_sub,
    input [7:0] a,
    input [7:0] b,
    output reg [7:0] out,
    output reg result_is_zero
);//

    always @(*) begin
        case (do_sub)
          0: out = a+b;
          1: out = a-b;
        endcase

    end
    always@(*)
        begin
            if (out == 0)
            	result_is_zero = 1;
            else
                result_is_zero = 0;
        end
        
endmodule

5.Case Statement

复制代码
module top_module (
    input [7:0] code,
    output reg [3:0] out,
    output reg valid);//

     always @(*) begin
         case (code)
            8'h45: out = 4'd0;
            8'h16: out = 4'd1;
            8'h1e: out = 4'd2;
            8'h26: out = 4'd3;
            8'h25: out = 4'd4;
            8'h2e: out = 4'd5;
            8'h36: out = 4'd6;
            8'h3d: out = 4'd7;
            8'h3e: out = 4'd8;
            8'h46: out = 4'd9;
            default: out = 4'd0;
        endcase

         if(out == 4'd0 && code != 8'h45) 
            valid = 1'b0;
        else
            valid = 1'b1;
     end
     		              
endmodule
相关推荐
ThreeYear_s6 分钟前
基于fpga的疲劳驾驶检测
fpga开发
阑梦清川19 分钟前
国防科技大学计算机基础慕课课堂学习笔记
笔记·学习·数学建模
不太可爱的叶某人2 小时前
【学习笔记】深入理解Java虚拟机学习笔记——第3章 垃圾收集器与内存分配策略
java·笔记·学习
半导体守望者4 小时前
Kyosan K5BMC ELECTRONIC INTERLOCKING MANUAL 电子联锁
经验分享·笔记·功能测试·自动化·制造
晨曦backend5 小时前
Vim 复制/剪切/粘贴命令完整学习笔记
笔记·学习·vim
GoldenaArcher5 小时前
Fullstack 面试复习笔记:HTML / CSS 基础梳理
笔记·面试·html
DIY机器人工房6 小时前
[10-3]软件I2C读写MPU6050 江协科技学习笔记(16个知识点)
笔记·科技·学习
青椒大仙KI116 小时前
25/6/11 <算法笔记>RL基础算法讲解
笔记·学习
爱上妖精的尾巴7 小时前
3-16单元格区域尺寸调整(发货单记录保存-方法2)学习笔记
javascript·笔记·学习·wps·js宏·jsa
岁月磨吾少年志7 小时前
【FPGA开发】DDS信号发生器设计
fpga开发