【HDLBits 刷题 2】Verilog Language(2)Vectors 部分

这篇具有很好参考价值的文章主要介绍了【HDLBits 刷题 2】Verilog Language(2)Vectors 部分。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

目录

写在前面

Vectors

Vector0

Vector1

Vector2

Vectorgates

Gates4

Vector3

Vectorr

 Vector4

Vector5


写在前面

来到了 Verilog 语法的矢量部分,这部分仍然比较简单,所以只给出题目、代码和仿真结果,其他不多赘述。

Vectors

Vector0

构建一个具有一个3位输入的电路,然后输出相同的矢量,并将其拆分为三个单独的1位输出。将输出连接到输入向量的位置 0、位置 1 等。在图表中,旁边带有数字的刻度线表示矢量(或“总线”)的宽度,而不是为矢量中的每个位绘制一条单独的线。  

module top_module ( 
    input wire [2:0] vec,
    output wire [2:0] outv,
    output wire o2,
    output wire o1,
    output wire o0  ); // Module body starts after module declaration

assign outv = vec;
assign o2 = vec[2];
assign o1 = vec[1];
assign o0 = vec[0];

endmodule

仿真波形

hdlbits答案,Verilog,fpga开发,Verilog,硬件描述语言,数字IC,编程

Vector1

向量的字节序(或者非正式地称为“方向”)是最低有效位的索引较低(小端序,例如[3:0])还是较高的索引(大端序,例如[0:3])。在 Verilog 中,一旦以特定的字节序声明向量,就必须始终以相同的方式使用它。例如,在声明时写作是非法的。与字节序保持一致是很好的做法,因为如果分配或一起使用具有不同字节序的向量,则会发生奇怪的错误。

构建一个组合电路,将输入半字(16 位,[15:0])拆分为较低的[7:0]和较高的[15:8]字节

module top_module( 
    input wire [15:0] in,
    output wire [7:0] out_hi,
    output wire [7:0] out_lo );

assign out_hi = in[15:8];
assign out_lo = in[7:0];

endmodule

仿真波形

hdlbits答案,Verilog,fpga开发,Verilog,硬件描述语言,数字IC,编程

Vector2

32 位向量可以被视为包含 4 个字节(位 [31:24]、[23:16] 等)。构建一个电路,该电路将反转 4 字节字的字节顺序。

AaaaaaaaBbbbbbbbCcccccccDddddddd => DdddddddCcccccccBbbbbbbbAaaaaaaa

当一段数据的字节顺序需要交换时,例如在小端 x86 系统和许多 Internet 协议中使用的大端格式之间,通常使用此操作。

module top_module( 
    input wire [15:0] in,
    output wire [7:0] out_hi,
    output wire [7:0] out_lo );

    assign out[31:24] = in[7:0];
    assign out[23:16] = in[15:8];
    assign out[15:8] = in[23:16];
    assign out[7:0] = in[31:24];

endmodule

仿真波形

hdlbits答案,Verilog,fpga开发,Verilog,硬件描述语言,数字IC,编程

Vectorgates

构建一个具有两个 3 位输入的电路,该输入计算两个向量的按位 OR、两个向量的逻辑 OR 以及两个向量的反 (NOT)。将 的反函数放在 的上半部分(即位 [5:3]),将 的反函数放在下半部分。

module top_module( 
    input [2:0] a,
    input [2:0] b,
    output [2:0] out_or_bitwise,
    output out_or_logical,
    output [5:0] out_not
);

assign out_or_bitwise = a | b;
assign out_or_logical = a || b;
assign out_not[5:3] = ~b;
assign out_not[2:0] = ~a;

endmodule

仿真波形

hdlbits答案,Verilog,fpga开发,Verilog,硬件描述语言,数字IC,编程

Gates4

构建一个具有四个输入的组合电路,在[3:0]中。
有 3 个输出:

  • .out_and:输出4路输入AND门。
  • .out_or:4输入OR门的输出。
  • .out_xor:输出4路输入异或门。
module top_module( 
    input [3:0] in,
    output out_and,
    output out_or,
    output out_xor
);
assign out_and = ∈
assign out_or = |in;
assign out_xor = ^in;

endmodule

波形仿真

hdlbits答案,Verilog,fpga开发,Verilog,硬件描述语言,数字IC,编程

Vector3

位拼接符
给定几个输入向量,将它们连接在一起,然后将它们拆分为多个输出向量。
有六个 5 位输入向量:a、b、c、d、e 和 f,总共 30 位输入。有四个 8 位输出向量:w、x、y 和 z,用于 32 位输出。输出应是输入向量的串联,后跟两个1 。

