Sure, here’s an example of a 4-bit parallel-in, serial-out (PISO) shift register implemented using SystemVerilog:
module piso_shift_register_4bit( input logic [3:0] parallel_in, input logic clock, input logic reset, output logic serial_out ); logic [3:0] shift_reg; always_ff @(posedge clock) begin if (reset) begin shift_reg <= 4'b0000; end else begin shift_reg <= {parallel_in, shift_reg[3:1]}; end end assign serial_out = shift_reg[0]; endmodule
In this code, we define a module called `piso_shift_register_4bit` with three input ports `parallel_in`, `clock`, and `reset`, and one output port `serial_out`. The `parallel_in` input is a 4-bit binary value to be loaded into the shift register, the `clock` input is a single-bit binary value representing the clock signal, and the `reset` input is a single-bit binary value representing the reset signal. The `serial_out` output is a single-bit binary value representing the output of the shift register.
The `shift_reg` signal is a 4-bit binary value representing the contents of the shift register.
Inside the `always_ff` block, we use an if-else statement to describe the behavior of the shift register. If `reset` is asserted, the shift register is reset to 0. Otherwise, the shift register is updated by shifting the contents of the register one bit to the left and loading the `parallel_in` value into the least significant bit position.
The `assign` statement is used to assign the value of the least significant bit of `shift_reg` to the `serial_out` output, which represents the output of the shift register.
You can instantiate this module in your top-level design hierarchy and connect it to other modules or input/output signals as needed. Note that you can modify the code to implement a shift register with a different number of bits by changing the bit width of the input and output signals, and modifying the shift register logic accordingly.