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
相关推荐
xian_wwq40 分钟前
【学习笔记】攻击链贯穿端边云!边缘网络访问三大核心风险预警
笔记·学习·安全·边缘计算
深蓝海拓4 小时前
PySide6从0开始学习的笔记(一) 学前班
笔记·学习
s09071364 小时前
Xilinx FPGA使用 FIR IP 核做匹配滤波时如何减少DSP使用量
算法·fpga开发·xilinx·ip core·fir滤波
shipship--4 小时前
htb academy笔记-module-Password Attacks(五)
笔记
智行众维5 小时前
【用户心得】SCANeR™Studio学习笔记(六):人因工程Pack——一站式搞定驾驶模拟的多模态数据同步
笔记·学习·自动驾驶·汽车·仿真·scaner·人因工程
xian_wwq5 小时前
【学习笔记】基于人工智能的火电机组全局性能一体化优化研究
人工智能·笔记·学习·火电
阿蒙Amon6 小时前
JavaScript学习笔记:6.表达式和运算符
javascript·笔记·学习
大筒木老辈子6 小时前
C++笔记---并发支持库(atomic)
java·c++·笔记
Cricyta Sevina6 小时前
Java Collection 集合进阶知识笔记
java·笔记·python·collection集合
IMPYLH6 小时前
Lua 的 Coroutine(协程)模块
开发语言·笔记·后端·中间件·游戏引擎·lua