HDLBits-移位寄存器
数字移位
算术右移(左侧补最高位,也就是“符号位”),左移没有区别。下文依次是左移 1,左移 8,右移 1,右移 8。
注意左移的时候符号位也一样补全。
module top_module(input clk,input load,input ena,input [1:0] amount,input [63:0] data,output reg [63:0] q); always @(posedge clk) beginif (load) beginq <= data;end else beginif (ena) begincase(amount)2'b00: q <= {q[62:0], 1'b0};2'b01: q <= {q[55:0], 8'b0};2'b10: q <= {q[63], q[63:1]};2'b11: q <= {{8{q[63]}}, q[63:8]}; default: ;endcaseendelse beginendendend
endmodule