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

creating assembly functions

How can I create an assembly function?

How can I call it from c?

Thanx..

Parents
  • When I make something like this:

    1).src file with the following code

    PUBLIC _koko
    _koko:
    mov A,R7;
    mov B,R5;
    DIV AB;
    mov R7,B;
    RET
    end

    2)a C file as follows:
    #include <AT89X51.H>
    
    extern char koko(char c,char d);
    void main(void)
    {
    
    P0=koko(1,2);
    }

    It gives the following warning:

    *** WARNING L5: CODE SPACE MEMORY OVERLAP
        FROM:    0000H
        TO:      0006H

    How can this be resolved?
    Note that both files are included in the project list with the src file as the first file in the list

Reply
  • When I make something like this:

    1).src file with the following code

    PUBLIC _koko
    _koko:
    mov A,R7;
    mov B,R5;
    DIV AB;
    mov R7,B;
    RET
    end

    2)a C file as follows:
    #include <AT89X51.H>
    
    extern char koko(char c,char d);
    void main(void)
    {
    
    P0=koko(1,2);
    }

    It gives the following warning:

    *** WARNING L5: CODE SPACE MEMORY OVERLAP
        FROM:    0000H
        TO:      0006H

    How can this be resolved?
    Note that both files are included in the project list with the src file as the first file in the list

Children
  • How can this be resolved?
    by following the following suggestion TO THE LETTER

    The simplest way to create a C-callable assembly file, is to start with an outline in 'C', then let the compiler turn it into assembly source by using the SRC directive - see the Manual

    Erik

  • Assembly language has an "ORG" directive that tells the assembler where the instructions are located. It also lets you declare "segments" to put your code into so that the linker can relocate them. Without the benefit of these mechanisms, your code will go at address 0000h, where it conflicts with the restart vector.

    Take a look at some of the example assembly to see how this works. Or, as Erik suggests, use the SRC directive and have the compiler generate a sample file from C that actually does what you want.

  • "use the SRC directive and have the compiler generate a sample file from C that actually does what you want."

    As I said before, if you let the compiler do it, you can be certain that the compiler will generate code using all the correct conventions for 'C'-compatibility!