EDITORIAL words
Fight operator bit is a plurality of small expressions are merged to form a large expression, the symbol {} to achieve a plurality of arithmetic expressions are connected, each with between expression "," separated. Sleeper bit fight operator is particularly like a wing senior operator, it Cong Huiling Xiu, not only simple data stitching, but can be used to perform a shift operation, and the data is always circular, is not lost, use very extensive.
Code examples
/**************************************************** * Engineer: Dream Brother Wing * QQ : 761664056 * The module function: bit concatenation operator module *****************************************************/ 01 module shift(clk,rst_n,led_out); 02 the INPUT CLK ; // system input 03 the INPUT rst_n ; // reset 04 05 Output REG [ . 3 : 0 ] led_out ; // LED drive port 06 07 always@(posedge clk or negedge rst_n) 08 begin 09 if(!rst_n) 10 begin Led_out. 11 <= 4'b0111 ; // make one of the lamps is lit 12 end 13 else 14 begin Led_out 15 <= { led_out [ 0 ], led_out [ . 3 : . 1 ]}; // achieve water lights 16 end 17 end 18 endmodule |
Write test code as follows
/**************************************************** * Engineer: Dream Brother Wing * QQ : 761664056 * The module function: bit concatenation operator test module *****************************************************/ 01 `timescale 1ns/1ps 02 module tb; 03 reg clk; 04 reg rst_n; 05 06 wire [3:0]led_out; 07 08 initial 09 begin 10 clk=0; 11 rst_n=0; 12 # 1000.1 rst_n=1; 13 end 14 15 always #10 clk=~clk; 16 17 shift shift( 18 .clk(clk), 19 .rst_n(rst_n), 20 .led_out(led_out) 21 ); 22 endmodule |
查看仿真波形如下:
从仿真图可以看出,每个时钟周期,0都会向右移动一位。到最右边时就会放返回最左边继续循环,使用拼位的运算符,在很多场合-如串并转换等,会使代码编写变得简单。
代码的意思是,每次把最低位放到最高位,让前三位放到后面,这样逻辑就实现了移位,形成了循环。