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
相关推荐
今儿敲了吗3 分钟前
面向对象(二)——UML基础
笔记·uml
sheeta199811 分钟前
Vue 前端基础笔记
前端·vue.js·笔记
哆哆啦0013 分钟前
obsidian远程同步方案:infiniCloud+remotely save方案
笔记·git·obsidian
咸鱼翻身小阿橙30 分钟前
Qt Quick 登录界面代码学习笔记
笔记·qt·学习
Brilliantwxx30 分钟前
【C++】priority_queue以及 仿函数 的学习
开发语言·c++·笔记·学习·算法
小+不通文墨39 分钟前
树莓派4b-wiringpi库的安装和使用
驱动开发·经验分享·笔记·嵌入式硬件·学习
小麦嵌入式1 小时前
FPGA入门(三):3-8 译码器 仿真波形解读
stm32·单片机·嵌入式硬件·mcu·fpga开发·硬件工程
xuhaoyu_cpp_java1 小时前
SpringMVC学习(三)
java·经验分享·笔记·学习·spring
学机械的鱼鱼1 小时前
【学习笔记】XTDrone2 目录结构说明
笔记·学习
05候补工程师2 小时前
【矩阵代数】伴随矩阵、逆矩阵与秩的逻辑关系全梳理
笔记·线性代数·考研·矩阵