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
相关推荐
菜菜子爱学习1 小时前
Nginx学习笔记(九)—— Nginx Rewrite深度解析
linux·运维·笔记·学习·nginx
Always_away3 小时前
数学分析| 极限论| 1.数列极限常用方法总结
笔记·学习·考研·数学
霜绛4 小时前
Unity:GUI笔记(一)——文本、按钮、多选框和单选框、输入框和拖动条、图片绘制和框绘制
笔记·学习·unity·游戏引擎
草莓熊Lotso5 小时前
《吃透 C++ 类和对象(中):拷贝构造函数与赋值运算符重载深度解析》
开发语言·c++·经验分享·笔记·其他
饕餮争锋6 小时前
设计模式笔记_结构型_门面模式
笔记·设计模式
鸢栀w7 小时前
前端css学习笔记5:列表&表格&背景样式设置
前端·css·笔记·学习
阿群今天学习了吗7 小时前
label studio 服务器端打开+xshell端口转发设置
linux·运维·服务器·笔记·python
17岁的勇气7 小时前
Unity Shader unity文档学习笔记(十九):粘土效果,任意网格转化成一个球(顶点动画,曲面着色器)
笔记·学习·unity·图形渲染·顶点着色器·曲面着色器
Hello_Embed9 小时前
STM32HAL 快速入门(六):GPIO 输入之按键控制 LED
笔记·stm32·单片机·嵌入式硬件·学习
奶黄小甜包9 小时前
C语言零基础第16讲:内存函数
c语言·笔记·学习