Compilation error in Quartus for Verilog language

124 Views Asked by At

I am new to Verilog and it's tools. I am simulating/compiling in Quartus Prime. In this particular code, it's showing up an error which is supposed to be the syntax of the language.

Error Message Screenshot

Code :

module conditional_op();
    int result;
    int a = 9;
    int b = 31;
    reg c = 0;
    
    initial begin
    
        #1; result = (a == 9) ? 1:0;
        $display("result=%0d",result);
        
        #1; result = ((a+b) == 40) ? 1:0;
        $display("result=%0d",result);
        
        #1; result = (b == 30) ? 678 : -99;
        $display("result=%0d",result);
        
        #1; c = (b ==31)? 1'bz : 1'b0;
        $display("c=%b",c);
    
    end
endmodule

I tried by relocating all the inputs and outputs beside the module name in the parenthesis, but it didn't work.

2

There are 2 best solutions below

0
toolic On BEST ANSWER

Your code compiles without errors and simulates as expected on multiple simulators on EDA playground. Here is an example simulation output:

# result=1
# result=1
# result=-99
# c=z

Since you used the int keyword, it is necessary to enable SystemVerilog features in your tool. Refer to the Quartus documentation for doing so. int is a data type that was added to the SystemVerilog extension to the language (IEEE Std 1800). int was not part of the superseded Verilog IEEE Std 1364.

If that still yields compile errors, there may be a bug in the version of the tool you are using. In that case, contact the vendor for support.

2
Im Groot On

You have to use integer, not int. Replace the int with integer.

module conditional_op();
    integer result;
    integer a = 9;
    integer b = 31;
    reg c = 0;
    
    initial begin
    
        #1; result = (a == 9) ? 1:0;
        $display("result=%0d",result);
        
        #1; result = ((a+b) == 40) ? 1:0;
        $display("result=%0d",result);
        
        #1; result = (b == 30) ? 678 : -99;
        $display("result=%0d",result);
        
        #1; c = (b ==31)? 1'bz : 1'b0;
        $display("c=%b",c);
    
    end
endmodule

int data type is most oftenly confused with integer data type. This is why it is also a commonly asked question in interviews. Here are details about int

  1. int is available only in system Verilog.
  2. int is 32-bit variable which is made of of bit data type
  3. Can store only 2-state values (0, 1)
  4. This is not synthesizable

Here are details about integer

  1. Available in both Verilog and System Verilog
  2. int is a 32-bit variable which is made of reg data type
  3. Can store 4-state values (0, 1, z, x)
  4. This is synthesizable as it represents register of 32 flip-flops.

Link: Int vs Integer details

Also check this thread where difference between reg and integer is clarified. integer vs reg