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

How do you add in-line assembly code to your c code?

I would like to be able to drop into assembler in the middle of a c program, but can't find any way to do this. The C166 compiler manual has some examples of using ASM and ENDASM, but even when I enter the example code exactly as given in the book, the compiler generates "error C25: syntax error near '<EOF>'. Normally, in-line assembly is a very uncomplicated process. Is in-line assembly even possible with the C166 compiler?

Thanks

Parents
  • Caveat: I'm assuming here that C166 works the same as C51 in this respect.

    "The point af ASM/ENDASM is to get the compiler to generate an .SRC file"

    No.
    The point of the SRC diretive is to get the compiler to generate a .SRC file;

    The point of the ASM/ENDASM is to mark sections of code which are already in assembler - and are therefore just pasted verbatim into the .SRC file with no translation at all.

    It is not uncommon for compilers to implement "inline assembly" in this way.

    You can use the SRC diretive without using ASM/ENDASM, but you can't use ASM/ENDASM without the SRC diretive!

    I think that the use of inline assembly should be avoided; if you have something that really needs to be done in assembler (and such things unquestionably exist) then, I say, write it in proper assembler and call it from 'C'.
    This is because 'C' makes no guarantees about how it might be using the various processor registers between statements - but inline assembler often relies upon a certain usage!
    http://www.keil.com/forum/docs/thread1757.asp

    Other disadvantages of inline assembler with the Keil tools are:
    1. The SRC directive causes you to lose all 'C' debug information for the whole file;

    2. The SRC directive causes the affected file to be translated on every build - whether it needs it or not

Reply
  • Caveat: I'm assuming here that C166 works the same as C51 in this respect.

    "The point af ASM/ENDASM is to get the compiler to generate an .SRC file"

    No.
    The point of the SRC diretive is to get the compiler to generate a .SRC file;

    The point of the ASM/ENDASM is to mark sections of code which are already in assembler - and are therefore just pasted verbatim into the .SRC file with no translation at all.

    It is not uncommon for compilers to implement "inline assembly" in this way.

    You can use the SRC diretive without using ASM/ENDASM, but you can't use ASM/ENDASM without the SRC diretive!

    I think that the use of inline assembly should be avoided; if you have something that really needs to be done in assembler (and such things unquestionably exist) then, I say, write it in proper assembler and call it from 'C'.
    This is because 'C' makes no guarantees about how it might be using the various processor registers between statements - but inline assembler often relies upon a certain usage!
    http://www.keil.com/forum/docs/thread1757.asp

    Other disadvantages of inline assembler with the Keil tools are:
    1. The SRC directive causes you to lose all 'C' debug information for the whole file;

    2. The SRC directive causes the affected file to be translated on every build - whether it needs it or not

Children