Mixed Programming of C51 and Assembly Language 1

Publisher:乐基儿vosLatest update time:2016-07-01 Source: eefocusKeywords:C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
1. Mixed programming within functions

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.

Keywords:C51 Reference address:Mixed Programming of C51 and Assembly Language 1

Previous article:F020 Basics
Next article:C51 and assembly mixed programming function declaration

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号