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
相关推荐
鬼手点金1 小时前
构建有效 Agent 的核心原则
java·人工智能·git·学习·自动化
姜九笙5612 小时前
python学习---归来仍是新人
java·python·学习
海绵宝宝转agent2 小时前
2026-10-19学习笔记
笔记·学习
云水初2 小时前
【agent篇】RAG Agent避坑指南(附高级RAG Agent汇总)
开发语言·笔记·python·学习·langchain·agent·rag
外收内放3 小时前
数据分析(图表信息详解)
python·学习·数据分析·matplotlib
气质、小青年!3 小时前
进程1学习
linux·学习
坤坤子吖3 小时前
Linux 线程同步与互斥——互斥锁
linux·服务器·c++·笔记·学习
撩得Android一次心动3 小时前
Jetpack Compose 知识点整理3【个人用】
android·笔记·学习·kotlin·android compose
威嵌神州4 小时前
国产化加固计算机项目选型笔记|板卡、整机、平板与定制模块评估要点
笔记·fpga开发·电脑
阿梦Anmory4 小时前
规划领域定义语言(PDDL)学习笔记
笔记·学习