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. byteena1 controls the upper byte d15:8, while byteena0 controls the lower byte d7: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
相关推荐
晓梦林8 小时前
BUUCTF findKey-学习笔记
笔记·学习
x173880627310 小时前
XXE外部实体注入
xml·笔记
库玛西15 小时前
C++ 运行时多态 :核心总结与原理图解
c语言·c++·笔记
魔力女仆16 小时前
语言开发笔记3
笔记
x173880627316 小时前
文件包含漏洞介绍
笔记
一只小菜鸡..19 小时前
南京大学 操作系统 (JYY) 学习笔记:CPU 的局限、GPU 与 AI 时代的算力革命
人工智能·笔记·学习
所愿ღ20 小时前
SSM框架-Spring3
java·开发语言·笔记·spring
影视飓风TIM21 小时前
C++ STL 完整入门笔记[8]:deque 底层原理深度剖析
开发语言·c++·笔记
辰丁电子21 小时前
PCB设计:EMMC设计规范
fpga开发·pcb设计·pcb工艺·layout·pcb layout
优化Henry21 小时前
5G站点软件错误告警与资源激活超时两类典型告警分析与处理
网络·笔记·学习·5g·信息与通信