1

I have a basic compiler error I am not able to figure out. Code:

module (input [127:0] in1,
        input [2:0] en);
real a1;
if(en==3'b001)
begin
  a1=$bitstoreal(in1[31:0]);
end

The error is :

Error: E:/Modeltech_pe_edu_10.0/examples/FloatingPt.v(20): near "=": syntax error, unexpected '=', expecting IDENTIFIER or TYPE_IDENTIFIER or '#' or '('

2 Answers 2

3

You have procedural code outside a procedural construct.

real a1;
initial
  begin
  if(en==3'b001)
    begin
    a1=$bitstoreal(in1[31:0]);
    end
  end
Sign up to request clarification or add additional context in comments.

3 Comments

I dont want it inside an initial block. Is there any other way to do it?
Yes. Use a task or a function.
Take a look at this memory model. micron.com/get-document/?documentId=5243 -> Sim Models -> LPDDR Verilog Model. The model is mobile_ddr.v You can see how the model uses a few procedural blocks for high-level control and then calls tasks containing groups of calculations.
3

Assignments in Verilog are done by the assign statement if you're trying to set the value of a wire or within a procedural block (always or initial) for other data types.

In your example, you are missing an always block:

always @(*) begin
    if(en==3'b001) begin
        a1=$bitstoreal(in1[31:0]);
    end
end

You also might have a problem assigning a bus to the real type if you're not sure of what you're doing. You might need to write it as a1 = $itor(in1);

2 Comments

If I dont want to include an always block, how do i do it?
its not possible to do continuous assignment for real types. I think they are implemented as registers.

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.