HDLBits-Modules 题解【Verilog模块例化】(中文翻译+英文原文,可顺带学习英文)

news2024/10/6 8:22:28

Moudule

概念介绍

到目前为止,你已经熟悉了一个模块,它是一个通过输入和输出端口与其外部交互的电路。更大、更复杂的电路是通过将较小的模块和其他连接在一起的部分(例如赋值语句和always块)组合而成的更大模块来构建的。因为模块可以包含其他模块的实例,由此形成了一个层级结构。

By now, you’re familiar with a module, which is a circuit that interacts with its outside through input and output ports. Larger, more complex circuits are built by composing bigger modules out of smaller modules and other pieces (such as assign statements and always blocks) connected together. This forms a hierarchy, as modules can contain instances of other modules.

下面这张图展示了一个非常简单的电路及其子模块。在这个练习中,创建一个实例模块mod_a,然后这个模块的三个引脚(in1,in2,和out)连接到你的顶层模块的三个端口(a,b,和out)。这个模块mod_a是给定给你的——你必须实例化它。

The figure below shows a very simple circuit with a sub-module. In this exercise, create one instance of module mod_a, then connect the module’s three pins (in1, in2, and out) to your top-level module’s three ports (wires a, b, and out). The module mod_a is provided for you — you must instantiate it.

在连接这些模块时,只有在模块上的端口才是重要的。你不需要知道模块内部的代码(结构)。模块mod_a看上去像这样:

When connecting modules, only the ports on the module are important. You do not need to know the code inside the module. The code for module mod_a looks like this:

module mod_a ( input in1, input in2, output out );
    // Module body
endmodule

![[Pasted image 20230411225523.png]]

模块的层级结构是由下面这样构成的,在一个模块中实例化其它模块,只要所有的模块都隶属于同一个工程(这样编译器能够知道从哪里找到这些模块)。一个模块的代码并不会被写到其它模块的主体里面去。(不同模块的代码是不嵌套的)

The hierarchy of modules is created by instantiating one module inside another, as long as all of the modules used belong to the same project (so the compiler knows where to find the module). The code for one module is not written inside another module’s body (Code for different modules are not nested).

你可能需要将信号通过端口名或者端口位置来连接。作为额外的练习,两种方法都尝试下。

You may connect signals to the module by port name or port position. For extra practice, try both methods.

在这里插入图片描述

方法

连接信号到模块端口

有两种常采用的方法将wire 连接到端口:位置连接法和名字连接法

There are two commonly-used methods to connect a wire to a port: by position or by name.

位置连接法

通过位置去将wire 连接到端口的语法通常是更常见的,因为它使用了一个类C语法。在例化一个模块时,端口根据模块的声明从左到右依次被连接。例如:

The syntax to connect wires to ports by position should be familiar, as it uses a C-like syntax. When instantiating a module, ports are connected left to right according to the module’s declaration. For example:

mod_a instance1 ( wa, wb, wc);

上面这段verilog代码例化了一个mod_a模块并且给它了一个模块名字“instance1”,然后连接信号wa(在这个新模块之外)和这个新模块的第一个端口(in1),连接信号wb和这个新模块的第二个端口(in2) ,连接信号wc和这个新模块的第三个端口(in3)。 这个语法的一个缺点就是如果这个模块端口的排序改变了,所有的例化模块都需要找到并且改变到匹配这个新模块的顺序。

This instantiates a module of type mod_a and gives it an instance name of “instance1”, then connects signal wa (outside the new module) to the first port (in1) of the new module, wb to the second port (in2), and wc to the third port (out). One drawback of this syntax is that if the module’s port list changes, all instantiations of the module will also need to be found and changed to match the new module.

名字连接法

即使端口顺序改变了,通过姓名连接信号和端口仍然让wires保持正确的连接性。但是,这个语法更加冗长。

Connecting signals to a module’s ports by name allows wires to remain correctly connected even if the port list changes. This syntax is more verbose, however.

mod_a instance2 ( .out(wc), .in1(wa), .in2(wb));

