校招Verilog——串並轉換和並串轉換


一、串並轉換

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM