assign waddr_gray[ADDR_WDTH:0]=waddr[ADDR_WDTH:0] ^ {1’b0,waddr[ADDR_WDTH:1] };
//写法 1
assign bin_code[0]=gray_code[0]^gray_code[1]^gray_code[2]^gray_code[3] ;
assign bin_code[1]=gray_code[1]^gray_code[2]^gray_code[3] ;
assign bin_code[2]=gray_code[2]^gray_code[3] ;
assign bin_code[3]=gray_code[3] ;
//写法2
assign bin_code = {gray_code[3], ^gray_code[3:2], ^gray_code[3:1], ^gray_code};
//写法3:
function [ADDR_WIDTH:0] bin_out;
input [ADDR_WIDTH:0] gray_in;
reg [ADDR_WIDTH:0] gray_code;
reg [ADDR_WIDTH:0] bin_code;
integer i,j;
reg tmp;
begin
gray_code = gray_in;
0;i<=ADDR_WIDTH;i=i+1) =
begin
tmp=1'b0;
i;j<=ADDR_WIDTH;j=j+1) =
tmp=gray_code[j]^tmp;
tmp; =
end
bin_out= bin_code;
end
endfunction