上面的verilog代码将mod_a模块例化成了“instance2”, 然后将信号wa连接到端口in1wb连接到端口in2wc连接到端口out。注意端口顺序是不相关的,因为连接根据对应的名称来生成的,无关它在子模块端口列表中的位置。还要注意在语法里面端口名前面的点!

The above line instantiates a module of type mod_a named “instance2”, then connects signal wa (outside the module) to the port named in1, wb to the port named in2, and wc to the port named out. Notice how the ordering of ports is irrelevant here because the connection will be made to the correct name, regardless of its position in the sub-module’s port list. Also notice the period immediately preceding the port name in this syntax.

模块代码示例

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

	// Create an instance of "mod_a" named "inst1", and connect ports by name:
	mod_a inst1 ( 
		.in1(a), 	// Port"in1"connects to wire "a"
		.in2(b),	// Port "in2" connects to wire "b"
		.out(out)	// Port "out" connects to wire "out" 
				// (Note: mod_a's port "out" is not related to top_module's wire "out". 
				// It is simply coincidence that they have the same name)
	);

/*
	// Create an instance of "mod_a" named "inst2", and connect ports by position:
	mod_a inst2 ( a, b, out );	// The three wires are connected to ports in1, in2, and out, respectively.
*/
	
endmodule

总结

  1. 两种方法尽量用名字连接法,防止被例化的模块改了端口顺序
  2. 第二种例化方法不要忘记每个端口前的.
  3. 模块例化也是一条一句,也要以分号;结尾

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/411034.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

从零开始学OpenCV——图像灰度变换详解(线性与非线性变换)

文章目录图像灰度变化灰度变换介绍灰度线性变换灰度分段线性变换图像点运算灰度非线性变换线性点运算灰度的非线性变换:对数变换灰度的非线性变换:伽马变换灰度的非线性变换:对比拉伸灰度的非线性变换: S形灰度变换灰度的非线性变…

tomcat中出现RFC7230和RFC3986问题解析

问题截图 问题分析 出现上述问题,是因为各版本tomcat中对特殊字符和请求路径中携带中文参数而产生的错误提示。 解决办法 1、调整tomcat版本 tomcat 7.0.76之前的版本不会出现类似问题 2、tomcat9之前,修改tomcat目录底下的/conf/catalina.properti…

233:vue+openlayers绘制渐变填充色的圆形、多边形

第233个 点击查看专栏目录 本示例的目的是介绍如何在vue+openlayer中绘制带有渐变填充色的圆形、多边形。这里用canvas的方式去渲染,用到了DEVICE_PIXEL_RATIO,设备上的物理像素与设备无关像素 (dips) 之间的比率 (window.devicePixelRatio)。 直接复制下面的 vue+openlayer…

用ChatGPT创建一个REST API

ChatGPT是OpenAI公司开发的大型语言模型。在本文中,主要探讨如何使用ChatGPT在C#中创建REST API。 一、简介 ChatGPT是由人工智能研究中心OpenAI创建的尖端自然语言处理模型,OpenAI公司是由埃隆马斯克、萨姆奥特曼和格雷格布罗克曼共同创办的。该模型于…

360浏览器+Adobe Acrobat DC实现在线预览PDF大样校对

甲方:实现方正PDF文字大样校对,校对后在360浏览器中新开一个页面在线预览PDF文字大样校对结果。 我方实现过程: 1.方案选择 方案零:使用浏览器自带的PDF阅览器,经测试360极速模型,谷歌等软件能预览但是标记的PDF内容…

【笔记】大模型,大资料

大模型,大资料,loss会降低,准确率会增加 1大模型 1.1模型的顿悟时刻 举了一个一知半解的例子 1.2 模型 chain of thought 模型足够大时才会有比较好的作用 calibration 检测模型对于答案的confidence 会出现 “u-shape” 2.大资料 文法…

系统复杂度之【高可用】

接着,我们聊聊复杂度的第二个要求高可用。 参考维基百科,先来看看高可用的定义。 系统无中断地执行其功能的能力,代表系统的可用性程度,是进行系统设计时的准则之一。 这个定义的关键在于“ 无中断”,但恰好难点也在“…

Java 并发编程面试题——Future

