1、
创建一个16D触发器,有时我们仅需要修改部分触发器中的值。字节使能信号控制当前时钟周期中16个寄存器中哪个字节需被修改。byteena[1]控制高字节d[15:8],而byteena[0]控制低字节d[7:0]。
resetn是一个同步,低复位信号。
所有的D触发器由时钟的上升沿触发。
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)
begin
q<=16'd0;
end
else
begin
case (byteena)
2'b00:q<=q;
2'b01:q<={q[15:8],d[7:0]};
2'b10:q<={d[15:8],q[7:0]};
2'b11:q<=d;
endcase
end