We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
Read the descriptions in the Manual - especially the "See Also" reference...
The C166 compiler manual does have an index reference to in-line assembly, but it refers to ASM/ENDASM. When you read the ASM/ENDASM section, it states "This source text can be thought of as inline assembly. Using the SRC directive, however, outputs to the source file but the source text is not assembled and sent to the object file." So what's the point of ASM/ENDASM? All I'm trying to do is include some in-line assembly code that's recognized by the compiler as assembly code, and has it assembled and included in the object file. As I said before, this is not a complicated issue with most other C compilers. First, I'm only trying to see if in-line assembly is even possible with the C166 compiler, and second, how is it accomplished. I'm beginning to think that if in-line assembly is possible C166, that it must be a fairly complicated process. Regards
Hi Doneil, So what's the point of ASM/ENDASM? All I'm trying to do is include some in-line assembly code that's recognized by the compiler as assembly code, and has it assembled and included in the object file. The point af ASM/ENDASM is to get the compiler to generate an .SRC file with your inline assembly code included. You will have to pass the .SRC file through assembler to generate an object file. Perhaps a more elegant way to implement this would be to get the compiler to understand inline assembly and generate object code directly without having to resort to assembler. That's exactly what Keil did in their v4.24 release: the __asm keyword. See Application Note 172 for details: http://www.keil.com/appnotes/files/apnt_172.htm First, I'm only trying to see if in-line assembly is even possible with the C166 compiler, and second, how is it accomplished. I'm beginning to think that if in-line assembly is possible C166, that it must be a fairly complicated process. Oh yes, it's very possible. I've used both ASM/ENDASM and __asm. I got the impression that the __asm keyword still needs some work, since it doesn't support some things you would expect it to support. But that's hardly surprising: it's a new feature and it's not well documented, so we don't even now what to expect from it in terms of detailed syntax. As always, you have to now what you are doing when you are using inline assembly, but that's nothing new. Regards, - mike
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
"2. The SRC directive causes the affected file to be translated on every build - whether it needs it or not" Of course this is only if you are using the uVision IDE and can be avoided by using a make tool that checks obj->SRC->C dependencies; not that with today's speedy computers, it's all that important.
"Of course this is only if you are using the uVision IDE" True "and can be avoided by using a make tool" Also true "not that with today's speedy computers, it's all that important." Absolutely (unless it's a particularly huge souce file!).
What happens if you need in-line assembly in a header file (for a macro)? How do you set-up the compiler then?
This is covered in: http://www.keil.com/appnotes/files/apnt_172.htm Also the new method does not need the SRC directive anymore. Reinhard
Dimitris Papadakis asked: "What happens if you need in-line assembly in a header file (for a macro)? How do you set-up the compiler then?" Reinhard Keil replied: "This is covered in: http://www.keil.com/appnotes/files/apnt_172.htm Also the new method does not need the SRC directive anymore." The Application Note, and the original thread, relate to the C166 compiler. Dimitris specifically selected the C51 toolset for his follow-on question; Is this new "Extended Inline Assembler" facility available in C51? If not, is it intended that it will be?