当前位置: 首页 > news >正文

verilog的学习

verilog描述模块逻辑

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

module xxx;endmodule

标识符的命名规则
1.以字母开头
2.可以包含任何字母和数字以及下划线_、美元符号$
3.区分大小写

verilog模块端口描述

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

module circle(s,x1,x2);//这括号里里面就是端口
input s,x1;
output x2;endmodule

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

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

具体哪个门逻辑(output,input,input...)

PS:需要注意的是 有非门的情况先要提前声明,例如not(k,s)
eg:一个2输入与门,其输出为y,输入为x1和x2

and( y, x1, x2 );

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

在设计大规模电路时,使用门级原始结构会很繁琐。可行的选择是采用更为抽象的表达式和编程结构描述逻辑电路的行为。
所以在这里我们采取用逻辑表达式表示的方法,例如f = ~s1x1 + s1x2
在verilog中就可以用assign 进行连续赋值

assign f = (~s1 & x1) | (s1 & x2)

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

上述是用逻辑表达式定义语句的,这次就来看一个使用过程语句定义的,用always编程结构
eg:如果s=0,则f=x1;如果s=1,则f=x2

if(s) f = x1;
else f = x2;

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

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

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

module top_module( output one );// Insert your code hereassign one = 1'b1;endmodule

Zero

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

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

Wire

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

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

Wire4

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

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

Andgate

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

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

Norgate

取反往前推,推到输入端

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

Xnorgate

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

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

Wire decl

其实看组合逻辑电路即可

`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

照样看电路图

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
http://www.dtcms.com/a/311425.html

相关文章:

  • 高效游戏状态管理:使用双模式位运算与数学运算
  • 从基础功能到自主决策, Agent 开发进阶路怎么走?
  • 技巧|SwanLab记录ROC曲线攻略
  • VueX进阶Pinia
  • go idea goland debug 报错 no debug info found
  • 从递归到动态规划-解码方法
  • Json Jsoncpp
  • 深入 Go 底层原理(十四):timer 的实现与高性能定时器
  • python JSONPath 表达式生成器
  • 淘宝获取商品SKU详情API接口操作指南
  • 交互 Codeforces Round 1040 Interactive RBS
  • 开发指南128-基础类-BaseDAO
  • 力扣面试150题--回文数
  • ABP VNext + NATS JetStream:高性能事件流处理
  • FPGA kernel 仿真器调试环境搭建
  • 分类任务当中常见指标 F1分数、recall、准确率分别是什么含义
  • 「iOS」————SideTable
  • 基于Dockerfile 部署一个 Flask 应用
  • WAIC引爆AI,智元机器人收购上纬新材,Geek+上市,157起融资撑起热度|2025年7月人工智能投融资观察 · 极新月报
  • 【传奇开心果系列】Flet框架流式输出和实时滚动页面的智能聊天机器人自定义模板
  • github在界面创建tag
  • 性能测试-性能测试中的经典面试题二
  • 超级人工智能+无人机操控系统,振兴乡村经济的加速器,(申请专利应用),严禁抄袭!
  • spring-ai-alibaba 学习(十九)——graph之条件边、并行节点、子图节点
  • linux编译基础知识-库文件标准路径
  • Docker 的网络模式
  • 3 使用 Jenkins 构建镜像:将你的应用打包成镜像
  • 【20min 急速入门】使用Demucs进行音轨分离
  • ffmpeg命令和ffplay命令详解
  • Java高性能编程实践指南