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
相关推荐
jackson凌2 小时前
【Java学习笔记】SringBuffer类(重点)
java·笔记·学习
huangyuchi.3 小时前
【Linux】LInux下第一个程序:进度条
linux·运维·服务器·笔记·进度条·c/c++
大写-凌祁4 小时前
论文阅读:HySCDG生成式数据处理流程
论文阅读·人工智能·笔记·python·机器学习
Unpredictable2224 小时前
【VINS-Mono算法深度解析:边缘化策略、初始化与关键技术】
c++·笔记·算法·ubuntu·计算机视觉
傍晚冰川5 小时前
FreeRTOS任务调度过程vTaskStartScheduler()&任务设计和划分
开发语言·笔记·stm32·单片机·嵌入式硬件·学习
Love__Tay6 小时前
【学习笔记】Python金融基础
开发语言·笔记·python·学习·金融
半导体守望者7 小时前
ADVANTEST R3764 66 R3765 67爱德万测试networki connection programming网络程序设计手册
经验分享·笔记·功能测试·自动化·制造
hahaha60167 小时前
Xilinx 325T FPGA 中的 GT(GTP 或 GTX)收发器和普通 LVDS 接口的差模和共模电压
fpga开发
柠石榴7 小时前
【论文阅读笔记】《A survey on deep learning approaches for text-to-SQL》
论文阅读·笔记·深度学习·nlp·text-to-sql
田梓燊8 小时前
数学复习笔记 27
笔记