二、Verilog Language

Modules:Hierarchy

1、Modules

Problem Statement:

The figure below shows a very simple circuit with a sub-module.In this exercise, create one instanceof 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.

module top_module ( input a, input b, output out );// mod_a instance1 (a , b , out);                    By position// mod_a instance1 (.in1(a) , .in2(b) , .out(out));  By nameendmodule

2、Connecting ports by position

Problem Statement:

You are given a module named mod_a that has 2 outputs and 4 inputs, in that order. You must connect the 6 ports by position to your top-level module's ports out1out2abc, and d, in that order.

You are given the following module:

module mod_a ( output, output, input, input, input, input );

module top_module ( input a, input b, input c,input d,output out1,output out2
);mod_a instance1 (out1 , out2 , a , b , c , d);endmodule

3、Connecting ports by name

Problem Statement:

You are given a module named mod_a that has 2 outputs and 4 inputs, in some order. You must connect the 6 ports by name to your top-level module's ports:

Port in mod_a Port in top_module
output out1 out1
output out2 out2
input in1 a
input in2 b
input in3 c
input in4 d

You are given the following module:

module mod_a ( output out1, output out2, input in1, input in2, input in3, input in4);

module top_module ( input a, input b, input c,input d,output out1,output out2
);mod_a instance1(.in1(a) , .in2(b) , .in3(c) , .in4(d) , .out1(out1) , .out2(out2));endmodule

4、Three modules

Problem Statement:

You are given a module my_dff with two inputs and one output (that implements a D flip-flop). Instantiate three of them, then chain them together to make a shift register of length 3. The clk port needs to be connected to all instances.

The module provided to you is: module my_dff ( input clk, input d, output q );

Note that to make the internal connections, you will need to declare some wires. Be careful about naming your wires and module instances: the names must be unique.

module top_module ( input clk, input d, output q );wire q1;wire q2;my_dff instance1(.clk(clk) , .d(d)  , .q(q1));my_dff instance2(.clk(clk) , .d(q1) , .q(q2));my_dff instance3(.clk(clk) , .d(q2) , .q(q));endmodule

5、Modules and vectors

Problem Statement:

You are given a module my_dff8 with two inputs and one output (that implements a set of 8 D flip-flops). Instantiate three of them, then chain them together to make a 8-bit wide shift register of length 3. In addition, create a 4-to-1 multiplexer (not provided) that chooses what to output depending on sel[1:0]: The value at the input d, after the first, after the second, or after the third D flip-flop. (Essentially, sel selects how many cycles to delay the input, from zero to three clock cycles.)

The module provided to you is: module my_dff8 ( input clk, input [7:0] d, output [7:0] q );

module top_module ( input        clk, input  [7:0] d, input  [1:0] sel, output [7:0] q
);wire   [7:0] q1; wire   [7:0] q2; wire   [7:0] q3;my_dff8 instance1(.clk(clk) , .d(d)  , .q(q1));my_dff8 instance2(.clk(clk) , .d(q1) , .q(q2));my_dff8 instance3(.clk(clk) , .d(q2) , .q(q3));always@ (*)begincase (sel)4'd0 :      q = d;4'd1 :      q = q1;4'd2 :     q = q2;4'd3 :     q = q3;endcase
endendmodule

6、Adder 1

Problem Statement:

You are given a module add16 that performs a 16-bit addition. Instantiate two of them to create a 32-bit adder. One add16 module computes the lower 16 bits of the addition result, while the second add16 module computes the upper 16 bits of the result, after receiving the carry-out from the first adder. Your 32-bit adder does not need to handle carry-in (assume 0) or carry-out (ignored), but the internal modules need to in order to function correctly. (In other words, the add16 module performs 16-bit a + b + cin, while your module performs 32-bit a + b).

Connect the modules together as shown in the diagram below. The provided module add16 has the following declaration:

module add16 ( input[15:0] a, input[15:0] b, input cin, output[15:0] sum, output cout );

