Tengo un verilog como módulo me sale el error
Error (10137): Verilog HDL Procedural Assignment error object "result" on
left-hand side of assignment must have a variable data type
Si agrego también reg [31:0] result;
, recibo otro error
Error (10028): Can't resolve multiple constant
drivers for net "tempreg[0][31]" at mips_core_testbench.v(55)
.
.
.
.
Error (10028): Can't resolve multiple constant
drivers for net "tempreg[0][14]" at mips_core_testbench.v(55)
Error (12153): Can't elaborate top-level user hierarchy
Código:
module testbench (result, input_instruction, rs_content, rt_content);
output [31:0] result;
//reg [31:0] result;
input [31:0] input_instruction;
input [31:0] rs_content;
input [31:0] rt_content;
reg [31:0] tempreg [0:31];
integer type;
integer i;
initial begin
tempreg[0] = 1;
for (i = 1; i <= 31; i = i + 1)
tempreg[i] <= 0;
end
always@ (input_instruction) begin
if(input_instruction[31:26] == 6'b000000)
type = 1; // R-type
else
type = 0; // I-type
end
always@ (type) begin
case(input_instruction[5:0])
//add
6'b100000:
tempreg[input_instruction[15:11]] = tempreg[input_instruction[25:21]] + tempreg[input_instruction[20:16]];
//sub
6'b100010:
tempreg[input_instruction[15:11]] = tempreg[input_instruction[25:21]] - tempreg[input_instruction[20:16]];
//and
6'b100100:
tempreg[input_instruction[15:11]] = tempreg[input_instruction[25:21]] & tempreg[input_instruction[20:16]];
//or
6'b100101:
tempreg[input_instruction[15:11]] = tempreg[input_instruction[25:21]] | tempreg[input_instruction[20:16]];
//sra
6'b000011:
tempreg[input_instruction[15:11]] = tempreg[input_instruction[20:16]] >>> input_instruction[10:6];
//srl
6'b000010:
tempreg[input_instruction[15:11]] = tempreg[input_instruction[20:16]] >> input_instruction[10:6];
//sll
6'b000010:
tempreg[input_instruction[15:11]] = tempreg[input_instruction[20:16]] << input_instruction[10:6];
//sltu------
//6'b101011:
endcase
end
always@ (!type) begin
case(input_instruction[31:26])
//addi
6'b001000:
tempreg[input_instruction[20:16]] = tempreg[input_instruction[25:21]] + tempreg[input_instruction[15:0]];
//addiu----
//6'b001001:
//andi
6'b001100:
tempreg[input_instruction[20:16]] = tempreg[input_instruction[25:21]] & tempreg[input_instruction[15:0]];
//ori
6'b001101:
tempreg[input_instruction[20:16]] = tempreg[input_instruction[25:21]] | tempreg[input_instruction[15:0]];
//slti
6'b001010:
begin
if (tempreg[input_instruction[15:0]] - tempreg[input_instruction[25:21]] > 0 )
tempreg[input_instruction[20:16]] = 1;
else
tempreg[input_instruction[20:16]] = 0;
end
//lui
6'b001111:
tempreg[input_instruction[20:16]] = tempreg[input_instruction[15:0]] << 16'b0;
endcase
end
always @(type or tempreg[input_instruction[15:11]] or tempreg[input_instruction[20:16]])
begin
if (type == 1)
result <= tempreg[input_instruction[15:11]];
else
result <= tempreg[input_instruction[20:16]];
end
endmodule
Código editado:
module testbench (result, input_instruction, rs_content, rt_content);
output reg[31:0] result;
input [31:0] input_instruction;
input [31:0] rs_content;
input [31:0] rt_content;
reg [31:0] tempreg [0:31];
integer type;
integer i;
initial begin
tempreg[0] = 1;
for (i = 1; i <= 31; i = i + 1)
tempreg[i] = 0;
end
always@ (input_instruction) begin
if(input_instruction[31:26] == 6'b000000)
type = 1; // R-type
else
type = 0; // I-type
end
always @ * begin
if (type) begin
case (input_instruction[5:0])
//add
6'b100000:
tempreg[input_instruction[15:11]] = tempreg[input_instruction[25:21]] + tempreg[input_instruction[20:16]];
//sub
6'b100010:
tempreg[input_instruction[15:11]] = tempreg[input_instruction[25:21]] - tempreg[input_instruction[20:16]];
//and
6'b100100:
tempreg[input_instruction[15:11]] = tempreg[input_instruction[25:21]] & tempreg[input_instruction[20:16]];
//or
6'b100101:
tempreg[input_instruction[15:11]] = tempreg[input_instruction[25:21]] | tempreg[input_instruction[20:16]];
//sra
6'b000011:
tempreg[input_instruction[15:11]] = tempreg[input_instruction[20:16]] >>> input_instruction[10:6];
//srl
6'b000010:
tempreg[input_instruction[15:11]] = tempreg[input_instruction[20:16]] >> input_instruction[10:6];
//sll
6'b000010:
tempreg[input_instruction[15:11]] = tempreg[input_instruction[20:16]] << input_instruction[10:6];
//sltu------
//6'b101011:
endcase
end else begin
case (input_instruction[31:26])
//addi
6'b001000:
tempreg[input_instruction[20:16]] = tempreg[input_instruction[25:21]] + tempreg[input_instruction[15:0]];
//addiu----
//6'b001001:
//andi
6'b001100:
tempreg[input_instruction[20:16]] = tempreg[input_instruction[25:21]] & tempreg[input_instruction[15:0]];
//ori
6'b001101:
tempreg[input_instruction[20:16]] = tempreg[input_instruction[25:21]] | tempreg[input_instruction[15:0]];
//slti
6'b001010:
begin
if (tempreg[input_instruction[15:0]] - tempreg[input_instruction[25:21]] > 0 )
tempreg[input_instruction[20:16]] = 1;
else
tempreg[input_instruction[20:16]] = 0;
end
//lui
6'b001111:
tempreg[input_instruction[20:16]] = tempreg[input_instruction[15:0]] << 16'b0;
endcase
end
end
always @(type or tempreg[input_instruction[15:11]] or tempreg[input_instruction[20:16]])
begin
if (type == 1)
result = tempreg[input_instruction[15:11]];
else
result = tempreg[input_instruction[20:16]];
end
endmodule