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
相关推荐
三贝勒文子1 小时前
Synopsys 逻辑综合之 MultiBit Flip-Flop 与 ICG
fpga开发·eda·synopsys
潇-xiao1 小时前
进程状态 + 进程优先级切换调度-进程概念(5)
linux·笔记
骁的小小站1 小时前
HDLBits刷题笔记和一些拓展知识(十一)
开发语言·经验分享·笔记·其他·fpga开发
njsgcs2 小时前
ParaCAD 笔记 png 图纸标注数据集
笔记
Andy杨2 小时前
20250710-2-Kubernetes 集群部署、配置和验证-网络组件存在的意义?_笔记
网络·笔记·kubernetes
DKPT4 小时前
Java设计模式之行为型模式(责任链模式)介绍与说明
java·笔记·学习·观察者模式·设计模式
崔高杰4 小时前
微调性能赶不上提示工程怎么办?Can Gradient Descent Simulate Prompting?——论文阅读笔记
论文阅读·人工智能·笔记·语言模型
KhalilRuan5 小时前
Unity Demo——3D平台跳跃游戏笔记
笔记·游戏·unity·游戏引擎
MUTA️6 小时前
《MAE: Masked Autoencoders Are Scalable Vision Learners》论文精读笔记
人工智能·笔记·深度学习·transformer
使一颗心免于哀伤7 小时前
《设计模式之禅》笔记摘录 - 6.原型模式
笔记·设计模式