If you want to use assembly language inside a C language function, you should use the following Cx51 compiler control commands:
#pragma asm
;;; Assembly code
#pragma endasm
function:
The asm and endasm commands are used to merge the assembler program marked by them into the .SRC file. This source program with asm and endasm block marks can be regarded as an online embedded assembler. In this respect, this command is somewhat similar to the #define command.
Implementation:
(1) Compiler settings and SRC file generation
.SRC files are generated in command-line compilation mode using the SRC compiler control command. In the IDE environment, you can set specific options for the C source files that need to generate SRC files:
l Right-click the file tab under Project Workspace
l Select the Options for file… item to open the Options – Properties page.
l Select Generate Assembler SRC file
l Select the Assembler SRC file option
(2) Add library files
According to the selected compilation mode, add the corresponding library file to the project. For example, in the "small" mode, add the "keil\c51\lib\c51s.lib" file to the project. The LIB files in the \C51\LIB\ directory under the Keil installation directory are as follows:
C51S.LIB - Small model without floating point operations
C51C.LIB - Compact model without floating point operations
C51L.LIB - Large model without floating point operations C51FPS.LIB -
Small model with floating point operations
C51FPC.LIB - Compact model with floating point operations
C51FPL.LIB - Large model with floating point operations
If this library file is not added, the "UNRESOLVED EXTERNAL SYMBOL" warning will be prompted.
After the above settings, when compiling, the IDE will generate an assembly source file (.SRC) and the assembler will convert this file into an object file (.OBJ).
Precautions:
(1) Although labels can be added in assembly language to execute some jump instructions, be careful not to make them the same as other labels generated by the compiler.
(2) After following the Cx51 parameter calling rules, if a char number is passed to the function, the compiler will compile it into passing it through R7. At this time, if R7 is called directly in the assembly language, a warning will appear that the defined variable (formal parameter) has not been called.
2. Function external mixed programming
Implementation:
If you want to write a complete function in assembly language that can be called by other functions, you can follow the following process:
(1) Creation of source files
Create a new C source file such as test.c, add it to the project, and write a dummy function to implement the function (that is, write the function name and parameters, without giving a specific implementation, but it is best to write a simple code to call the parameters so that the compiler does not prompt a "defined variable is not called" warning).
(2) From (1) in the “Specific process” above.
(3) From (2) in the “Specific process” above.
(4) Compile the file, remove test.c from the project, and rename the generated test.src file to, for example, test.a51.
(5) Add test.a51 to the project and write the specific assembly code to be implemented in it.
(6) Recompile the entire file.
Precautions:
(1) Before calling the function, you must declare the existence of the function in the called file. The writing method should be the same as the C function implementation in assembly language, that is, the function name in test.c.
Previous article:F020 Basics
Next article:C51 and assembly mixed programming function declaration
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- ASML predicts that its revenue in 2030 will exceed 457 billion yuan! Gross profit margin 56-60%
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- What is the effective communication rate of STM32 USB CDC HOST DEVICE?
- 11. [Learning LPC1768 library functions] Systick experiment
- Ask God
- [ST NUCLEO-H743ZI Review] + 5. CAN communication transceiver test
- Request resume
- MicroPython Hands-on (30) - Blynk for the Internet of Things
- Schematic resource help
- EEWORLD University ---- DC / DC switching regulator packaging innovation
- What are some of the principles of mechanical, galvanometer, and laser scanners?
- 7nm lithography machine was used to pay off debts, hundreds of employees were laid off, and the 100 billion chip project came to an end!!!