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
相关推荐
LeeAmos16 分钟前
Addendum No. 1 to JESD209-4 Low Power Double Data Rate 4X (LPDDR4X)的中文版
笔记
Zebros1 小时前
LC无线无源传感器读取方案设计研究综述
fpga开发·信息与通信·射频工程
国科安芯2 小时前
商业航天通信载荷数字处理单元供电架构研究——基于ASP7A84AS的高精度低压差线性稳压器技术分析
前端·单片机·嵌入式硬件·fpga开发·架构·安全性测试
Ab_stupid2 小时前
CTF-WEB培训笔记
笔记·web
逸模2 小时前
逸模 VS CAD+SU系列(二)施工图:告别手动改图,全专业图纸自动生成
笔记·其他·cad·su·施工图
Ab_stupid3 小时前
CTF-Android培训笔记
android·笔记
chushiyunen3 小时前
高斯数据库笔记、gaussDb
数据库·笔记
小杰~3 小时前
【个人笔记】VuePress Theme Plume 主题全解析 + 快速上手教程
笔记
whyTeaFo3 小时前
MIT 6.1810: xv6 book Chapter7: Locking 笔记
笔记
Szime4 小时前
AD9653 国产替代怎么选?四通道 16 位 125MSPS ADC 选型参考
嵌入式硬件·fpga开发