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
相关推荐
齐生15 天前
iOS 知识点 - 渲染机制、动画、卡顿小集合
笔记
用户962377954485 天前
VulnHub DC-1 靶机渗透测试笔记
笔记·测试
齐生16 天前
iOS 知识点 - IAP 是怎样的?
笔记
tingshuo29177 天前
D006 【模板】并查集
笔记
tingshuo29178 天前
S001 【模板】从前缀函数到KMP应用 字符串匹配 字符串周期
笔记
西岸行者13 天前
学习笔记:SKILLS 能帮助更好的vibe coding
笔记·学习
ZPC821013 天前
docker 镜像备份
人工智能·算法·fpga开发·机器人
ZPC821013 天前
docker 使用GUI ROS2
人工智能·算法·fpga开发·机器人
starlaky13 天前
Django入门笔记
笔记·django
勇气要爆发13 天前
吴恩达《LangChain LLM 应用开发精读笔记》1-Introduction_介绍
笔记·langchain·吴恩达