C51: CALLING ASSEMBLY ROUTINES from C
ÒÔÏÂÈ«ÎÄתÔØ×Ôhttp://www.keil.com/support/docs/50.htm Copyright © 2010 Keil™, An ARM® Company.
Information in this article applies to:
C51 All Versions
QUESTION
In the C51 compiler manual, there is example of an assembly module calling a C function. Is there any example of a C program calling an assembly routine?
ANSWER
There are no examples in the book, but it is easy to create your own. The asm routine must know how parameters are passed, values returned, and the naming conventions of segments. The steps you must follow to create an example are outlined below:
Write a simple function in C that passes parameters and returns values the way you want your assembly routine to.
Use the SRC directive (#PRAGMA SRC at the top of the file) so that the C compiler generates a .SRC file instead of a .OBJ file.
Compile the C file. Since the SRC directive was specified, the .SRC file is generated. The .SRC file contains the assembly code generated for the C code you wrote.
Rename the .SRC file to a .A51 file.
Edit the .A51 file and insert the assembly code you want to execute into the body of the assembly function shell included in the .A51 file.
For example, the following code
#pragma SRC
unsigned char my_assembly_func (
unsigned int argument)
{
return (argument + 1); // Insert dummy lines to access all args and retvals
}
when compiled generates the following assembly SRC file.
NAME TESTCODE
?PR?_my_assembly_func?TESTCODE SEGMENT CODE
PUBLIC _my_assembly_func
; #pragma SRC
; unsigned char my_assembly_func (
RSEG ?PR?_my_assembly_func?TESTCODE
USING 0
_my_assembly_func:
;---- Variable 'argument?040' assigned to Register 'R6/R7' ----
; SOURCE LINE # 2
; unsigned int argument)
; {
Ïà¹ØÎĵµ£º
Boss˵£¬Òª¿´OpenGL£¬¿´ÁË¿ìÒ»¸öÔ£¬×ÜËã³öÁ˸öÏñÑùµÄ¶«Î÷£¬ÓÃCдÁ˸ö3DÃÔ¹¬£¬
ËäȻֻÓÐ350ÐÐ
´úÂ룬²»¹ý±ßѧ±ßд£¬×ã×ãдÁËÒ»ÖÜʱ¼ä£¬»¹ÊÇСÓгɾ͸еģ¬»î»î»î£¡
&n ......
£¨Î壩
40. Á´±íÌ⣺һ¸öÁ´±íµÄ½áµã½á¹¹
struct Node
{
int data ;
Node *next ;
};
typedef struct Node Node ;
(1)ÒÑÖªÁ´±íµÄÍ·½áµãhead,дһ¸öº¯Êý°ÑÕâ¸öÁ´±íÄæÐò ( Intel)
Node * ReverseList(Node *head) //Á´±íÄæÐò
{
i ......
¹ØÓÚCµÄ˼¿¼
Cong Wang
May, 2006
Network Engineering Department
Institute of Post and Telecommunications, Xi'an, P.R.China
ÒýÑÔ
CÓïÑÔ½áºÏÁË»ã±àµÄËùÓÐÍþÁ¦£¬ËüµÄ³éÏó³Ì¶ÈÅöÇɼÈÂú×ãÁ˳ÌÐòÔ±µÄÒªÇó, ÓÖÈÝÒ×ʵÏÖ¡£ÒòÆä¶ÀÌصÄÁé»îÐÔºÍÇ¿´óµÄ¿ÉÒÆÖ²ÐÔ£¬ÏµÍ³³ÌÐòÔ±ºÍºÚ¿ÍÃǸüÊǶÔËüÖÓ°® ......
Ê×ÏÈ¡¢ÎÒÃÇ¿´32λµÄÕûÊý£ºint ¡¢unsigned int¡¢long¡¢unsigned long ¡£ÕâЩ¶¼ÊÇ»ù±¾ÀàÐÍ£¬Ã»ÓÐunsigned¹Ø¼ü×ÖµÄÊÇÓзûºÅµÄ£¬·´Ö®ÊÇÎÞ·ûºÅµÄ¡£»¹ÓбÈÈçDWORD¡¢ UINTÕâЩҲֻÊÇд±ðÃû£¨typedef£©¶øÒÑ¡£ÓзûºÅÕûÊýÖµµÃ×¢ÒâµÄÊÇʲô·¶Î§ÄÚÊÇÕýÊý£¬Ê²Ã´·¶Î§ÊǸºÊý¡£ÕâÑù¶ÔÓÚ¼Ó¼õÔËËã¡¢±È½ÏÔËËãµÈÓкܴó°ïÖú£¬·ñÔòºÜÈÝÒ×Òç³ö»òÕß± ......
ÒÔÏÂÈ«ÎÄתÔØ×Ôhttp://www.keil.com/support/docs/1671.htm Copyright © 2010 Keil™, An ARM® Company.
Information in this article applies to:
C51 Version 6.02
&mi ......