2

I am a newbie to xilinx so please excuse any stupidities in the code.

Ah so I am trying to design an 8-bit ALU and the module is working perfectly on the simulation but we need to take inputs and display outputs on FPGA board.

Technically I should have used RS-232 but since we just have an 8-bit input and 8 switches are available, we are trying to code it this way.

However, the code does not compile and gives error "expecting 'endmodule', found 'forever'".

I used 'forever' and not 'always' because always does not allow any instance to be instantiated within it.

Can anybody please help us figure out what is wrong with the code?

module main(out,in,switch);
output [7:0] out;
input [7:0] in;
input switch;
reg [7:0] a,b,select;
reg [1:0] count;
wire eq, comp, C8;
initial
begin
count = 2'b00;
select = 8'b0000_0000;
end
MyALU A(eq, comp, C8, out, a, b, 1'b0, select[0], select[1], select[2], select[3]);


forever
begin
if (switch)
    begin
        case (count)
        00: 
             begin
             a  = in;
             count = 2'b01;
             end
        01: 
             begin
             b  = in;
             count = 2'b10;
             end     
        10: 
             begin
             select  = in;
             A(eq, comp, C8, out, a, b, 1'b0, select[0], select[1], select[2], select[3]);
             count = 2'b00;
             end
        default
             a = in;
      endcase        
    end
end 
Shubham Batra
  • 2,357
  • 5
  • 29
  • 48
Maira Muneer
  • 75
  • 1
  • 1
  • 7
  • Loops inside verilog must be inside some procedural block. Use `initial` before `forever`. Or remove `forever` and use `always @(*)` is finer way. `endmodule` is missing here. – sharvil111 Dec 07 '15 at 05:18
  • Module instantiation is simply outside any procedural block. If multiple instances are required (which is not the case here), use `generate` block. – sharvil111 Dec 07 '15 at 05:22

2 Answers2

1

Every module in verilog must end with the line endmodule. That is missing in your code. And try using always@(*) instead of forever. forever is not synthesizable and only used for verification with simulation.

Greg
  • 18,111
  • 5
  • 46
  • 68
Jorc
  • 21
  • 3
0
  1. Replace the forever statement by always @(*).
  2. Remove this line from the case statement: A(eq, comp, C8, out, a, b, 1'b0, select[0], select[1], select[2], select[3]);
  3. Add endmodule at the end.
Kirk Beard
  • 9,569
  • 12
  • 43
  • 47
Anil
  • 1
  • 1