verilog的学习

verilog描述模块逻辑

数字逻辑电路以模块(module)的形式定义

语法:

vl 复制代码
module xxx;


endmodule

标识符的命名规则

1.以字母开头

2.可以包含任何字母和数字以及下划线_、美元符号$

3.区分大小写

verilog模块端口描述

电路模块的端口:一个电路模块有输入和输出信号,它们统称为端口(port)

语法:

vl 复制代码
module circle(s,x1,x2);//这括号里里面就是端口
input s,x1;
output x2;

endmodule

电路功能描述---门级原始结构

门级原始结构又称门实例化 gate instantiation

语法:

vl 复制代码
具体哪个门逻辑(output,input,input...)

PS:需要注意的是 有非门的情况先要提前声明,例如not(k,s)

eg:一个2输入与门,其输出为y,输入为x1和x2

vl 复制代码
and( y, x1, x2 );

电路功能描述---行为定义---连续赋值

在设计大规模电路时,使用门级原始结构会很繁琐。可行的选择是采用更为抽象的表达式和编程结构描述逻辑电路的行为。

所以在这里我们采取用逻辑表达式 表示的方法,例如f = ~s1x1 + s1x2

在verilog中就可以用assign 进行连续赋值

vl 复制代码
assign f = (~s1 & x1) | (s1 & x2)

电路功能描述---行为定义---过程语句

上述是用逻辑表达式 定义语句的,这次就来看一个使用过程语句定义的,用always编程结构

eg:如果s=0,则f=x1;如果s=1,则f=x2

vl 复制代码
if(s) f = x1;
else f = x2;

但是上述过程语句需要包含在always结构中

vl 复制代码
always @(sensitivity_list)
[begin]
    [procedural assignment statements]  //过程赋值语句
    [if-else statements]  //if-else语句
    [case statements]     //case语句
    [while, repeat, and for loops] //循环语句
    [task and function calls]      //任务和函数调用
[end]

PS:
1.always块中的输出信号必须定义成寄存器型reg

2.一个Verilog模块中可以包含多个always块

3.一整个always块可以看成是一个并行语句

verilog基础练习

verilog 练习网站

Step one

没啥好说的就让你输出一个值

v 复制代码
module top_module( output one );

// Insert your code here
    assign one = 1'b1;

endmodule

Zero

也没啥好说的,就是让你指定输出为0

v 复制代码
module top_module(
    output zero
);// Module body starts after semicolon
assign zero = 0;
endmodule

Wire

就是让你接线,这里注意输出在左,输入在右

v 复制代码
module top_module( input in, output out );
assign out = in;
endmodule

Wire4

也没啥好说的,在一对一接线上,增加了input 的 口

v 复制代码
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

反相器

不在输出端取反,而是将气泡往前推,推到输入端

v 复制代码
module top_module( input in, output out );
assign out = ~in;
endmodule

Andgate

没啥好说的,直接在输入端取与即可

v 复制代码
module top_module( 
    input a, 
    input b, 
    output out );
assign out = a & b;
endmodule

Norgate

取反往前推,推到输入端

v 复制代码
module top_module( 
    input a, 
    input b, 
    output out );
    assign out = ~(a | b);
endmodule

Xnorgate

我其实一开始直接写成与或式,完全忘记了还可以直接用^表示的

v 复制代码
module top_module( 
    input a, 
    input b, 
    output out );
    assign out = ~(a ^ b);
endmodule

Wire decl

其实看组合逻辑电路即可

v 复制代码
`default_nettype none
module top_module(
    input a,
    input b,
    input c,
    input d,
    output out,
    output out_n   );
    wire haha;
    wire haha1;
    wire haha2;
    assign haha = (a & b);
    assign haha1 = (c & d);
    assign haha2 = (haha|haha1);
    assign out_n = ~haha2;
    assign out = haha2;
endmodule

7458

照样看电路图

v 复制代码
module top_module ( 
    input p1a, p1b, p1c, p1d, p1e, p1f,
    output p1y,
    input p2a, p2b, p2c, p2d,
    output p2y );
    wire p2xi1;
    wire p2xi2;
    wire p1xi1;
    wire p1xi2;
    assign p2xi1 = (p2a & p2b);
    assign p2xi2 = (p2c & p2d);
    assign p2y = (p2xi1 | p2xi2);
    assign p1xi1 = (p1a & p1c & p1b);
    assign p1xi2 = (p1f & p1e & p1d);
    assign p1y = (p1xi1 | p1xi2);

endmodule
相关推荐
西岸行者5 天前
学习笔记:SKILLS 能帮助更好的vibe coding
笔记·学习
ZPC82105 天前
docker 镜像备份
人工智能·算法·fpga开发·机器人
ZPC82105 天前
docker 使用GUI ROS2
人工智能·算法·fpga开发·机器人
悠哉悠哉愿意5 天前
【单片机学习笔记】串口、超声波、NE555的同时使用
笔记·单片机·学习
别催小唐敲代码5 天前
嵌入式学习路线
学习
毛小茛5 天前
计算机系统概论——校验码
学习
babe小鑫5 天前
大专经济信息管理专业学习数据分析的必要性
学习·数据挖掘·数据分析
winfreedoms5 天前
ROS2知识大白话
笔记·学习·ros2
在这habit之下5 天前
Linux Virtual Server(LVS)学习总结
linux·学习·lvs
我想我不够好。5 天前
2026.2.25监控学习
学习