1
module Rotator(shift,lr,in,out);

input [3:0]  shift;
input [15:0] in;
input   [15:0] out;
input lr;

wire [15:0] la, ra, lb,rb, lc,rc, ld,rd;

//left shift:2^n

assign la = shift[0] ? { in[14:0],in[15]} : in; //<<1
assign lb = shift[1] ? { la[13:0],la[15:14]} : la; //<<2
assign lc = shift[2] ? { lb[11:0],lb[15:12]}: lb; //<<4
assign ld = shift[3] ? { lc[7:0], lc[15:8]}:lc; //<<8

//right shift:2^n

assign ra = shift[0]? { in[0], in[15:1]}: in;  //>>1
assign rb = shift[1]? { ra[1:0], in[15:2]}: ra; //>>2
assign rc = shift[2]? { rb[3:0], in[15:4]}: rb; //>>4
assign rd = shift[3]? { rc[7:0], in[15:8]}:rc; //>>8

assign out = lr? ld : rd;

endmodule

我正在尝试制作 16b 桶式旋转器。但结果不会随着移位值而改变,我认为我强调的部分是问题。请给我建议

4

1 回答 1

3

out needs to be defined as output, currently at input. Some simulators/fpgas can be very strict on the enforcing the direction of the port, most will give a warning.

FYI, there is a bug in the assignments for rb, rc and rd. They are referencing in and should be using ra, rb and rc respectively.

Working fixed example: http://www.edaplayground.com/s/6/332

于 2013-11-05T19:39:02.500 回答