当前位置:网站首页>【Verilog】HDLBits题解——验证:阅读模拟
【Verilog】HDLBits题解——验证:阅读模拟
2022-08-03 12:10:00 【wjh776a68】
Finding bugs in code
Mux
题目链接
module top_module (
input sel,
input [7:0] a,
input [7:0] b,
output [7:0] out );
assign out = ({
8{
sel}} & a) | ({
8{
~sel}} & b);
endmodule
NAND
题目链接
module top_module (input a, input b, input c, output out);//
wire out_reverse;
andgate inst1 (out_reverse, a, b, c, 1, 1);
assign out = ~out_reverse;
endmodule
Mux
题目链接
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, mux1;
mux2 mux2_0 ( sel[0], a, b, mux0 );
mux2 mux2_1 ( sel[0], c, d, mux1 );
mux2 mux2_2 ( sel[1], mux0, mux1, out );
endmodule
Add/Sub
题目链接
// 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))
result_is_zero = 1;
else
result_is_zero = 0;
end
endmodule
Case Statement
题目链接
module top_module (
input [7:0] code,
output reg [3:0] out,
output reg valid=1 );//
always @(*)
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 out <= 0; valid <= 0; end
endcase
endmodule
Build a circuit from a simulation waveform
Combinational circuit 1
题目链接
module top_module (
input a,
input b,
output q );//
assign q = a & b; // Fix me
endmodule
Combinational circuit 2
题目链接
module top_module (
input a,
input b,
input c,
input d,
output q );//
assign q = ~(a ^ b ^ c ^ d); // Fix me
endmodule
Combinational circuit 3
题目链接
module top_module (
input a,
input b,
input c,
input d,
output q );//
assign q = (c | d) & (a | b); // Fix me
endmodule
Combinational circuit 4
题目链接
module top_module (
input a,
input b,
input c,
input d,
output q );//
assign q = c | b; // Fix me
endmodule
Combinational circuit 5
题目链接
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 );
reg [3:0] q_reg;
assign q = q_reg;
always @ (*) begin
case(c)
0: q_reg = b;
1: q_reg = e;
2: q_reg = a;
3: q_reg = d;
default: q_reg = 'hf;
endcase
end
endmodule
Combinational circuit 6
题目链接
module top_module (
input [2:0] a,
output [15:0] q );
reg [15:0] q_reg;
assign q = q_reg;
always @ (*) begin
case(a)
0: q_reg = 'h1232;
1: q_reg = 'haee0;
2: q_reg = 'h27d4;
3: q_reg = 'h5a0e;
4: q_reg = 'h2066;
5: q_reg = 'h64ce;
6: q_reg = 'hc526;
7: q_reg = 'h2f19;
endcase
end
endmodule
Sequential circuit 7
题目链接
module top_module (
input clk,
input a,
output q );
always @ (posedge clk) begin
q <= ~a;
end
endmodule
Sequential circuit 8
题目链接
module top_module (
input clock,
input a,
output p,
output q );
reg q_reg = 0;
reg p_reg = 0;
assign p = p_reg;
assign q = q_reg;
always @ (*) begin
if(clock)
p_reg <= a;
end
always @ (negedge clock) begin
q_reg <= a;
end
endmodule
Sequential circuit 9
题目链接
module top_module (
input clk,
input a,
output [3:0] q );
reg [3:0] q_reg;
assign q = q_reg;
always @ (posedge clk) begin
if (a) begin
q_reg <= 4;
end
else begin
q_reg <= (q_reg + 1) % 7;
end
end
endmodule
Sequential circuit 10
题目链接
module top_module (
input clk,
input a,
input b,
output q,
output state );
reg state_reg;
assign state = state_reg;
assign q = a ^ b ^ state;
always @ (posedge clk) begin
state_reg <= (a & b) | (a & state_reg) | (b & state_reg);
end
endmodule
边栏推荐
- dataset数据集有哪些_数据集类型
- R语言ggplot2可视化:使用patchwork包的plot_layout函数将多个可视化图像组合起来,ncol参数指定行的个数、byrow参数指定按照行顺序排布图
- Vs Shortcut Keys---Explore Different Programming
- 【Verilog】HDLBits题解——Circuits/Sequential Logic/Latches and Flip-Flops
- 小身材有大作用——光模块基础知识(一)
- 一个扛住 100 亿次请求的红包系统,写得太好了!!
- Matlab学习13-图像处理之可视化GUI程序
- 别再用if-else了,分享一下我使用“策略模式”的项目经验...
- R语言绘制时间序列的自相关函数图:使用acf函数可视化时间序列数据的自相关系数图
- LyScript 实现对内存堆栈扫描
猜你喜欢
随机推荐
距LiveVideoStackCon 2022 上海站开幕还有3天!
微信为什么使用 SQLite 保存聊天记录?
智能日报脚本
pandas连接oracle数据库并拉取表中数据到dataframe中、筛选当前时间(sysdate)到一天之前的所有数据(筛选一天范围数据)
JUC(三):锁核心类AQS ing
Go 语言快速入门指南: 介绍及安装
4500字归纳总结,一名软件测试工程师需要掌握的技能大全
Vs Shortcut Keys---Explore Different Programming
面试突击71:GET 和 POST 有什么区别?
R语言使用ggpubr包的ggtexttable函数可视化表格数据(直接绘制表格图或者在图像中添加表格数据)、使用tab_add_vline函数自定义表格中竖线(垂直线)的线条类型以及线条粗细
零拷贝、MMAP、堆外内存,傻傻搞不明白...
长城简漫·暑期安全篇⑤ 这个强,不能逞
thymeleaf中的日期格式转化
肝完Alibaba这份面试通关宝典,我成功拿下今年第15个Offer
ThreadLocal源码解析及使用场景
技术总监需要会些什么?也太难了!
最牛逼的集群监控系统,它始终位列第一!
第四课 标识符、关键字、变量、变量的分类和作用域、常量
LeetCode-142. 环形链表 II
基于SSM和Web实现的农作物生长监控系统