赞
踩
module shiftregist
(data_out,clk,rst_n,load,data_load,ctr_shiftright,ctr_shiftleft,data_shiftright,data_shiftleft);
parameter shiftregist_width=4;
output [shiftregist_width-1:0] data_out;
input [shiftregist_width-1:0] data_load;
input load,clk,rst_n,ctr_shiftright,ctr_shiftleft,data_shiftright,data_shiftleft;
reg [shiftregist_width-1:0] data_out;
always @(posedge clk or negedge rst_n)
if (!rst_n)
data_out<=0;
else if (load) data_out<=data_load;
else if (ctr_shiftright)
data_out<={data_shiftright,data_out[shiftregist_width-1:1]};
else if (ctr_shiftleft)
data_out<={data_out[shiftregist_width-2:0],data_shiftleft};
else data_out<=data_out;
endmodule
module testbench_shiftregist;
parameter shiftregist_width=4;
reg [shiftregist_width-1:0] data_load;
reg load,clk,rst_n,ctr_shiftright,ctr_shiftleft,data_shiftright,data_shiftleft;
wire [shiftregist_width-1:0] data_out;
always
#5 clk=~clk;
initial begin data_load=0;load=0;rst_n=1;ctr_shiftright=0;ctr_shiftleft=0;clk=0;
data_shiftright=0;data_shiftleft=0; end
initial begin #10 rst_n=0;#3 rst_n=1;end
initial begin #15 load=1;data_load=4'b1010;#10 load=0; end
initial begin #30 ctr_shiftright=1;#20 data_shiftright=1;#20 ctr_shiftright=0;
#20 ctr_shiftleft=1;#25 data_shiftleft=1;#20 data_shiftleft=0; end
shiftregist U1 (.clk(clk),.rst_n(rst_n),.load(load),.ctr_shiftright(ctr_shiftright),
.ctr_shiftleft(ctr_shiftleft),.data_shiftright(data_shiftright),
.data_shiftleft(data_shiftleft),.data_load(data_load),.data_out(data_out));
endmodule
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。