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)
; {
相关文档:
(五)
40. 链表题:一个链表的结点结构
struct Node
{
int data ;
Node *next ;
};
typedef struct Node Node ;
(1)已知链表的头结点head,写一个函数把这个链表逆序 ( Intel)
Node * ReverseList(Node *head) //链表逆序
{
i ......
刚刚完成的C读取文件一行数据,可以读大量数据的行。
/*
函数功能:
读取文件的一行,当开辟内存不够时return值为-1,size会给出至少需要的内存大小,
return值为1时表示此时文件结束,从buffer,size得到最后一行的数据和大小。
输入参数:
stream:文件流
......
详解C盘Windows文件夹里重要文件的作用
在整个Windows操作系统中,最重要的莫过于“Windows”文件夹,对电脑进行任何操作几乎都有关。了解这里对于掌握整个系统的运作有很大的作用,如果有兴趣不妨往下看看。
一、印象中的Windows文件夹
“Windows”文件夹给人的第一印象就是大而乱,感觉里面 ......
--摘自 《Oracle Pro*C 程序开发》 --Create/Modify Email:xingchengli@gmail.com
SQLDA 的结构如下:
struct SQLDA
{
long N; /* Descriptor size in number of entries */
char **V; Ptr to Arr of addresses of main variables */
long *L; /* Ptr to Arr of lengths of buffe ......
C/C++是最主要的编程语言。这里列出了50名优秀网站和网页清单,这些网站提供c/c++源代码。这份清单提供了源代码的链接以及它们的小说明。我已尽力包括最佳的C/C++源代码的网站。这不是一个完整的清单,您有建议可以联系我,我将欢迎您的建议,以进一步加强这方面的清单。
1、http://snippets.dzone.com/tag/c/ --数以千计 ......