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
相关推荐
JJJJ_iii4 分钟前
【深度学习03】神经网络基本骨架、卷积、池化、非线性激活、线性层、搭建网络
网络·人工智能·pytorch·笔记·python·深度学习·神经网络
玉石观沧海9 分钟前
高压变频器故障代码解析F67 F68
运维·经验分享·笔记·分布式·深度学习
初级炼丹师(爱说实话版)1 小时前
MySql速成笔记5(多表关系)
笔记
iconball2 小时前
个人用云计算学习笔记 --19 (MariaDB服务器)
linux·运维·笔记·学习·云计算
岑梓铭2 小时前
《考研408数据结构》第四章(串和串的算法)复习笔记
数据结构·笔记·考研·算法
冬夜戏雪3 小时前
记录下C盘清理步骤(有效)
经验分享·笔记
我登哥MVP3 小时前
Apache Tomcat 详解
java·笔记·tomcat
泽虞4 小时前
《Qt应用开发》笔记
linux·开发语言·c++·笔记·qt
报错小能手4 小时前
linux学习笔记(21)线程同步——互斥锁
linux·笔记·学习
爱吃汽的小橘5 小时前
异步串口通信和逻辑分析仪
运维·服务器·网络·单片机·嵌入式硬件·fpga开发