Barrel shifter are used in signal processors to eliminate the problems of overflow, by scaling the input and output. This scaling is done by shifting the word to the left or to the right. Shifting the word to left is equal to multiplication by 2, where as right shifting a word is equivalent to division by 2.
If a number is shifted "n" times to the left, then it is equivalent to multiplication by 2^(n), and vice versa. In barrel shifting process the input word is shifted to right to prevent the overflow which might occur due to any arithmetic operation. After this the final answer is shifted back to the left .
Below given is a verilog module code for a barrel shifter implementation for an eight bit word.
module barrel_shifter (data_out, data_in, load, clk, reset);output [7:0] data_out;input [7:0] data_in;input load, clk, reset;reg [7:0] data_out;always @ (posedge reset or posedge clk)if (reset = 1'b1) data_out<= 8'b0;else if (load) data_out<= data_in;else data_out<= {data_out[6:0], data_out[7]};endendmodule
0 comments:
Post a Comment