1

I am trying to make a module which XORs 5 bits of a 24-bit input, and when I try to reference the XOR module in my top module, I am getting an error when I try and assign the data bits I want to. I am not entirely sure what syntax I am supposed to use instead. If I could get some advice on that, it would be greatly appreciated.

module XOR(input Data[0], input Data[1], input Data[2], input Data[3], input Data[4],  output Out);
    input [4:0] Data;
    output Out;
    
    assign Out = Data[0] ^ Data[1] ^ Data[2] ^ Data[3] ^ Data[4];
endmodule

module twobit(
    input [24:0] Data,
    output [24:0] Errors
    );  
    
    wire [4:0] xorOut;
    XOR u1 (.Data[0](Data[0]), .Data[1](Data[1]), .Data[2](Data[2]), .Data[3](Data[3]), .Data[4](1), .Out(xorOut[0]));
    
endmodule 
toolic
  • 57,801
  • 17
  • 75
  • 117
Spice
  • 31
  • 3

1 Answers1

0

There are 2 main problems with your code.

You use the wrong syntax for your XOR module port declarations. You just need to use declarations similar to the twobit module.

The other problem is with the XOR port connections in the twobit module.

This code compiles without syntax errors:

module XOR(
    input [4:0] Data,
    output Out
);
    
    assign Out = Data[0] ^ Data[1] ^ Data[2] ^ Data[3] ^ Data[4];
endmodule

module twobit(
    input [24:0] Data,
    output [24:0] Errors
    );  
    
    wire [4:0] xorOut;
    XOR u1 (.Data(Data[4:0]), .Out(xorOut[0]));
    
endmodule 

Here is a related post which may help explain this: How to instantiate a module

toolic
  • 57,801
  • 17
  • 75
  • 117