Verilog:HDLBits刷题-基础

前言

这是我第二次刷HDLBits的题,第一次是刚接触FPGA时,为了快速入门Verilog,第一次刷题跟着B站视频刷的,但是现在发现没有很大的用处,个人感觉还是有一点Verilog基础后,再来刷HDLBits会好一点,虽然很多人说这上面的题都很简单,但是还是值得刷一遍,里面几乎涵盖了Verilog的所有常用语法,并且还可以尝试用不同方法解同一道题。

代码

以下是我写的每道题的代码和思路


Basic

// 线
module top_module (
     input in, output out
);
assign out = in;
    
endmodule

// 3输入、4输出
// assign:描述的是连接关系,不是赋值关系
module top_module( 
    input a,b,c,
    output w,x,y,z );
    assign w = a;
    assign x = b;
    assign y = b;
    assign z = c;

endmodule

// 非门
module top_module( input in, output out );

assign out = ~ in;

endmodule

// 与门
module top_module( 
    input a, 
    input b, 
    output out );
    assign out = a & b;

endmodule

// 或非门
module top_module( 
    input a, 
    input b, 
    output out );
    assign out = ~(a | b);

endmodule

// 同或门=异或非
module top_module( 
    input a, 
    input b, 
    output out );
    assign out = ~(a ^ b);

endmodule

// module内部用wire连接
`default_nettype none
module top_module(
    input a,
    input b,
    input c,
    input d,
    output out,
    output out_n   ); 
    wire wire_ab;
    wire wire_cd;
    wire wire_abcd;

    assign wire_ab = a & b;
    assign wire_cd = c & d;
    assign wire_abcd = wire_ab | wire_cd;

    assign out = wire_abcd;
    assign out_n = ~ wire_abcd;


endmodule

// 7458芯片

module top_module ( 
    input p1a, p1b, p1c, p1d, p1e, p1f,
    output p1y,
    input p2a, p2b, p2c, p2d,
    output p2y );

    wire wire_1_abc;
    wire wire_1_def;
    wire wire_2_ab;
    wire wire_2_cd;
    wire wire_1;
    wire wire_2;

    assign wire_2_ab = p2a & p2b;
    assign wire_2_cd = p2c & p2d;
    assign wire_1 = wire_2_ab | wire_2_cd;

    assign wire_1_abc = p1a & p1b & p1c;
    assign wire_1_def = p1d & p1e & p1f;
    assign wire_2 = wire_1_abc | wire_1_def;

    assign p1y = wire_2;
    assign p2y = wire_1;

endmodule

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值