Keil™, An ARM® Company

Technical Support

µVISION1: INLINE ASSEMBLY


Information in this article applies to:

  • µVision Version 1

QUESTION

How do I include in-line assembly in my C files and use the Project Manager in µVision Version 1 to compile the C file and assemble the SRC file?

ANSWER

In-line assembly requires that you do a number of things that fall outside the "normal" project build process. All of these can be implemented using the µVision IDE.

The process for building in-line assembly files is:

  1. Compile the C source file using the SRC directive. This directive tells the compiler to generate an assembly file with the .SRC file extension (unless you specify a different one). This file must then be assembled using the Assembler.
  2. Assemble the .SRC file generated by the compiler.
  3. Include the object file generated by the assembler in your project.

To do this in µVision:

  1. Add the C source file to the project.
  2. On the first line in the C file, add #pragma SRC. This causes the compiler to generate the assembly file. You should not specify this directive in the general compiler options because that would generate assembly for ALL C files.
  3. Compile this file using the Compile File command from the project menu. This generates the .SRC file, which is the assembly source file.
  4. Open the Project dialog box using the Edit Project command in the Project menu.
  5. Select the C file for which an assembly file is desired and un-check the "Include in Link/Lib" check box. When this checkbox is un-checked, µVision does not include the object file in the linker command line. This is necessary since the compiler does not generate an object file when the SRC directive is used.
  6. Add the assembler .SRC file to the project. When you do this, µVision will complain that is does not recognize that file type. This is normal. Just click OK and close the Add File To Project dialog. µVision uses the file extensions that are defined in the Make Options dialog box. If you add SRC to the assembler extensions list, µVision automatically recognizes and adds the SRC file. However, this is not necessary. It is easy to manually add one or two files.
  7. Next, select the assembler .SRC file in the Project dialog box and change the translator type to Assembler.
  8. Un-check the "Always Build" checkbox. When checked, this control forces re-compilation or re-assembly of the source file.
  9. Check the "Include in Link/Lib" checkbox. This includes the object file in the linker command line.

NOTE
If you have only one file included in the linkage, the linker may complain that it has unresolved symbols for library routines that you used. This is due to the way the compiler and assembler generate object modules, but it is easy to fix.

When the compiler generates object files, the library information is included in the object file that is emitted.

When the assembler generates object files, references to the C library are not included. So, you must manually specify that the linker include the C libraries.

You can include the libraries in the µVision project manager by simply selecting the appropriate library from the lib directory. µVision correctly identifies library files and automatically adds them to the project.

SEE ALSO

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Monday, July 18, 2005


Did this article provide the answer you needed?
 
Yes
No
Not Sure