
HDLBit练习
HDLBit的题目学习
闲庭信步sss
分享自己学习ic的知识
展开
-
HDLBit 生命游戏Conwaylife
题目:生命游戏这道题目是著名的康威生命游戏,一个中心点周围有8个邻居,如果周围的邻居中1的数目为0-1个,那么中心点变为0;如果周围邻居中1的数目为2个,那么中心点状态不变;如果周围邻居中1的数目为3个,中心点变为1;如果周围邻居中1的数目大于3个,中心点变为0。我们可以将周围的8个邻居的值都加起来来判断周围邻居中1的个数,但是直接做的话就要分很多情况讨论,比如边角,首行末行,首列末列,因此这里使用了一个巧妙地方法,先进行padding,提前把1616扩展成1818这样就方便计算了。module原创 2022-04-07 09:09:29 · 1736 阅读 · 0 评论 -
HDLBit 四位十进制BCD码计数器
题目:四位十进制BCD码计数器题目要求为输出一个16bit数,每四位为一个BCD码,从高位至低位每位BCD码分别为十进制的千位,百位,十位,个位。module top_module ( input clk, input reset, // Synchronous active-high reset output [3:1] ena, output [15:0] q); reg [3:0] ones; reg [3:0] tens; r原创 2022-04-06 17:37:17 · 2402 阅读 · 0 评论 -
HDLBit 触发器双沿检测
题目:双沿检测题目要求大概就是要在触发器上升沿和下降沿都能寄存输出数据,在always(posedge clk or negedge clk)是会报错的代码如下module top_module( input clk, input d, output q); reg p, n; // A positive-edge triggered flip-flop always @(posedge clk) p <= d ^ n; //原创 2022-04-06 15:18:34 · 458 阅读 · 0 评论 -
HDLBit Exams/ece241 2014 q3
题目:Exams/ece241 2014 q3module top_module ( input c, input d, output [3:0] mux_in); assign mux_in[0] = c ? 1'b1 : d; assign mux_in[1] = 1'b0; assign mux_in[2] = d ? 1'b0 : 1'b1; assign mux_in[3] = c ? d : 1'b0; /*原创 2022-04-05 17:07:53 · 1574 阅读 · 1 评论 -
HDLBit Mux256to1v
题目:Mux256to1很容易写成下面的写法,然后就报错了module top_module( input [1023:0] in, input [7:0] sel, output [3:0] out ); assign out = in[sel*4+3:sel*4];endmodule正确写法module top_module ( input [1023:0] in, input [7:0] sel, output [3:0] out); //原创 2022-04-05 11:36:54 · 407 阅读 · 0 评论 -
HDLBit 符号位扩展
题目:符号位扩展这题其实没啥好讲的,主要是总是忘了个括号。下面这个是错的,少了个大括号module top_module ( input [7:0] in, output [31:0] out );// // assign out = { replicate-sign-bit , the-input }; assign out = {24{in[7]},in};endmodule正确答案module top_module ( input [7:0]原创 2022-04-04 09:55:14 · 482 阅读 · 0 评论 -
HDLBit vector reverse
题目:向量反转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]}; endmodulemodule top_module( input [7:0] in, output [7:0] out); always @(*) begin for (int i原创 2022-04-04 09:43:47 · 251 阅读 · 0 评论 -
HDLBit练习 Cs450/timer
题目点这module top_module( input clk, input load, input [9:0] data, output tc); reg [9:0]data_r; always@(posedge clk)begin if(load)begin data_r <= data; end else if(data_r == 10'd0)begin原创 2022-04-02 10:37:50 · 854 阅读 · 0 评论 -
verilog 12小时时钟设计
题目来源于HDLBits大致意思是设计一个12小时的时钟,分为时 分 秒 ,每个单位又由两个bcd码组成,复位为12:00:00;且有pm信号输出,pm为1时为下午。代码如下:module top_module( input clk, input reset, input ena, output pm, output [7:0] hh, output [7:0] mm, output [7:0] ss); wire [4:0原创 2021-08-20 11:10:02 · 1730 阅读 · 1 评论 -
Verilog双边沿采样触发器 HDLBitDualedge
题目如下:我一开始想当然就这样写了module top_module ( input clk, input d, output q); always@(posedge clk) q <= d; always@(negedge clk) q <= d; endmodule结果报错,后面网上搜了一下,看了下这篇博文【 Verilog 】always@()的敏感源中为什么不能双原创 2021-08-17 16:17:09 · 3287 阅读 · 0 评论 -
HDLBit Edgedetect及触发器仿真的一些心得
先看题目其实简而言之就是检测输入数据从0到1的变化,若是检测到输入从0变化为1,则输出该位的对应位为1.解题思路是用到一个使用一个寄存器保存上个时钟输入的值,若上个时钟输入为0,当前时钟输入为1,则输出为1.module top_module ( input clk, input [7:0] in, output [7:0] pedge); wire [7:0] temp; always@(posedge clk)begin原创 2021-08-14 11:30:16 · 309 阅读 · 0 评论 -
HDLBit练习 Exams/ece241 2014 q1c有符号数溢出的判断
计算机中有符号数采用补码进行运算。溢出的判断1.在加法运算中,如果次高位(数值位最高位)相加形成进位,而最高位(符号位)相加(包括次高位的进位)却没有进位时,则结果溢出。或则相反,如果次高位无进位,而最高位有进位则结果溢出。2.在减法运算中,如果次高位不需要借位,而最高位需要借位,则结果溢出。或者相反,如果次高位需要借位,而最高位不需借位,则结果溢出。怎么理解呢:其实减法运算等价于加法运算,因此溢出只会发生在两个正数相加或者两个负数相加。而两个整数相加发生溢出时,次高位(数值位最高位)相加形成进位原创 2021-08-06 09:42:14 · 879 阅读 · 0 评论 -
HDLBits 练习 Mux256to1v
Mux256to1v题目要求:Create a 4-bit wide, 256-to-1 multiplexer. The 256 4-bit inputs are all packed into a single 1024-bit input vector. sel=0 should select bits in[3:0], sel=1 selects bits in[7:4], sel=2 selects bits in[11:8], etc.一开始我的写法:module top_module(原创 2021-08-04 21:05:11 · 1379 阅读 · 0 评论 -
HDLBits:在线学习 Verilog Bcdadd100
Bcdadd100*生成块的使用module top_module( input [399:0] a, b, input cin, output cout, output [399:0] sum ); wire [3:0] sum0; wire [99:0] cout100; bcd_fadd add1( .a(a[3:0]), .b(b[3:0]), ...原创 2021-08-04 11:36:52 · 1666 阅读 · 0 评论