Verilog实现移位寄存器
生活随笔
收集整理的這篇文章主要介紹了
Verilog实现移位寄存器
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Verilog實(shí)現(xiàn)8位環(huán)形移位寄存器
左移: 環(huán)形就是首尾相連
module shift_regist (input wire clk,input wire rstn,input wire [7:0]D,output reg [7:0]Q ); always @(posedge clk or negedge rstn) beginif(!rstn)Q<=8'b000000;elseQ<={D[6:0],D[7]} ; end endmodule //shift_regist右移:
module shift_regist (input wire clk,input wire [7:0]D,input wire rstn,output reg [7:0]Q ); always @(posedge clk ) beginif(!rstn)Q<=8'b000000;elseQ<={D[0],D[7:1]} ; end endmodule //shift_regist普通的移位寄存器用for語句實(shí)現(xiàn):
module shift_regist2(Q,D,rst,clk);output [7:0] Q;input D,rst,clk;reg [7:0] Q;integer i; always @(posedge clk)if (!rst) Q<=8'b000000;elsefor (i=7;i>0;i=i-1)beginQ[i]<=Q[i-1]; Q[0]<=D;end endmodule普通左移:
//8 bit shift register module shift_regist(input d,input rstn,input clk,output reg [7:0]q );always@(posedge clk or negedge rstn)beginif(!rstn)q <=8'b0;elseq <={q[6:0],d};end endmoduletb測(cè)試:
module tb;reg d,rstn,clk;wire [7:0]q;shift_regist u_shift(d,rstn,clk,q);initial beginrstn=0;clk=0;#5rstn=1;endalways #5 clk=~clk;initial begind=0;#10 d=0; //00#10 d=1; //001#10 d=1; //0011#10 d=0; //00110#10 d=0;#10 d=1;#10 d=1;#10 d=0;#10 d=1;#10 $finish;end endmodule圖形分析:
雙向shift:就是加個(gè)判斷
always@(posedge clk)beginif(dir==0)sf<={sf[2:0],din};elsesf<={din,sf[3:1]}; end總結(jié)
以上是生活随笔為你收集整理的Verilog实现移位寄存器的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 品优购商城项目常见BUG解析
- 下一篇: MongoDB之增删改查全套语法锦囊⭐️