2021年6月25日 星期五

HDLBits 4-bit shift register

 HDLBits   4-bit shift register

4-bit shift register(Shift4)

Build a 4-bit shift register (right shift), with asynchronous reset, synchronous load, and enable.
  • areset: Resets shift register to zero.
  • load: Loads shift register with data[3:0] instead of shifting.
  • ena: Shift right (q[3] becomes zero, q[0] is shifted out and disappears).
  • q: The contents of the shift register.
    If both the load and ena inputs are asserted (1), the load input has higher priority.
module top_module(
    input clk,
    input areset,  // async active-high reset to zero
    input load,
    input ena,
    input [3:0] data,
    output reg [3:0] q); 
    always@(posedge clk or posedge areset)begin
        if(areset)begin
           q <= 'd0; 
        end
        else if(load)begin
           q <= data; 
        end
        else if(ena)begin
            q <= {1'd0,q[3:1]};
        end
    end
endmodule

沒有留言:

張貼留言

2026 作業1 MQTT基本觀念

 2026 作業1MQTT基本觀念 作業  參考下面網址 https://alex9ufoexploer.blogspot.com/2025/02/1-mqtt-relay-dht22-mqtt-box-pc-mymqtt.html https://alex9ufoexploer...