易截截图软件、单文件、免安装、纯绿色、仅160KB

A51: CALLING C FUNCTIONS from ASSEMBLY

以下全文转载自http://www.keil.com/support/docs/697.htm                       Copyright © 2010 Keil™, An ARM® Company.
Information in this article applies to:
C51 Version 5 and Later
QUESTION
I wish to call a function written in C from my assembly code. How do I do it?
ANSWER
The easiest way to achieve this is to let the C compiler generate the correct assembly code for you.
Suppose you have a C function called 'foo' which takes a single unsigned char argument and returns an unsigned char value. In a new C file write a dummy function that calls 'foo'. For example:
#pragma src
extern unsigned char foo(unsigned char);
void dummy(void)
{
unsigned char x,y;
x = 1;
y = foo(x);
}
#pragma SRC directs the C compiler to generate assembly code when the file is compiled. The extension of the assembly file will be 'src'.
If you view the src file you will see how to call the function 'foo' from assembly. It shows the registers or memory locations used to pass the function arguments and which registers or memory locations are used to return a value. In addition it also gives you the correct function naming convention to use, which is essential for interfacing assembly to C.
You can then use the src file as a template to write the function call in your own assembly code. Note that you must also include the EXTRN directive for the function, eg:
EXTRN CODE (_foo)
Permission to use documents and related graphics available from this server ("Server") is granted, provided that (1) the below copyright notice appears in all copies and that both the copyright notice and this permission notice appear, (2) use of documents and related graphics available from this Server is for informational and non-commercial or personal use only, (3) no documents or related graphics, including logos, available from this Server are modified in any way


相关文档:

经典C/C++面试题(三)

1) 什么是预编译,何时需要预编译:总是使用不经常改动的大型代码体。
程序由多个模块组成,所有模块都使用一组标准的包含文件和相同的编译选项。在这种情况下,可以将所有包含文件预编译为一个预编译头。
2) char * const p;
  char const * p
  const char *p ......

【入门】用Linux中man命令查询C函数

      大家都知道在Unix/Linux中有个man命令,可以查询常用的命令,函数。可是对于我们这样只知道用"man 函数名"来查询的人来说,会遇到很多问题,比如:
      man read,我想看的是ANSI C中stdio的read函数原型和说明,没想到出来的确是BASH命令的说明,这是怎么回事 ......

anic:比C快比Java安全比shell还简单的新语言

一位ID为ultimus的程序员开发了一种名为anic的新语言,近日引起业界关注。根据Google Code上该项目的简介,该语言的正式名称是ANI,anic是这种语言的参考实现。
ANI是一种实验性、高性能、静态安全、完全隐含支持并行、面向对象的通用数据流编程语言。
anic用GNU工具链写成,因此可移植性很好,可以运行于所有主流操作系 ......

详解C盘Windows文件夹里重要文件的作用

详解C盘Windows文件夹里重要文件的作用 
在整个Windows操作系统中,最重要的莫过于“Windows”文件夹,对电脑进行任何操作几乎都有关。了解这里对于掌握整个系统的运作有很大的作用,如果有兴趣不妨往下看看。
一、印象中的Windows文件夹
“Windows”文件夹给人的第一印象就是大而乱,感觉里面 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号