目录1.什么是 Future 模式?Java 中是如何实现的?2.Callable、Future 与 FutureTask 分别是什么?2.1.Callable 接口2.2.Future 接口2.3.FutureTask 类3.CompletableFuture 类有什么用?1.什么是 Future 模式?Java 中是如…

windows系统管理_Windows server 2016 组管理与授权

组账户的概述 在 windows 服务器中,当我们需要为多个用户设置相同的权限时,一个一个的逐一设置会比较 麻烦,这个时候我们就需要用到另一种模式,组账户,使用此账户来进行简化操作。 在以后的职场中,每家公司…

Flink 优化 (五) --------- Job 优化

目录一、使用 DataGen 造数据1. DataStream 的 DataGenerator2. SQL 的 DataGenerator二、算子指定 UUID三、链路延迟测量四、开启对象重用五、细粒度滑动窗口优化一、使用 DataGen 造数据 开发完 Flink 作业,压测的方式很简单,先在 kafka 中积压数据&a…

全景图像畸变校正

1.简介 理想的相机基本上是小孔成像的,在小孔成像模型中,如果焦距一定,那么图像传感器像素平面的面积直接决定了相机视场角的大小,超过这个视场角范围的物体不会被镜头获取到。因此基于透镜成像原理的相机,视场角无法…

JAVA解析XML时的内存消耗问题

问题出现 最近一个项目中,有个需求功能是从外部传入的XML读取数据,然后写入到数据库中。 写完之后,有在本地电脑上的Tomcat跑了一下,正常读取到XML中的数据,并整理好后,插入了数据库保存了。但是线上运行的…

C语言文件操作复习回顾(2)

TIPS 文件的顺序读写:fgetc, fputc, fputs(一行字符串的输出\n注意一下), fgets(一行字符串的输入\n三特性),fprintf(格式化字符串的输出联想printf很简单),fscanf&…

pyspark 实验二,rdd编程

1.环境准备 start-all.sh启动Hadoop ./bin start-all.sh 启动spark 上传数据集 1.求该系总共多少学生 linessc.textFile("file:///home/data.txt") res lines.map(lambda x:x.split(",")).map(lambda x:x[0]) sumres.distinct() sum.cont() 2.求该系设置…

【MybatisPlus快速入门】—— 进阶入门

进阶篇 1.1 映射专题 Mybatis 框架之所以能够简化数据库操作,是因为他内部的映射机制,通过自动映射,进行数据的封装,我们只要符合映射规则,就可以快速高效的完成SQL操作的实现既然 MybatisPlus 是基于Mybatis 的增强…

程序员如何能提高自己的编程水平?

这些实用的小建议,能帮你迅速地提高编程水平: 不要做无意义的奋斗 拒绝喊口号和无意义的奋斗,包括但不限于: ①做了计划表却从未有执行的一天; ②每天都是最早来、最晚走,但是工作进度趋近于0&#xff1b…

ASP.NET Core MVC 从入门到精通之接化发(一)

随着技术的发展,ASP.NET Core MVC也推出了好长时间,经过不断的版本更新迭代,已经越来越完善,本系列文章主要讲解ASP.NET Core MVC开发B/S系统过程中所涉及到的相关内容,适用于初学者,在校毕业生&#xff0c…

PathCore:IAD文献解读

论文链接:[Towards Total Recall in Industrial Anomaly Detection]Towards Total Recall in Industrial Anomaly Detection :数据集, :标签 : 在ImageNet上预训练后的网络 第 张图 网络中第 层 1. Locall…

Sentinel学习笔记

Sentinel 官方文档: https://github.com/alibaba/Sentinel/wiki/%E4%B8%BB%E9%A1%B5 SpringCloud Alibaba: https://spring-cloud-alibaba-group.github.io/github-pages/greenwich/spring-cloud-alibaba.html#_spring_cloud_alibaba_sentinel 是什么…

丝滑的打包部署,一套带走~

以下文章来源于悟空聊架构 ,作者悟空聊架构 本文主要内容如下: 目录 一、背景 Docker打包部署方案 项目背景:新项目的后端框架是刚起步,搭建的是一套微服务框架,基础服务有网关 Gateway, Nacos 注册中心…