HDLBits学习------Problem 1~9

参考连接:HDLBits导学

Problem 1 : Zero

        问题:没有输入,输出0

        解决

module top_module(
    output zero
);// Module body starts after semicolon
    assign zero = 0;
endmodule

Problem 2 : Wire

       问题:使用wire让输出等于输入

       解决

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

Problem 3 : Wire4

        问题:创建一个模块有3个输入和4个输出,实现这样的连接:

                                                                        

        思路:wire 的源一般只能有一个,终点确可以有多个。一个源可以驱动多个信号。

        解决

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

        注意:assign 语句并不是创建 wire ,而是将创建 wire 之间的连接。


 Problem 4 : Notgate

        问题:通过 assign 语句以及 Verilog 的逻辑操作符,实现一个非门模块。

        思路“~”  逐位取反,只有一位也可以逻辑取反

        解决

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

Problem 5 : Andgate

        问题:创建一个模块实现与门

        思路“&” 逐位与

        解决

module top_module( 
    input a, 
    input b, 
    output out );
	
    assign out = a&b;
    
endmodule

        注意“&” 是逐位与,而 “&&” 是逻辑与


Problem 6 : Norgate

        问题:创建一个模块实现或非门

        思路“|” 逐位或 和 “~”的组合使用

        解决

module top_module( 
    input a, 
    input b, 
    output out );

    assign out = ~(a|b);
    
endmodule

        注意“~” 非逻辑的优先级大于 “|”


Problem 7 : XNorgate

        问题:创建一个模块实现同或门

        思路“~” 取反 和 “^” 异或的组合使用

        解决

module top_module( 
    input a, 
    input b, 
    output out );

    assign out = ~(a^b);
    
endmodule

        注意“^” 为逐位异或,Verilog 中不存在逻辑异或符号。


Problem 8 : Declaring wires

        问题:实现以下电路。 创建两条中间线(命名为您想要的任何名称)将 AND 和 OR 门连接在一起。

        

        解决

`default_nettype none
module top_module(
    input a,
    input b,
    input c,
    input d,
    output out,
    output out_n   ); 
    
    wire a_b = a & b;
    wire c_d = c & d;
    assign out = a_b | c_d;
    assign out_n = ~(a_b | c_d);

endmodule

        注意:可以在定义变量的同时给它赋值;

                信号只能被一个信号驱动,但是可以驱动多个信号


Problem 9 : 7458

        问题:创建一个与 7458 芯片功能相同的模块,它有 10 个输入和 2 个输出

        思路:7458的一个输出是四个输入中 两两相与后再或得到一个输出,另一个输出是六个输入中三三相与后再或得到的

        解决

module top_module ( 
    input p1a, p1b, p1c, p1d, p1e, p1f,
    output p1y,
    input p2a, p2b, p2c, p2d,
    output p2y );
	
	wire and2_1 = p2a & p2b;
	wire and2_2 = p2c & p2d;
	wire and3_1 = p1a & p1b & p1c;
	wire and3_2 = p1d & p1e & p1f;
	
	assign p2y = and2_1 | and2_2;
	assign p1y = and3_1 | and3_2;


endmodule

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值