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
相关推荐
_落纸14 小时前
三大基础无源电子元件——电阻(R)、电感(L)、电容(C)
笔记
Alice-YUE15 小时前
【CSS学习笔记3】css特性
前端·css·笔记·html
2303_Alpha15 小时前
SpringBoot
笔记·学习
风_峰16 小时前
Ubuntu Linux SD卡分区操作
嵌入式硬件·ubuntu·fpga开发
FPGA_Linuxer16 小时前
FPGA 40 DAC线缆和光模块带光纤实现40G UDP差异
网络协议·fpga开发·udp
Hello_Embed1 天前
STM32HAL 快速入门(二十):UART 中断改进 —— 环形缓冲区解决数据丢失
笔记·stm32·单片机·学习·嵌入式软件
咸甜适中1 天前
rust语言 (1.88) 学习笔记:客户端和服务器端同在一个项目中
笔记·学习·rust
Grassto1 天前
RAG 从入门到放弃?丐版 demo 实战笔记(go+python)
笔记
Magnetic_h1 天前
【iOS】设计模式复习
笔记·学习·ios·设计模式·objective-c·cocoa
周周记笔记1 天前
学习笔记:第一个Python程序
笔记·学习