Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

expecting 'endmodule', found 'else'

Status
Not open for further replies.

Abhisek hota

Newbie level 1
Newbie level 1
Joined
Mar 15, 2015
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
10

Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module ram_mem(din,add,rst,clk,en,rw,dout);
input [3:0]din;
input [5:0]add;
input rst,clk,en,rw;
output reg [3:0]dout;
reg [3:0]mem[0:63];
 
always@(clk)
begin
 
if(en)
    begin
        always@(posedge clk or negedge rst)
            begin
                if(rw)
                    mem[add]<=din;
                else
                    dout<=mem[add];
            end
    end
 
else
    begin
        always@(negedge clk or negedge rst)
            begin
                if(rw)
                    mem[add]<=din;
                else
                    dout<=mem[add];
            end
    end
    
end
 
endmodule

 
Last edited by a moderator:

Unpaired begin end statements, just count it and correct according to the intended program function.

Looks like you have pasted some code unintentionally twice, alos the surrounding always @(clk) makes no sense. I guess you wanted something like below.

By the way, using proper indentation can help you to read your own text.


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
if(en)
begin
  always@(posedge clk or negedge rst)
  begin
    if(rw)
      mem[add]<=din;
    else
      dout<=mem[add];
  end
end

 

Unpaired begin end statements, just count it and correct according to the intended program function.

Looks like you have pasted some code unintentionally twice, alos the surrounding always @(clk) makes no sense. I guess you wanted something like below.

By the way, using proper indentation can help you to read your own text.


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
if(en)
begin
  always@(posedge clk or negedge rst)
  begin
    if(rw)
      mem[add]<=din;
    else
      dout<=mem[add];
  end
end


If (en) begin
always @ (posedge clk or negedge rst)
...
end


This isn't legal Verilog. It would only be legal if en was a static value at compile time, i.e a parameter or constant (selective compile based on a constant), but not using an input.

I think the OP doesn't know how to write the simplest behavioral description of a flip-flop:

Code Verilog - [expand]
1
2
3
4
5
6
7
// simplest FF
always @ (posedge clk)
  q <= d;
// simple FF with async reset
always @ (posedge clk or negedge rst)
  if (!rst) q <= 0;
  else      q <= d;

 
  • Like
Reactions: FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top