串并转换和并串转换

一、串并转换

module left_shifter_reg
(
input               clk     ,
input               rst_n   ,
input               din     ,
output  reg [7:0]   dout
);

always @(posedge clk or negedge rst_n) begin
    if(!rst_n)
        dout <= 8'b0;
    else
        dout <= {dout[6:0], din};
end  

endmodule

二、并串转换

module right_shifter_reg
(
input               clk         ,
input               rst_n       ,
input       [7:0]   din         ,
input               din_vld     ,
output              dout
);

reg     [7:0]       shift       ;  

always @(posedge clk or negedge rst_n) begin  
    if(!rst_n)
        shift <= 8'b0;
    else if(din_vld) //将值寄存住
        shift <= din;
    else
        shift <= {shift[0], shift[7:1]}; //不断右移
end  

assign dout = shift[0];//不断输出


endmodule

参考资料:https://blog.csdn.net/Reborn_Lee

原文地址:https://www.cnblogs.com/xianyufpga/p/13520155.html