ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Verilog练习:HDLBits笔记3

2021-10-30 17:31:06  阅读:272  来源: 互联网

标签:wire module HDLBits 笔记 Verilog input output assign out


二、Verilog Language

Vectors 

1、Vectors

Problem Statement:

Build a circuit that has one 3-bit input, then outputs the same vector, and also splits it into three separate 1-bit outputs. Connect output o0 to the input vector's position 0,o1 to position 1, etc.

Vector0.png

module top_module ( 
    input wire [2:0] vec,
    
    output wire [2:0] outv,
    output wire o2,
    output wire o1,
    output wire o0  
); 
    assign outv = vec;
    assign o2 = outv[2];
    assign o1 = outv[1];
    assign o0 = outv[0];

endmodule

2、Vectors in more details

Problem Statement: 

 Build a combinational circuit that splits an input half-word (16 bits, [15:0] ) into lower [7:0] and upper [15:8] bytes.

`default_nettype none     // Disable implicit nets. Reduces some types of bugs.
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

 3、Vector part select

Problem Statement: 

A 32-bit vector can be viewed as containing 4 bytes (bits [31:24], [23:16], etc.). 

Build a circuit that will reverse the byte ordering of the 4-byte word.

module top_module( 
    input  [31:0] in,
    output [31:0] out 
);
    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

4、Bitwise operators

Problem Statement: 

 Build a circuit that has two 3-bit inputs that computes the bitwise-OR of the two vectors, the logical-OR of the two vectors, and the inverse (NOT) of both vectors. Place the inverse of b in the upper half of out_not (i.e., bits [5:3]), and the inverse of a in the lower half.

Vectorgates.png

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 = ~{b,a};

endmodule

 5、Four-input gates

Problem Statement: 

Build a combinational circuit with four inputs, in[3:0].

There are 3 outputs:

  • out_and: output of a 4-input AND gate.
  • out_or: output of a 4-input OR gate.
  • out_xor: output of a 4-input XOR gate.
module top_module( 
    input [3:0] in,
    output out_and,
    output out_or,
    output out_xor
);
    assign out_and = & in[3:0];
    assign out_or  = | in[3:0];
    assign out_xor = ^ in[3:0];

endmodule

 


 

标签:wire,module,HDLBits,笔记,Verilog,input,output,assign,out
来源: https://blog.csdn.net/WinstonQQM/article/details/121052543

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有