Shift Register(Using Submodule)

來源:互聯網
上載者:User

標籤:io   os   ar   sp   c   on   log   amp   r   

/***************************************************

/  Shift Register module by Submodule

/  Programing by seongki

***************************************************/

module Shift_Register_4_str(output [3:0] A_par,input [3:0] I_par,input s1,s0,MSB_in,LSB_in,CLK,Clear);

wire [1:0] select;

assign select = {s1,s0};

 

stage ST0(I_par[0],I_par[1],LSB_in,I_par[0],A_par[0],select,CLK,Clear);

stage ST1(I_par[1],I_par[2],I_par[0],I_par[1],A_par[1],select,CLK,Clear);

stage ST2(I_par[2],I_par[3],I_par[1],I_par[2],A_par[2],select,CLK,Clear);

stage ST3(I_par[3],MSB_in,I_par[2],I_par[3],A_par[3],select,CLK,Clear);

endmodule

 

module stage(i0,i1,i2,i3,Q,select,CLK,Clr);

input i0,i1,i2,i3, CLK,Clr;

output Q;

input [1:0] select;

wire mux_out;

Mux_4x_1 M0(mux_out,i0,i1,i2,i3,select);

D_flip_flop M1(Q,mux_out,CLK,Clr);

endmodule

 

module Mux_4x_1(mux_out,i0,i1,i2,i3,select);

output mux_out;

input i0,i1,i2,i3;

input [1:0] select;

reg mux_out;

[email protected](select,i0,i1,i2,i3)

case(select)

2‘b00:mux_out=i0;

2‘b01:mux_out=i1;

2‘b10:mux_out=i2;

2‘b11:mux_out=i3;

endcase

endmodule

 

module D_flip_flop(Q,D,CLK,Clr);

output Q;

input D,CLK,Clr;

reg Q;

[email protected](posedge CLK, negedge Clr)

if(~Clr) Q<=0;

else Q<=D;

endmodule

//testbench

`timescale 1ns/1ns

module tb_Shift_Register_Structural_model;

reg [3:0] I_par;

reg s1,s0,MSB_in,LSB_in,CLK,Clear;

wire [3:0] A_par;

 

Shift_Register_4_str test1(A_par,I_par,s1,s0,MSB_in,LSB_in,CLK,Clear);

 

initial

  begin

    I_par=4‘b1111;

    Clear=0; MSB_in=0; LSB_in=0; CLK=0; s1=0; s0=0;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

    #10 CLK=1;

 

    #10 Clear=1; MSB_in=0; LSB_in=0; CLK=0; s1=0; s0=0;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

    #10 CLK=1;

 

    #10 Clear=1; MSB_in=0; LSB_in=0; CLK=0; s1=0; s0=1;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

    #10 CLK=1;

 

    #10 Clear=1; MSB_in=0; LSB_in=0; CLK=0; s1=1; s0=0;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

    #10 CLK=1;

 

    #10 Clear=1; MSB_in=0; LSB_in=0; CLK=0; s1=1; s0=1;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

 

  end

endmodule

 

Shift Register(Using Submodule)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.