module top_module(input  [31:0] a,input  [31:0] b,output [31:0] sum
);wire   [15:0] out1;wire   [15:0] out2;wire cout_cin;add16 instance1(.a(a[15:0]) ,  .b(b[15:0]) ,  .cin(1'd0) ,     .cout(cout_cin) , .sum(out1));add16 instance2(.a(a[31:16]) , .b(b[31:16]) , .cin(cout_cin) , .sum(out2));assign sum = {out2 , out1};endmodule

7、Adder 2

Problem Statement:

you are given a module add16 that performs a 16-bit addition. You must instantiate two of them to create a 32-bit adder. One add16 module computes the lower 16 bits of the addition result, while the second add16 module computes the upper 16 bits of the result. Your 32-bit adder does not need to handle carry-in (assume 0) or carry-out (ignored).

Connect the add16 modules together as shown in the diagram below. The provided module add16 has the following declaration:

module add16 ( input[15:0] a, input[15:0] b, input cin, output[15:0] sum, output cout );

Within each add16, 16 full adders (module add1, not provided) are instantiated to actually perform the addition. You must write the full adder module that has the following declaration:

module add1 ( input a, input b, input cin, output sum, output cout );

Recall that a full adder computes the sum and carry-out of a+b+cin.

module top_module (input [31:0] a,input [31:0] b,output [31:0] sum
);//wire   [15:0] out1;wire   [15:0] out2;wire cout_cin;add16 instance1(.a(a[15:0]) ,  .b(b[15:0]) ,  .cin(1'd0) ,     .cout(cout_cin) , .sum(out1));add16 instance2(.a(a[31:16]) , .b(b[31:16]) , .cin(cout_cin) , .sum(out2));assign sum = {out2 , out1};endmodulemodule add1 ( input a, input b, input cin,   output sum, output cout );assign sum = a ^ b ^ cin;assign cout = (a&b) | (a&cin) | (b&cin);endmodule

8、Carry-select adder

Problem Statement:

In this exercise, you are provided with the same module add16 as the previous exercise, which adds two 16-bit numbers with carry-in and produces a carry-out and 16-bit sum. You must instantiate three of these to build the carry-select adder, using your own 16-bit 2-to-1 multiplexer.

Connect the modules together as shown in the diagram below. The provided module add16 has the following declaration:

module add16 ( input[15:0] a, input[15:0] b, input cin, output[15:0] sum, output cout );

module top_module(input  [31:0] a,input  [31:0] b,output [31:0] sum
);wire [15:0] out1;wire [15:0] out2;wire [15:0] out3;wire [15:0] out4;wire sel;add16 instance1(.a(a[15:0])  , .b(b[15:0])  , .cin(1'b0) , .sum(out1) , .cout(sel));add16 instance2(.a(a[31:16]) , .b(b[31:16]) , .cin(1'b0) , .sum(out2));add16 instance3(.a(a[31:16]) , .b(b[31:16]) , .cin(1'b1) , .sum(out3));always@(*) begincase(sel)1'b0 : out4 = out2;1'b1 : out4 = out3;endcaseendassign sum = {out4 , out1};endmodule

9、Adder-subtractor

Problem Statement:

You are provided with a 16-bit adder module, which you need to instantiate twice:

module add16 ( input[15:0] a, input[15:0] b, input cin, output[15:0] sum, output cout );

Use a 32-bit wide XOR gate to invert the b input whenever sub is 1. (This can also be viewed as b[31:0] XORed with sub replicated 32 times. Also connect the sub input to the carry-in of the adder.

module top_module(input  [31:0] a,input  [31:0] b,input  sub,output [31:0] sum
);wire   [15:0] out1;wire   [15:0] out2;wire   [31:0] b_sub;wire          cout_cin;assign b_sub = b ^ {32{sub}};add16 instance1(.a(a[15:0]) , .b(b_sub[15:0]) , .cin(sub) , .sum(out1) , .cout(cout_cin));add16 instance2(.a(a[31:16]) , .b(b_sub[31:16]) , .cin(cout_cin) , .sum(out2));assign sum = {out2 , out1};endmodule

Verilog练习:HDLBits笔记4相关推荐

  1. Verilog HDL 学习笔记3-Latch

    Verilog HDL 学习笔记3-Latch 第一次接触Latch是在大二学习数电的时候,那时候Latch被翻译成锁存器,当时还纠结着锁存器和寄存器的区别(要是当时我知道他俩的英文名叫latch和r ...

  2. Verilog HDL程序笔记2

    Verilog HDL程序笔记2 Verilog HDL程序笔记1:写出属于你的第一个Verilog HDL模块 文章目录 Verilog HDL程序笔记2 前言 一.如何测试模块? 1.仿真平台 2 ...

  3. Verilog HDL 学习笔记2-blocking and non-blocking assignment

    2013年5月6日 10:42:38 Verilog HDL 学习笔记2-blocking and non-blocking assignment ---学习贵在总结,将学习的心得体会记录 在学习ve ...

  4. Verilog练习:HDLBits笔记15

    四.Sequential Logic Finite State Machines 1.Simple FSM 1(asynchronous reset) Problem Statement: This ...

  5. Verilog HDL学习笔记

    目录 1 硬件描述语言简介 1.1 概述 1.2 HDL语言特点 2 程序的基本语法 2.1 Verilog HDL 程序结构 2.1 Verilog HDL 程序规则 模块 连续赋值语句assign ...

  6. verilog学习 | HDLBits:在线学习答案

    HDLBits 在提供 Verilog 基础语法教程的同时,还能够在线仿真 Verilog 模块. 以下是各单元解法答案.希望可以帮助您了解 Verilog 的工作原理. 前言 HDLBits 在提供 ...

  7. 初学Verilog语言基础笔记整理(实例点灯代码分析)持续更新~

    实例:点灯学习 一.Verilog语法学习 1. 参考文章 刚接触Verilog,作为一个硬件小白,只能尝试着去理解,文章未完-持续更新. 参考博客文章: Verilog语言入门学习(1) Veril ...

  8. [笔记][原创]Verilog HDL语法分析笔记

         这篇帖子用于记录学习Verilog过程中的一些syntax的问题,会不断更新,有不正确的地方请各位帮忙指正:D 一.Verilog 语法中的可综合性 Verilog HDL 真的很强大,如果 ...

  9. Verilog HDL学习笔记(一)常见错误

    我初学verilog语言,很多细节都没注意,按着自己的思想就写了,编译的时候才发现各种问题.这些都是我在学习中遇到的问题,还是很常见的. 1.Error (10028): Can't resolve ...

  10. 自己整理的:学习verilog DHL问题笔记——Quartus常见错误

    我初学verilog语言,很多细节都没注意,按着自己的思想就写了,编译的时候才发现各种问题.这些都是我在学习中遇到的问题,还是很常见的. 1.Error (10028): Can't resolve ...

最新文章

  1. 在存储过程中如何实现将ID列表字符串传入IN()
  2. php 处理raw数据,php以raw格式传递数据
  3. 单片机流星灯_51单片机拖尾灯实现
  4. input的值提交不上
  5. kubernetes1.8.4 安装指南 -- 9. calico
  6. android程序到处apk,导出已安装到手机中程序的apk文件
  7. 算法训练营 重编码_编码训练营适合您吗?
  8. 计算机内部运算的部件是什么意思,运算器是执行什么和什么运算的部件
  9. html5之input标签学习
  10. OpenStack回顾和展望-2018
  11. 中国各地区工业COD排放量面板数据(1998-2017年)
  12. 2021SC@SDUSC Zxing开源代码(十)Data Matrix二维码(三)
  13. Classification and Representation
  14. 腾讯高级工程师带你完整体验Node.js开发实战
  15. 一个有启发意义的故事
  16. 个人博客系统【项目篇】
  17. 关于采集插件的一些详细知识
  18. 树莓派3B+采用花生棒进行内网穿透,从拆箱到实现SSH远程控制与sftp简单远程文件上传下载
  19. endo BCN-OH具有良好的水溶性,CAS:1263166-90-0
  20. 3t硬盘分区 Linux win,大师为你解说3t硬盘分区【搞定步骤】_

热门文章

  1. 南卡租房之Park Circle
  2. 单片机2017福建省中职省赛_我院学子在2017年福建省合泰杯单片机应用设计竞赛中再获佳绩...
  3. 国内手机市场寒风持续,华为与OV竞争将更激烈
  4. 归去来兮辞 陶渊明
  5. @Deprecated
  6. 12306订票候补是个坑_12306候补购票好几天了都没兑现成功是不是凉凉了?
  7. 深度学习实例——Flappy Bird
  8. linux环境变量lang=c,设置linux环境变量LANG
  9. 怎样搭建serveru ftp个人服务器
  10. 2.1.1队列——雏形(初始版本)