HDLBits答案——Verification: Reading Simulations
1 Finding bugs in code
1.1 Bugs mux2
module top_module (
input sel,
input [7:0] a,
input [7:0] b,
output [7:0] out );
assign out = sel ? a:b;
endmodule
1.2 Bugs nand3
module top_module (input a, input b, input c, output out);//
wire out_0;
andgate inst1 (out_0, a, b, c, 1'b1 , 1'b1);
assign out = ~out_0;
endmodule
1.3 Bugs mux4
module top_module (
input [1:0] sel,
input [7:0] a,
input [7:0] b,
input [7:0] c,
input [7:0] d,
output [7:0] out ); //
wire [7:0] mux0;
wire [7:0] mux1;
mux2 U1 ( sel[0], a, b, mux0 );
mux2 U2 ( sel[0], c, d, mux1 );
mux2 U3 ( sel[1], mux0, mux1, out );
endmodule
1.4 Bugs addsubz
// synthesis verilog_input_version verilog_2001
module top_module (
input do_sub,
input [7:0] a,
input [7:0] b,
output reg [7:0] out,
output reg result_is_zero
);//
always @(*) begin
case (do_sub)
0: out <= a+b;
1: out <= a-b;
endcase
if (out==0)
result_is_zero = 1;
else
result_is_zero = 0;
end
endmodule
1.5 Bugs case
module top_module (
input [7:0] code,
output reg [3:0] out,
output reg valid );//
always @(*)begin
case (code)
8'h45:begin
out <= 0;
valid <= 1;
end
8'h16:begin
out <= 1;
valid <= 1;
end
8'h1e:begin
out <= 2;
valid <= 1;
end
8'h26:begin
out <= 3;
valid <= 1;
end
8'h25:begin
out <= 4;
valid <= 1;
end
8'h2e:begin
out <= 5;
valid <= 1;
end
8'h36:begin
out <= 6;
valid <= 1;
end
8'h3d:begin
out <= 7;
valid <= 1;
end
8'h3e:begin
out <= 8;
valid <= 1;
end
8'h46:begin
out <= 9;
valid <= 1;
end
default:begin
valid <= 0;
out <= 0;
end
endcase
end
endmodule
2 Build a circuit from a simulationwaveform
2.1 Sim/circuit1
module top_module (
input a,
input b,
output q );//
assign q = a&b; // Fix me
endmodule
2.2 Sim/circuit2
module top_module (
input a,
input b,
input c,
input d,
output q );//
assign q = ~a & ~b & ~c & ~d | ~a & ~b & c & d | ~a & b & ~c & d | ~a & b & c & ~d |
a & b & ~c & ~d | a & b & c & d | a & ~b & ~c & d | a & ~b & c & ~d;
endmodule
2.3 Sim/circuit3
module top_module (
input a,
input b,
input c,
input d,
output q );//
assign q = b & d | b & c | a & d | a & c; // Fix me
endmodule
2.4 Sim/circuit4
module top_module (
input a,
input b,
input c,
input d,
output q );//
assign q = b|c; // Fix me
endmodule
2.5 Sim/circuit5
module top_module (
input [3:0] a,
input [3:0] b,
input [3:0] c,
input [3:0] d,
input [3:0] e,
output [3:0] q );
always@(*)begin
case(c)
4'd0:q<=b;
4'd1:q<=e;
4'd2:q<=a;
4'd3:q<=d;
default:q<=4'hf;
endcase
end
endmodule
2.6 Sim/circuit6
module top_module (
input [2:0] a,
output [15:0] q );
always@(*)begin
case(a)
3'd0:q<=16'h1232;
3'd1:q<=16'haee0;
3'd2:q<=16'h27d4;
3'd3:q<=16'h5a0e;
3'd4:q<=16'h2066;
3'd5:q<=16'h64ce;
3'd6:q<=16'hc526;
3'd7:q<=16'h2f19;
endcase
end
endmodule
2.7 Sim/circuit7
module top_module (
input clk,
input a,
output q );
always@(posedge clk)begin
q <= ~a;
end
endmodule
2.8 Sim/circuit8
module top_module (
input clock,
input a,
output p,
output q );
always@(*)begin
if(clock)
p <= a;
else
p <= p;
end
always@(negedge clock)begin
q <= p;
end
endmodule
2.9 Sim/circuit9
module top_module (
input clk,
input a,
output [3:0] q );
always@(posedge clk)begin
if(a)begin
q <= 4'd4;
end
else if(q == 4'd6)begin
q <= 4'd0;
end
else begin
q <= q + 1'b1;
end
end
endmodule
2.10 Sim/circuit10
module top_module (
input clk,
input a,
input b,
output q,
output state );
always @(posedge clk) state <= state ? a|b : a&b;
assign q = a^b^state;
endmodule
HDLBits答案——Verification: Reading Simulations的更多相关文章
- Cracking Digital VLSI Verification Interview 第三章
目录 Programming Basics Basic Programming Concepts Object Oriented Programming Concepts UNIX/Linux Pro ...
- Greedy:Jessica's Reading Problem(POJ 3320)
Jessica's Reading Problem 题目大意:Jessica期末考试临时抱佛脚想读一本书把知识点掌握,但是知识点很多,而且很多都是重复的,她想读最少的连续的页数把知识点全部掌握(知识点 ...
- 解决Lost connection to MySQL server at 'reading initial communication packet', 的方法
今天用heidsql连接mysql时出了问题,提示:Lost connection to MySQL server at 'reading initial communication packet 网 ...
- Cummins INSITE locked and ask for verification code
Some Cummins INSITE users turn to our engineer with a same question: INSITE has detected an invalid ...
- 验证(Verification)与确认(Validation)的差别
验证(Verification)与确认(Validation)的差别 说法一: (2)“验证(Verification)”的涵义 通过提供客观证据对规定要求已得到满足的认定. (2)“确认(Valid ...
- c++ primer plus 习题答案(1)
c++ primer plus 习题答案用的是第五版,IDE仍然是vs2013.我只标注了题号,具体的题目找下书上对应内容吧. p110.8 #include<iostream> #inc ...
- 论文选读二:Multi-Passage Machine Reading Comprehension with Cross-Passage Answer Verification
论文选读二:Multi-Passage Machine Reading Comprehension with Cross-Passage Answer Verification 目前,阅读理解通常会给出 ...
- linux环境,通过rpm删除mysql包,报错:error reading information on service mysqld: Invalid argument
问题描述: 今天在做saltstack的练习,想要通过sls的方式,在远程进行mysql数据库的安装,发现无法通过service的方式启动数据库,然后就想给删除了重新进行安装,在通过rpm -e进行删 ...
- 200个最常见的JAVA面试问题(附答案)
本文内容: 20个最常见的JAVA面试问题(附答案) 13个单例模式JAVA面试问题(附答案) 说说JVM和垃圾收集是如何工作的(附答案) 说说如何避免JAVA线程死锁(附答案) Java中HashS ...
- nginx error: upstream prematurely closed connection while reading response header from upstream
本篇文章由:http://xinpure.com/nginx-error-upstream-prematurely-closed-connection-while-reading-response-h ...
随机推荐
- alter role 导致的数据库无法登录问题
ALTER ROLE 用于更改一个数据库角色.只要改角色后续开始一个新会话,指定的值将会成为该会话的默认值,并且会覆盖 kingbase.conf中存在的值或者从命令行收到的值. 显性的更改角色的一 ...
- Oracle PLM,协同研发的产品生命周期管理平台
官网:Oracle PLM - 方正璞华 适用企业:电子高科技.机械制造.医疗器械.化工行业等大型企业和中小型企业 咨询热线:4006-160-730 申请试用.预约演示.产品询价 邮箱:jiangc ...
- getch()之隐藏输入密码
getch() :读取字符且不会回显(不会显示):不从输入缓冲区读取:在getch中,把回车按键输入, 识别为回车符'\r':在getchar中,把回车按键输入,识别为回车符'\n'. getch() ...
- 图-kruskal算法,prim算法
要求无向图 最小生成树: 连通性,累加和最小 并查集 结构 K算法 从最小的边开始,加上有没有形成环,没有就加,加上有环就不要 难点:如何判断加上一条边,有没有形成环. P算法 从点的角度开始
- 防火墙:iptable和firewalld常用操作
iptables //安装iptables-service yum install iptables-services //编辑config文件 vi /etc/sysconfig/iptables ...
- 使用Prometheus和Grafana监控RabbitMQ集群 (使用RabbitMQ自带插件)
配置RabbitMQ集群 官方文档:https://www.rabbitmq.com/prometheus.html#quick-start 官方github地址:https://github.com ...
- Pixar 故事公式
文章转载自:https://mp.weixin.qq.com/s/wMfFVh9tAM5Qo4ED658yUg
- 洛谷P7167 [eJOI 2020 Day1] Fountain (单调栈+ST)
开两个数组:to[i][j]表示从i这个位置向下的第2j个圆盘是哪个,f[i][j]表示流满从i这个位置向下的 2j 个圆盘需要多少体积的水. 详情见代码: 1 #include<bits/st ...
- 洛谷P1719 最大加权矩形 (DP/二维前缀和)
题目描述也没啥好说的,就是给你个你n*n的矩形(带权),求其中最大权值的子矩阵. 首先比较好想的就是二维前缀和,n<=120,所以可以用暴力. 1 #include<bits/stdc++ ...
- vulnhub靶场|NAPPING: 1.0.1
准备: 攻击机:虚拟机kali.本机win10. 靶机:NAPPING: 1.0.1,地址我这里设置的桥接,,下载地址:https://download.vulnhub.com/napping/nap ...