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)
; {
相关文档:
大家都知道在Unix/Linux中有个man命令,可以查询常用的命令,函数。可是对于我们这样只知道用"man 函数名"来查询的人来说,会遇到很多问题,比如:
man read,我想看的是ANSI C中stdio的read函数原型和说明,没想到出来的确是BASH命令的说明,这是怎么回事 ......
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <getopt.h>
#define MAX_READFILE 24
#define MAX_INPUTFILE 10240
char *file ;
void time_out(){
syslog(LOG_INFO,"read inp ......
一位ID为ultimus的程序员开发了一种名为anic的新语言,近日引起业界关注。根据Google Code上该项目的简介,该语言的正式名称是ANI,anic是这种语言的参考实现。
ANI是一种实验性、高性能、静态安全、完全隐含支持并行、面向对象的通用数据流编程语言。
anic用GNU工具链写成,因此可移植性很好,可以运行于所有主流操作系 ......
刚刚完成的C读取文件一行数据,可以读大量数据的行。
/*
函数功能:
读取文件的一行,当开辟内存不够时return值为-1,size会给出至少需要的内存大小,
return值为1时表示此时文件结束,从buffer,size得到最后一行的数据和大小。
输入参数:
stream:文件流
......
1:每一个变量在使用前都得声明,不然在使用的时候就有可能是随机的数字
2:注意头文件中函数声明的时候要在后面加上分号
3:注意串口可以打印变量,就像C中的printf一样
4:DNW中不能打印float型数据
5:注意结构体指针数组 的使用和调用
6: ......