HDLBits刷题Day01

本文介绍了Verilog语言中的基本门电路(包括Not, And, Nor, Xor门),Wire数据类型及其用法,以及如何声明和连接电路。详细讲解了Quartus中的默认值设定和7458集成块的使用。适合初学者了解数字逻辑设计的底层原理。


强烈建议大家去看看HDLBits 中文导学,原文在知乎
链接: link.

1. Zero

要求输出0;考察了Quartus中,不给变量赋值默认值为0;
模块声明语句中不需要加分号;

//赋0
module top_module(
    output zero
);
    assign zero=0;
    //或者assign zero=1'b0;

endmodule

2. Wire

wire是一种Verilog的数据类型;代表信号;一个输入,多个输出;

assign A=B; //连续赋值 

Tips:与软件编程语言不同的是,这里A ,B是动态的,A始终等于B,并且随着B的改变而改变

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

类似一个黑盒,只需要将输入赋值给输出就行;

3.Wire4

声明的顺序没有影响,Verilog并行执行;

input a;
//其实是
input wire a;
默认省略 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

4. Notgate

~:逐位取反;位宽与输入一致
!: 逻辑取反;仅一位

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

5. Andgate

&:逐位与
&&:逻辑与

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

6.Norgate

或非门:或门的输出取反

module top_module( 
    input a, 
    input b, 
    output out );
    assign out=~(a|b);

endmodule

7.Xnorgate

同或门:相同为1,不同为0;
异或门:相同为0 ,不同为 1;
^:异或符号;

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

endmodule

8.Wire Declaring

模块的输入输出信号wire在模块中声明;
模块中要用到的中间过渡的信号;在模块外声明;

module top_module(
    input a,
    input b,
    input c,
    input d,
    output out,
    output out_n   ); 
    wire A1,A2;
    assign A1=a&b;
    assign A2=c&d;
    assign out=A1|A2;
    assign out_n=~(A1|A2);

endmodule

9.7458



module top_module ( 
    input p1a, p1b, p1c, p1d, p1e, p1f,
    output p1y,
    input p2a, p2b, p2c, p2d,
    output p2y );
    assign p2y=(p2a & p2b)|(p2c  & p2d);
    assign p1y=(p1a & p1b & p1c)|(p1f & p1e & p1d);
    
endmodule
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值