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 小时前
NIOS ii工程移植路径问题
fpga开发·nios ii
程序员Xu6 小时前
【LeetCode热题100道笔记】二叉树的右视图
笔记·算法·leetcode
程序员Xu7 小时前
【LeetCode热题100道笔记】二叉搜索树中第 K 小的元素
笔记·算法·leetcode
DKPT7 小时前
JVM中如何调优新生代和老生代?
java·jvm·笔记·学习·spring
我真的是大笨蛋10 小时前
K8S-基础架构
笔记·云原生·容器·kubernetes
程序员Xu13 小时前
【LeetCode热题100道笔记】腐烂的橘子
笔记·算法·leetcode
IT199513 小时前
Wireshark笔记-DHCP两步交互流程与数据解析
网络·笔记·wireshark
ST.J13 小时前
SQL与数据库笔记
数据库·笔记·sql
肥肠可耐的西西公主13 小时前
后端(JDBC)学习笔记(CLASS 1):基础篇(一)
笔记·学习
悠哉悠哉愿意15 小时前
【数学建模学习笔记】无监督聚类模型:分层聚类
笔记·python·学习·数学建模