0

I am trying to run this code, and it is giving these errors:

Syntax error near "always"
Syntax error near "endmodule"

I don't understand what is wrong in this code:

module fortran_v2(
    input clk
    );
parameter N=8;
parameter M=6;
parameter size=1000;     
reg [N-1:0] A [0:size-1];
reg [N-1:0] B [0:size-1];
reg [M-1:0] C [0:size-1];
reg [M-1:0] D [0:size-1];
reg [15:0] k=0;
integer open_file;
initial begin
open_file= $fopen("output.txt","w");
end

always @ (posedge clk) begin
if(k<1000)
k<=k+1;
else
k<=1000;
end

always @ (posedge clk) begin
if(k<1000) begin
  A[k]<=$random;
  B[k]<=$random;
  end

always @ (posedge clk) begin
if (k<1000) begin
  C[k]<=A[k]*B[k] +5;
  D[k]<=A[k]+B[k] -5;
  $fwrite(open_file,"A[%d",k,"]",A[k],"B[%d",k,"]",B[k],"C[%d",k,"]",C[k],"D[%d",k,"]",D[k]);
end
else
  A[k]=0;
end  
endmodule

2 Answers 2

4

You'd have no problem if you use a proper indentation. In one of your always blocks, keyword end is missing:

always @ (posedge clk) begin
  if(k<1000) begin
    A[k]<=$random;
    B[k]<=$random;
  end
end //missing end
Sign up to request clarification or add additional context in comments.

Comments

0

begin...end in Verilog correspond to curly braces in most programming languages {...} and so each "begin" must have an "end" associated with it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.