Advertisement
1WaKa_WaKa1

shift_reg

Apr 6th, 2023
819
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1ns / 1ps
  2.  
  3. module shift_reg(
  4.     input clk,
  5.     input reset,
  6.     input enable,
  7.     input mux_load,
  8.     input[31:0] inp,
  9.     output reg s_out
  10. );
  11.  
  12. reg[31:0] shifted_reg;
  13. wire[31:0] shifted_next_value;
  14. assign shifted_next_value = (mux_load) ? inp : shifted_reg >> 1;
  15. always @(posedge reset) begin
  16.     if (reset) begin
  17.             shifted_reg <= 0;
  18.             s_out <= shifted_reg[0];
  19.     end
  20. end
  21.  
  22. always @(posedge clk) begin
  23.     if (mux_load) begin
  24.             shifted_reg <= inp;
  25.     end else begin
  26.             shifted_reg <= shifted_next_value;
  27.     end
  28.     if (enable) begin
  29.             s_out <= shifted_reg[0];
  30.     end
  31. end
  32. endmodule
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement