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
相关推荐
M78佐菲8 小时前
Linux学习笔记:TCP协议
linux·笔记·学习·tcp/ip·算法
噜~噜~噜~9 小时前
操作系统笔记-2.3.5.1.1生产者-消费者问题
笔记·操作系统
Huathy-雨落江南,浮生若梦13 小时前
Caddy 学习笔记 - 反向代理与 IP 封禁
笔记·学习·tcp/ip
谢白羽14 小时前
SGLang的AWQ量化笔记
笔记·python·sglang
噜~噜~噜~15 小时前
操作系统笔记-2.3.5.2 读者-写者问题
笔记·操作系统
MindUp16 小时前
企业私有化文件管理系统选型实录:从部署架构到AI能力的技术调研笔记
人工智能·笔记·架构
GGMM78916 小时前
西门子BOP20基本操作面板超详细教程(S120/G130专用)
笔记·变频器·变频器维修
cmc102817 小时前
292.三段式状态机第三段时序逻辑用state_c与_n的差异分析
fpga开发
一条破秋裤17 小时前
TIM 输入捕获与 PWMI:从边沿到频率、占空比
笔记·stm32·学习
知产xiao_xin17 小时前
知识产权入门 —— 工业品外观设计
经验分享·笔记·知识产权