Verilog刷题笔记42

题目:Create 16 D flip-flops. It's sometimes useful to only modify parts of a group of flip-flops. The byte-enable inputs control whether each byte of the 16 registers should be written to on that cycle. byteena[1] controls the upper byte d[15:8], while byteena[0] controls the lower byte d[7:0].

resetn is a synchronous, active-low reset.

All DFFs should be triggered by the positive edge of clk.

解题:

bash 复制代码
module top_module (
    input clk,
    input resetn,
    input [1:0] byteena,
    input [15:0] d,
    output [15:0] q
);
    always@(posedge clk)begin
        if(resetn==0)
            q<=16'b0;
        else if(byteena[1]|byteena[0])begin
            if(byteena[0]==1)
            	q[7:0]<=d[7:0];
        	if(byteena[1]==1)
            	q[15:8]<=d[15:8];
        end
    end
            
endmodule

结果正确:

其他解题方法:

bash 复制代码
module top_module (
    input clk,
    input resetn,
    input [1:0] byteena,
    input [15:0] d,
    output [15:0] q
);
 
always @(posedge clk) begin
	if(!resetn)
		q <= 16'd0;
	else begin
		case(byteena)
			2'b00: q <= q;
			2'b01: q[7:0] <= d[7:0];
			2'b10: q[15:8] <= d[15:8];
			2'b11: q <= d;
		endcase
	end	
end
endmodule
相关推荐
荆白雪3 小时前
触摸按键控制LED
fpga开发
sealaugh324 小时前
AI(学习笔记第十二课) 使用langsmith的agents
人工智能·笔记·学习
QZ_orz_freedom4 小时前
学习笔记--事务管理
笔记·学习
程序员大雄学编程5 小时前
「机器学习笔记14」集成学习全面解析:从Bagging到Boosting的Python实战指南
笔记·机器学习·集成学习
im_AMBER5 小时前
Web 开发 30
前端·笔记·后端·学习·web
试试勇气6 小时前
Linux学习笔记(八)--环境变量与进程地址空间
linux·笔记·学习
蒙奇D索大6 小时前
【数据结构】考研数据结构核心考点:平衡二叉树(AVL树)详解——平衡因子与4大旋转操作入门指南
数据结构·笔记·学习·考研·改行学it
郭庆汝7 小时前
自然语言处理笔记
笔记·自然语言处理·easyui
二进制怪兽7 小时前
[笔记] 驱动开发:Virtual-Display-Driver编译过程
笔记
ouliten7 小时前
cuda编程笔记(28)-- cudaMemcpyPeer 与 P2P 访问机制
笔记·cuda