return the (value of) assignment

Discussion in 'VHDL' started by valtih1978, Sep 6, 2013.

  1. valtih1978

    valtih1978 Guest

    Here is a funny code that I have Modelsimed

    function COMPUTE return boolean is
    constant STR: string := "abc";
    -- Error1: Target of signal assignment
    -- is not a signal.
    --STR <= STR;

    -- Error2: Constant "STR" cannot be target of
    -- variable assignment statement.
    --STR := STR;

    -- Return assignment is OK!
    return STR <= "xyz";
    end function;

    -- Error3: Type error resolving function call
    -- "COMPUTE" as type std.STANDARD.STRING.
    --constant STR: string := COMPUTE;

    constant B2:boolean := COMPUTE;
    report "Computed b2 = " & boolean'image(B2);
    end process;

    I am getting "Computed b2 = true" in the output despite I do not see
    anywhere how the assignment in the end of COMPUTE function evaluates to
    a boolean. A stand-alone assignment would violate checks marked with
    error1 and error2.
    valtih1978, Sep 6, 2013
    1. Advertisements

  2. valtih1978

    Andy Guest

    There is no assignment statement in your (uncommented) example code.

    The statement here is "return <expression>" and the expression returns true if STR is less than or equal to "xyz".

    VHDL defines the <= operator for l,r operands of the same type. The evaluation is based on the size of the arrays.

    VHDL operators can be overloaded, to implement more complex operations, such as is done in numeric_std for

    function "<=" (unsigned, unsigned) return boolean;

    Which evaluates the contents of the arrays to determine the result.

    A less ambiguous example would have been:

    return STR := "xyz";

    Since ":=" is not also a vhdl operator.

    Andy, Sep 6, 2013
    1. Advertisements

  3. valtih1978

    Tim McBrayer Guest

    In your example, '<=' is getting interpreted as 'less than or equal to', not 'signal
    assignment' here. It is true that "abc" <= "xyz", thus the returned boolean value.

    Tim McBrayer, Sep 6, 2013
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.