端口大小与连接大小不匹配

时间:2013-11-19 15:42:14

标签: cpu mips verilog system-verilog

我已经写了代码

Alu.v

module ALU(
    src1_i,
    src2_i,
    src3_i,
    src4_i,
    ctrl_i,
    result_o,
    zero_o
    );

//I/O ports
input  [32-1:0]  src1_i;
input  [32-1:0]  src2_i;
input  [4-1:0]   src3_i;//shmat is 5 bits instruction[10:6]
input  [15-1:0]  src4_i;//ori have to deal with 'zero-extended' number
input  [4-1:0]   ctrl_i;

output [32-1:0]  result_o;
output           zero_o;

//Internal signals
reg    [32-1:0]  result_o;
wire             zero_o;

//Parameter
assign zero_o = (result_o == 0);
//Main function
always @(*) begin
    case(ctrl_i)
        0 :result_o <= src1_i & src2_i;//and
        1 :result_o <= src1_i | src2_i;//or
        2 :result_o <= src1_i + src2_i;//add
        6 :result_o <= src1_i - src2_i;//substract
        7 :result_o <= src1_i < src2_i ? 1 : 0;//set less than
        10:result_o <= ~(src1_i - src2_i);//not the result for bne
        11:result_o <= (src1_i |  {16'b0000000000000000, src4_i});//ori
        12:result_o <= ~(src1_i | src2_i);//nor
        13:result_o <= src2_i << 16;//lui
        14:result_o <= src2_i << src1_i;//sllv
        15:result_o <= src2_i << src3_i;//sll
        default:result_o <= 0;//default
    endcase
end
endmodule

和其他模块

Simple_Single_CPU.v .....

ALU ALU(
        .src1_i(RSdata_o),
        .src2_i(reg_mux_data_o),
            .src3_i(instr_o[10:6]),
            .src4_i(instr_o[15:0]),
        .ctrl_i(ALUCtrl_o),
        .result_o(result_o),
        .zero_o(zero_o)
        );

............

我已经检查过端口大小和连接端口大小是否正确,但它会给我一个类似的警告

# ** Warning: (vsim-3015) C:/Users/lypan/Downloads/Lab2/Lab2/code/Simple_Single_CPU.v(116): [PCDPC] - Port size (4 or 4) does not match connection size (5) for port 'src3_i'. The port definition is at: C:/Users/lypan/Downloads/Lab2/Lab2/code/ALU.v(15).
# 
#         Region: /TestBench/cpu/ALU
# ** Warning: (vsim-3015) C:/Users/lypan/Downloads/Lab2/Lab2/code/Simple_Single_CPU.v(116): [PCDPC] - Port size (15 or 15) does not match connection size (16) for port 'src4_i'. The port definition is at: C:/Users/lypan/Downloads/Lab2/Lab2/code/ALU.v(16).
# 
#         Region: /TestBench/cpu/ALU

我无法弄清楚如何解决它。

你可以提前给我一些指导。

1 个答案:

答案 0 :(得分:2)

警告是正确的。

在模块ALU中,您有此声明:

input  [4-1:0]   src3_i;//shmat is 5 bits instruction[10:6]

这将src3_i的宽度设置为4,因为4-1 = 3,3:0是4位。

但是,在Simple_Single_CPU.v中,你有:

         .src3_i(instr_o[10:6]),

这将5位信号(instr_o [10:6])连接到4位端口(src3_i)。

您必须确定信号是真的应该是4位还是5位。例如,如果您想要5位,请使用:

input  [5-1:0]   src3_i;//shmat is 5 bits instruction[10:6]