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
相关推荐
智者知已应修善业5 小时前
【求中位数】2024-1-23
c语言·c++·经验分享·笔记·算法
张人玉6 小时前
百度 AI 图像识别 WinForms 应用代码分析笔记
人工智能·笔记·百度
xqqxqxxq6 小时前
背单词软件技术笔记(V1.0核心版及V2.0随机挖字母)
笔记
YJlio7 小时前
Active Directory 工具学习笔记(10.8):AdInsight——保存与导出(证据留存、共享与二次分析)
数据库·笔记·学习
xqqxqxxq8 小时前
背单词软件技术笔记(V2.0扩展版)
java·笔记·python
yuxb738 小时前
Kubernetes核心组件详解与实践:controller
笔记·kubernetes
受之以蒙10 小时前
Rust 与 dora-rs:吃透核心概念,手把手打造跨语言的机器人实时数据流应用
人工智能·笔记·rust
2401_8345170710 小时前
AD学习笔记-36 gerber文件输出
笔记·学习
hhhhhhh_hhhhhh_10 小时前
TC3x7-DEMO-V1.0原理图自学笔记
笔记
气π10 小时前
【JavaWeb】——(若依 + AI)-基础学习笔记
java·spring boot·笔记·学习·java-ee·mybatis·ruoyi