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)
; {
相关文档:
详解C盘Windows文件夹里重要文件的作用
在整个Windows操作系统中,最重要的莫过于“Windows”文件夹,对电脑进行任何操作几乎都有关。了解这里对于掌握整个系统的运作有很大的作用,如果有兴趣不妨往下看看。
一、印象中的Windows文件夹
“Windows”文件夹给人的第一印象就是大而乱,感觉里面 ......
刚从网上看到c和java混编的文章,就亟不可待的尝试了一下。呵呵,效果还是很好的。下面将自己成果粘贴出来
(转载于http://www.zxbc.cn/html/20070518/19986.html)。实验之后可以通过。
1java中调用c语言
首先编写Main.java
public class Main
{
public native static int getStrNum(byte str[], int s ......
经过验证可以实现,先将实现代码贴出,以备以后使用。
本文默认你的java开发环境已经安装成功,并且对于java语言和c++语言有过了解。
编写测试用类:Demo.java
代码如下:
public class Demo
{
public static int COUNT = 8;
private String msg;
private int[] counts;
......
以下全文转载自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 ......