dff with byte enable

1 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].
2 
3 resetn is a synchronous, active-low reset.
4 
5 All DFFs should be triggered by the positive edge of clk.

Dff16e - HDLBits (01xz.net)

 1 module top_module (
 2     input clk,
 3     input resetn,
 4     input [1:0] byteena,
 5     input [15:0] d,
 6     output [15:0] q
 7 );
 8     always @(posedge clk) begin
 9         if(resetn) begin
10             if(byteena[1])
11                 q[15:8] <= d[15:8];
12             else
13                 q[15:8] <= q[15:8];
14             if(byteena[0])
15                 q[7:0] <= d[7:0];
16             else
17                 q[7:0] <= q[7:0];
18         end
19         else begin
20             q <= 16'd0;
21         end
22     end
23 
24 endmodule

 额,当时好喜欢先写主体,后写!resetn,也不知道是怎么想的

posted @ 2023-04-25 12:31  江左子固  阅读(29)  评论(0)    收藏  举报