This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

help

code segment:

              ...
        EXTRN   NUMBER (MAX_NUM)


        DS      MAX_NUM


        END

another code segment:

        PUBLIC  MAX_NUM
        MAX_NUM EQU     8

when i assembled and linked these codes,
there was an error:

        Build target 'test'
assembling test.asm...
test.asm(13): error A28: ABSOLUTE EXPRESSION REQUIRED
Target not created

How did it hanppen?

Parents
  • The error message is telling you that an absolute expression is required.

    You did not say on which file the error was reported, but I would think it is from the:

      DS  MAX_NUM
    

    The expression you gave results in a relocatable value and not an absolute value; hence the error.

    Why not put the EQU into an include file and include that into your test.asm module?

Reply
  • The error message is telling you that an absolute expression is required.

    You did not say on which file the error was reported, but I would think it is from the:

      DS  MAX_NUM
    

    The expression you gave results in a relocatable value and not an absolute value; hence the error.

    Why not put the EQU into an include file and include that into your test.asm module?

Children
  • yu zhou,

    I have some suggestions for you.

    www.catb.org/.../smart-questions.html
    How To Ask Questions The Smart Way
    Eric Steven Raymond

    Before You Ask
    www.catb.org/.../smart-questions.html

    When You Ask
    www.catb.org/.../smart-questions.html

    [Chinese]
    www.beiww.com/.../smart-questions.html
    æé—®çš„æ™ºæ…§
    Eric Steven Raymond
    ç¿»è¯':王刚 <yafrank at 126 dot com >

    æé—®å‰
    www.beiww.com/.../smart-questions.html

    æé—®æ—¶
    www.beiww.com/.../smart-questions.html

  • I put the
    MAX_NUM EQU 8
    into the first file,not use the PUBLIC and EXTRN keywords to export and import the symbol!
    just like:

          MAX_NUM   EQU    8
    ...
          DS    MAX_NUM
    ...
    


    and then assembled and linked it,no errors!
    Why???

  • Why?

    Didn't you read the answers you got?

    "Look in the assembler manual what EQU means - it declares an assembly-time constant, not a run-time variable. The linker on the other hand processes run-time variables."

    PUBLIC and EXTRN are used for link-time symbols, not for assembly-time symbols. But your MAX_NUM is not a program variable that will be stored in any memory cell, and so will not be assigned any address by the linker.

    This is the same as programming in C:

    #define MAX_NUM 8
    


    or

    enum {
        MAX_NUM 8
    };
    


    as compared to:

    int MAX_NUM = 8;
    

    Only the "int MAX_NUM" alternative will be a link-time symbol, where generated code reads from the memory to pick up the value.

  • If i put the symbol into a single file,and include it it
    into some .asm file,so, what does it differ from using the PUBLIC and EXTRN to export and import the symbols?

  • PUBLIC and EXTRN are still for runtime variables, i.e variables that have an address.

    EQU is for assembly-time variables that does not have an address.

    You can include the file with the EQU into multiple assembler files.

    For runtime variables, you have one source file that allocates the space for the variable. This file should export the information about the variable with PUBLIC. You may then have multiple source files that makes use of the variable - they should contain a EXTRN declaration to tell the assembler that there somewhere externally exists a variable with a specific name.

  • I can't understand you,aren't both PUBLIC and EXTRN
    work in assembly time?

  • They work in assembly, but for runtime variables - variables that gets a memory address. The linker must be able to know how to get a reference from one source code module to be able to use a variable that exists in another module.

    But this is separate from assembly-time numeric constants used by the assembler. EQU does not produce a runtime variable. There will be no memory allocated in the RAM of the microcontroller for an EQU symbol. And since it is an assembly time constant without a memory address, there will be no need/use for any EXTRN/PUBLIC to inform the linker about the constant. Without a memory address to share between multiple source modules, the linker don't need to know.

    But all this is introductory stuff, and as I have already mentioned, the same concept exists for C also. Get a good introductory book about assembly programming.