Verilog错误:寄存器在连续赋值的左侧是非法的

Verilog错误:寄存器在连续赋值的左侧是非法的,verilog,Verilog,我是一名verilog noob,我必须为处理器执行此ALU,但我在这一行中得到以下错误: 分配SP_out=SP “连续赋值左侧的寄存器非法” 我用的是modelsim module ALU(opcode,ra,rb,ra_out,cin,co,res,rst,clk,pc,npc,CCRin,CCRo,SP,SP_out); output [1:0] res; // result input wire [7:0]pc; output reg [7:0] npc; input

我是一名verilog noob,我必须为处理器执行此ALU,但我在这一行中得到以下错误:

分配SP_out=SP

“连续赋值左侧的寄存器非法”

我用的是modelsim

module ALU(opcode,ra,rb,ra_out,cin,co,res,rst,clk,pc,npc,CCRin,CCRo,SP,SP_out);
  output [1:0] res; // result 
  input wire [7:0]pc;
  output reg [7:0] npc;
  input rst,clk;
  input wire cin;
  input wire [3:0] opcode;
  input wire[1:0] ra;
  input wire[1:0] rb;
  output reg[1:0] ra_out;
  input wire[7:0] SP; // testbench haygebli SP el mafroud yeb2a = 255
  output reg[7:0] SP_out;

  reg[255:0] dmem;

  input wire [3:0] CCRin;
  output reg [3:0] CCRo;
  output co;

  wire [2:0] result; //total result

  assign SP_out = SP;

  assign result = alu_out(ra,rb,cin); 
  assign res = result[1:0];
  assign co = result[2];



  function [2:0] alu_out;
   input [1:0] ra,rb;
   input cin;

  case (opcode)
    0: ;
    4: assign alu_out = ra + rb;
    5: assign alu_out = ra - rb;
    6: assign alu_out = ~(ra & rb);
    7: assign alu_out = {ra[1:0],cin};
    8: assign alu_out = {ra[0],cin,ra[1]};
    10: if (ra == 1)
          begin
         dmem[SP_out] = rb;
         SP_out = SP_out-1;
       end
     else
       begin
       SP_out = SP_out +1;
       rb = dmem[SP_out];
     end
    13: assign ra_out = rb;
    default: begin
    alu_out = 8'bxxxxxxxx; 
    npc = pc+1;


end
endcase 
endfunction
  always@( res)
   begin 
  if (res == 0)
     CCRo[0] = 1;
  else if ( res < 0)
   CCRo[1] = 1;
  else if (co == 1)
    CCRo[2] = 1;
  else if ( res < 0 & res > result)
    CCRo[3] = 1;
  else
    CCRo = CCRin;
end
endmodule
模块ALU(操作码、ra、rb、ra输出、cin、co、res、rst、clk、pc、npc、CCRin、CCRo、SP、SP输出);
输出[1:0]分辨率;//结果
输入线[7:0]pc;
输出寄存器[7:0]npc;
输入rst、clk;
输入线cin;
输入线[3:0]操作码;
输入线[1:0]ra;
输入线[1:0]rb;
输出寄存器[1:0]输出;
输入线[7:0]SP;//试验台haygebli SP el mafroud yeb2a=255
输出寄存器[7:0]输出;
reg[255:0]dmem;
输入线[3:0]CCRin;
输出寄存器[3:0]CCRo;
输出co;
连线[2:0]结果//总结果
分配SP_out=SP;
分配结果=alu out(ra、rb、cin);
分配res=结果[1:0];
分配co=结果[2];
函数[2:0]计算输出;
输入[1:0]ra,rb;
输入cin;
案例(操作码)
0: ;
4:分配alu_out=ra+rb;
5:分配alu_out=ra-rb;
6:分配alu_out=~(ra&rb);
7:赋值alu_out={ra[1:0],cin};
8:赋值alu_out={ra[0],cin,ra[1]};
10:如果(ra==1)
开始
dmem[SP_out]=rb;
SP_out=SP_out-1;
结束
其他的
开始
SP_out=SP_out+1;
rb=dmem[SP_out];
结束
13:分配ra_out=rb;
默认值:开始
alu_out=8'bxxxxxxxx;
npc=pc+1;
结束
尾声
端功能
始终@(res)
开始
如果(res==0)
CCRo[0]=1;
else if(res<0)
CCRo[1]=1;
如果(co==1),则为else
CCRo[2]=1;
否则如果(res<0&res>结果)
CCRo[3]=1;
其他的
CCRo=CCRin;
结束
端模

assign
语句仅在
wire
类型上合法,不在
reg
类型上合法

如果您有一个
reg
,则您希望从块中分配它:

always @* begin
   SP_out = SP;
end
或者,从
SP_out
中删除
reg
声明,将其视为连线,然后您的assign语句将工作


两个选项的行为方式完全相同

谢谢!我把它放在了一个总是挡块里,这就成功了。我有一个问题,如果我的输出是一根电线,这会影响什么?(我的助教告诉我所有输入必须是导线,输出必须是reg)我不知道,我认为输出导线和输出reg之间没有任何区别。输入总是有线的(但这并不重要,因为您没有分配它们),但这两种类型的输出对我来说都是有效的。我不知道你的助教为什么会这么说。我也不知道,非常感谢蒂姆!