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
相关推荐
闪闪发亮的小星星15 分钟前
卫星通信、主要业务类型、组成
笔记
十月的皮皮39 分钟前
C语言学习笔记20260612-菱形图案打印(两种写法)
c语言·笔记·学习
FPGA小徐1 小时前
FPGA 电赛信号叠加与分离项目 完整工程包
fpga开发
chase。1 小时前
【学习笔记】RIGVid:通过模仿生成视频实现机器人操作,无需物理演示
笔记·学习·音视频
c7691 小时前
【文献笔记】Learn to Relax with LLMs: Solving COPs via Bidirectional Coevolution
论文阅读·人工智能·笔记·语言模型·论文笔记·提示工程
FPGA小徐1 小时前
FPGA在做信号处理相比cpu的优势对比
fpga开发
Szime1 小时前
AD9218国产替代方向:双通道10位105MSPS ADC深智微科技选型经验
fpga开发
江鸟的坚持1 小时前
xilinx xadc 例化
fpga开发·xadc·xilinx xadc
Bnews1 小时前
买家电一对一的定制服务推荐:2026年618期间的专业选择指南
经验分享·笔记
佛系豪豪吖1 小时前
AtomCode 部署流程与使用经验
笔记·chatgpt·github·ai编程·gitcode