Cross-Compilation of assembly and C language in the Keil C51 Environment

Source: Internet
Author: User
    • Question
    • Answer
    • More information
    • See also
    • Forum threads

1. How to embed Assembly commands in C language:

Reprinted from:

C51: Getting inline assembly to work

Information in this article applies:

    • C51 All Versions

How do I implement inline assembly in C51 usingASMAnd
Directives. I have read some of the KnowledgeBase articles relating to this problem, but I still cannot get it to work.


The following example program, Main. C, demonstrates some simple inline assembly.

Void main (void) {test (); # pragma asm jmp $; endless loop # pragma endasm}

The following rules apply to C51 inline assembly:

    • To use # pragma ASM/endasm, you must setGenerate aggreger SRC FileAndAssemble SRC FileSource File compile options in µvision by right-clicking your source file name in the project workspace and selectingOptions
      For file
    • When usingGenerate aggreger SRC FileAndAssemble SRC FileOptions in µvision, if there are no other C modules in your project, you must manually include the C51 run-time Library (c51s. lib, c51m. lib, or c51l. lib ).
More information
    • ReferASMIn the cx51 user's guide.
    • ReferInterfacing C to AssemblerIn the cx51 user's guide.
See also
    • C51: Problems with # pragma ASM
    • GENERAL: SRC Directive
    • Bl51: Warning L1 (unresolved external) using inline assembly
    • C51: inline assembly generates target out of range
    • C51: In-line ASM gives compiler warnings
Forum threads

The followingDiscussion ForumThreads may provide information related to this topic.

    • Asembly code in C

Last reviewed: Thursday, July 17,200 8

-- Reprinted from:

Method: (assume that there is only oneCCodeFile)

The1Step: Create a project and addCFile, compiled through

The2Step: Right-clickKeilInterfaceProject WorkspaceInCFile Name, select'Option

The3Step: click'Generate aggreger SRC File''Assemble
SRC File'Check the two three-state check boxes to make them highlighted and checked. click confirm.

The4Step: SetKeilUnder the installation directoryC51/lib/c51s. Lib(If yesSmallMode) copy the file to the project directory

The5Step: Add a library fileC51s. LibFile to project, right-click'Source
Group 1', Select'Add files to group...', Select under the project directoryC51s. Lib, Click to open

(Because3Step. If no library file is added here, compileHEXThe file cannot be correctly executed by the microcontroller, and a warning will appear during compilation:

Warning L1: unresolved external symbol

Symbol:? C_startup

Unrecognized? C_startupThis label, which is defined in the library file


The6Step: Open the project directory and you can see that the new extension is. SRCFile, change its extension. A51

The7Step: add this. A51File to the project (this time the project containsC51s. LibLibrary file, otherwise the compilation will generate5The warning described in step and the generatedHEXFiles cannot be correctly run by single-chip microcomputer)

The8Step: recompile and generateHEXFile, loaded into the microcontroller, can be foundCThe language runs in the same way.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.