module top_module (
    input [4:0] a, b, c, d, e, f,
    output [7:0] w, x, y, z );

    wire [31:0]   combine;
    assign combine = {a,b,c,d,e,f,{2'b11}};
    assign w = combine[31:24];
    assign x = combine[23:16];
    assign y = combine[15:8];
    assign z = combine[7:0];
    
endmodule

 波形仿真

hdlbits答案,Verilog,fpga开发,Verilog,硬件描述语言,数字IC,编程

Vectorr

给定一个 8 位输入向量 [7:0],反转其位排序。

module top_module( 
    input [7:0] in,
    output [7:0] out
);

assign out = {in[0],in[1],in[2],in[3],in[4],in[5],in[6],in[7]};

endmodule

仿真波形

hdlbits答案,Verilog,fpga开发,Verilog,硬件描述语言,数字IC,编程

 Vector4

构建一个对 8 位数字进行签名扩展到 32 位的电路。
这需要将符号位的24个副本(即复制位[7]24次)连接起来,然后是8位数字本身。  

module top_module (
    input [7:0] in,
    output [31:0] out );

    assign out = {{24{in[7]}},in};

endmodule

无仿真波形

hdlbits答案,Verilog,fpga开发,Verilog,硬件描述语言,数字IC,编程

Vector5

给定五个 1 位信号(a、b、c、d 和 e),计算 25 位输出向量中的所有 25 个成对 1 位比较。如果要比较的两个位相等,则输出应为 1。 
out[24] = ~a ^ a;   // a == a, so out[24] is always 1.
out[23] = ~a ^ b;
out[22] = ~a ^ c;
 ...
out[ 1] = ~e ^ d;
out[ 0] = ~e ^ e;

  • 顶部向量是每个输入的 5 个重复的串联
  • 底部矢量是 5 个输入串联的 5 个重复
module top_module (
    input a, b, c, d, e,
    output [24:0] out );

assign out = {{~{5{a}}^{a,b,c,d,e}},{~{5{b}}^{a,b,c,d,e}},
{~{5{c}}^{a,b,c,d,e}},{~{5{d}}^{a,b,c,d,e}},{~{5{e}}^{a,b,c,d,e}}};

endmodule

无仿真波形

hdlbits答案,Verilog,fpga开发,Verilog,硬件描述语言,数字IC,编程文章来源地址https://www.toymoban.com/news/detail-730407.html

到了这里,关于【HDLBits 刷题 2】Verilog Language(2)Vectors 部分的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • HDLBits自学笔记3:Verilog language.Modules Hierarchy

    在顶层模块中实例化模块 mod_a ,其端口描述: module mod_a ( input in1, input in2, output out ); 在顶层模块中按信号位置实例化模块 mod_a ,其端口描述: module mod_a ( output, output, input, input, input, input ); 在顶层模块中按信号名实例化 mod_a ,其端口描述: module mod_a ( output out1, output out2,

    2024年02月12日
    浏览(25)
  • HDLBits-Verilog学习记录 | Verilog Language-Modules(1)

    practice:You may connect signals to the module by port name or port position. For extra practice, try both methods. 两种方法: 1、You may connect signals to the module by port name 注:mod_a的端口与top_module的输入输出端口顺序一致,按照位置从左到右适配 2、port position 注:这里直接将两者进行绑定 practice: Thi

    2024年02月11日
    浏览(28)
  • Verilog刷题[hdlbits] :Module add

    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 (assu

    2024年02月06日
    浏览(33)
  • verilog学习 | HDLBits:在线学习答案

    HDLBits 在提供 Verilog 基础语法教程的同时,还能够在线仿真 Verilog 模块。 以下是各单元解法答案。希望可以帮助您了解 Verilog 的工作原理。 HDLBits 在提供 Verilog 基础语法教程的同时,还能够在线仿真 Verilog 模块。 ⚠️ 注意:顶层的模块名称和端口名称 top_module 不能更改,否

    2024年02月16日
    浏览(25)
  • HDLbits 刷题 -- Alwaysblock2

    学习: For hardware synthesis, there are two types of always blocks that are relevant: Combinational: always @(*) Clocked: always @(posedge clk) Clocked always blocks create a blob of combinational logic just like combinational always blocks, but also creates a set of flip-flops (or \\\"registers\\\") at the output of the blob of combinational logic. Instea

    2024年04月09日
    浏览(31)
  • 【HDLBits 刷题 5】Circuits(1)Combinational Logic

    目录 写在前面 Combinational Logic Basic Gates Wire GND NOR Another gate Two gates More logic gates 7420 chips Truth table Two bit equality Simple circuit A Simple circuit B Combine circuits A and B Ring or vibrate Thermostat 3 bit population count Gates and vectors Even longer vectors Multiplexers 2 to 1 mux 2 to 1 bus mux 9 to 1 mux 256 to 1 mux 256 t

    2024年02月02日
    浏览(26)
  • hdlbits系列verilog解答(always块if语句)-31

    if 语句通常创建一个 2 对 1 多路复用器,如果条件为 true,则选择一个输入,如果条件为 false,则选择另一个输入。 always @(*) begin if (condition) begin out = x; end else begin out = y; end end 这等效于使用带有条件运算符的连续赋值: assign out = condition ? (x : y); 使用if语句不当时会产生不想

    2024年02月06日
    浏览(28)
  • hdlbits系列verilog解答(8位宽移位寄存器)-24

    这项练习是module_shift移位寄存器的延伸。模块端口不是只有单个引脚,我们现在有以向量作为端口的模块,您将在其上附加线向量而不是普通线网数据。与 Verilog 中的其他位置一样,端口的向量长度不必与连接到它的导线匹配,但这会导致向量的零填充或截断。本练习不使用

    2024年02月08日
    浏览(22)
  • Verilog单边沿检测和双边沿检测的方法(HDLBits例题)

    1.单边沿检测 边沿检测是用来检测某一信号是否发送了从0至1或者从1至0的变化,有同步和异步之分。 同步边沿检测:是使用一个基准时钟,即在同一个时钟下来检测一个信号的上升沿或者下降沿。 异步边沿检测:是利用D触发器来实现边沿检测。 HDLBits例题: 单边沿检测例题

    2024年02月11日
    浏览(29)
  • verilog1 HDLbits:12 hour clock(12小时计时器)

    HDL bit -12 hour clock题目地址 翻译:创建一组适合用作 12 小时制的计数器。计数器由一个快速运行的 clk 计时,每当时钟增加(即每秒一次)时,ena 就会有一个脉冲。 reset 将时钟重置为凌晨 12:00。pm 为 0 表示 AM,1 表示 PM。 hh、mm 和 ss 是两个 BCD(二进制编码十进制)数字,分别表示

    2024年02月19日
    浏览(28)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包