导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→C51编程:请教老古!![东海飘萍客]

 *第482篇: C51编程:请教老古!!

  
楼 主:东海飘萍客 2001年9月21日13:46
 C51编程:请教老古!!
   老古,你好!!
   我是一个用C51的新手,以前都是用汇编写的,现在正在学C51,我想在C里调用汇编程
序,我看着书自己写了一个,可是不对,书上写的又不是很清楚!!不知老古是否能给我详
细的解释一下具体的格式!!也就是说我能看着他写出接口来。还有在KEIL里怎么可以看到
列表文件!希望能指点一二,不胜感激 !!
我的E—MAIL:axiaxi520@163.net
                                                             东海飘萍客
  
2楼:东海飘萍客 2001年9月27日15:58
 斑竹,你怎么不回答我啊,难道你也不会,你是我唯一的希望啊,有哪位大虾知道怎样在c51里嵌套ASM,请指点一二,我的E—MAIL是axiaxi520@163.net!!
  
3楼:千古醉人 2001年9月27日16:05
 是的!我也很有兴趣知道!书上的我老是看不懂作者的思路!说的太粗略了!请老古挺身而出!
  
4楼:monkey 2001年10月16日11:49
 这个在C51BBS中不是已讨论过了吗?
利用预编译命令ASM 和SRC 不就可以了吗?
  
5楼:老古 2001年9月27日18:42
 列表文件为.LST,.M51的文件。关于嵌套的问题,keil的文档有说,在hlp目录里。
  
6楼:寄存器 2001年9月28日08:43
 还有一个简单的方法是直接用ASM ENDASM嵌入但得编译两次
  
7楼:千古醉人 2001年9月28日09:40
 编译两次!此话怎讲!难道不需要和高级语言的参数传递!如何编译两次呢!
  
8楼:寄存器 2001年9月28日14:09
 仅供参考,可在网上找到原文      
有时候,你的程序需要使用汇编语言来编写,像对硬件进行操作或一些对时钟要求很严
格的场合,但你又不希望用汇编语言来编写全部程序或调用用汇编语言编写的函数那么
你可以通过预编译指令”asm”在C代码中插入汇编代码
列表0-10
#include <reg51.h>
extern unsigned char code newval[256];
void func1(unsigned char param) {
unsigned char temp;
temp=newval[param];
temp*=2;
temp/=3;
#pragma asm
MOV P1, R7 ; 输出temp中的数
NOP ;
NOP
NOP
MOV P1, #0
#pragma endasm
当编译器在命令行加入”src”选项时,在”asm”和”endasm”中的代码将被复制到输出的
SRC
文件中如果你不指定”src”选项编译器将忽略在”asm”和”endasm”中的代码很重要的一
点是编译器不会编译你的代码并把它放入它所产生的目标文件中必须用得到的.src文
件经过编译后再得到.obj文件从上面的文件将得到下面的.src文件
  
9楼:寄存器 2001年10月10日10:31
 送你一点C51编译控制的资料
Example
C51 testfile.c SYMBOLS CODE DEBUG

#pragma SYMBOLS CODE DEBUG

In the above examples, SYMBOLS, CODE, and DEBUG are all control directives.
testfile.c is the source file to be compiled.
NOTE
The syntax is the same for the command line and the #pragma directive.
Multiple options, however, may be specified on the #pragma line.
Typically, each control directive may be specified only once at the beginning of
a source file. If a directive is specified more than once, the compiler 
generates a
fatal error and aborts compilation. Directives that may be specified more than
once are so noted in the following sections.
Directive Categories
Control directives can be divided into three groups: source controls, object
controls, and listing controls.
 Source controls define macros on the command line and determine the name
of the file to be compiled.
 Object controls affect the form and content of the generated object module
(*.OBJ). These directives allow you to specify the optimizing level or
include debugging information in the object file.
 Listing controls govern various aspects of the listing file (*.LST), in
particular its format and specific content.
Keil Software — Cx51 Compiler User’s Guide 23

The following table is an alphabetical list of the control directives. 
Unterlined
characters denote the abbreviation of the directive.
Directive Class Description
AREGS,
NOAREGS
Object Enable or disable absolute register (ARn) addressing.
ASM, ENDASM Object Marks the beginning and the end of an inline assembly block.
BROWSE &#8224; Object Enable generation of browser information.
CODE &#8224; Listing Add an assembly listing to the listing file.
COMPACT &#8224; Object Select COMPACT memory model.
COND,
NOCOND &#8224;
Listing Include or exclude source lines skipped from the preprocessor.
DEBUG &#8224; Object Include debugging information in the object file.
DEFINE Source Define preprocessor names in the Cx51 invocation line.
DISABLE Object Disables interrupts for the duration of a function.
EJECT Listing Inserts a form feed character into the listing file.
FLOATFUZZY Object Specify number of bits rounded during floating compare.
INCDIR, ID &#8224; Source Specify additional path names for include files.
INTERVAL &#8224; Object Specify the interval for interrupt vectors for SIECO chips.
INTPROMOTE,
NOINTPROMOTE &#8224;
Object Enable or disable ANSI integer promotion.
INTVECTOR,
NOINTVECTOR &#8224;
Object Specify base address for interrupt vectors or disable vectors.
LARGE &#8224; Object Select LARGE memory model.
LISTINCLUDE Listing Display contents of include files in the listing file.
MAXARGS &#8224; Object Specify size of variable argument lists.
MOD517,
NOMOD517
Object Enable or disable code to support the additional hardware
features of the 80C517 and derivatives.
MODA2,
NOMODA2
Object Enable or disable dual DPTR register support for Atmel 82x8252
and variants.
MODDP2,
NOMODDP2
Object Enable or disable dual DPTR register support for Dallas
Semiconductor 320, 520, 530, 550 and variants.
MODP2,
NOMODP2
Object Enable or disable dual DPTR register support for Philips and
Temic derivatives.
NOAMAKE &#8224; Object Disable information records for AutoMAKE.
NOEXTEND &#8224; Source Disable Cx51 extensions to ANSI C.
OBJECT,
NOOBJECT &#8224;
Object Enable object file and optionally specify name or suppress the
object file.
OBJECTEXTEND &#8224; Object Include additional variable type information in the 
object file.
ONEREGBANK Object Assume that only registerbank 0 is used in interrupt code.
OMF2 &#8224; Object Generate OMF2 output file format.
OPTIMIZE Object Specify the level of optimization performed by the compiler.
24 Chapter 2. Compiling with Cx51
2
Directive Class Description
ORDER &#8224; Object Variables are allocated in the order in which they appear in the
source file.
PAGELENGTH &#8224; Listing Specify number of rows on the page.
PAGEWIDTH &#8224; Listing Specify number of columns on the page.
PREPRINT &#8224; Listing Produce a preprocessor listing file where all macros are
expanded.
PRINT, NOPRINT &#8224; Listing Specify a name for the listing file or disable the 
listing file.
REGFILE &#8224; Object Specify a register definition file for global register 
optimization.
REGISTERBANK Object Select the register bank that is used for absolute register
accesses.
REGPARMS,
NOREGPARMS
Object Enable or disable register parameter passing.
RET_PSTK &#8224;,
RET_XSTK &#8224;
Object Use reentrant stack for saving return addresses.
ROM &#8224; Object Control generation of AJMP/ACALL instructions.
SAVE,
RESTORE
Object Saves and restores settings for AREGS, REGPARMS and
OPTIMIZE directives.
SMALL &#8224; Object Select SMALL memory model. (Default.)
SRC &#8224; Object Create an assembler source file instead of an object module.
STRING &#8224; Object Locate implicit string constants to xdata or far memory.
SYMBOLS &#8224; Listing Include a list of all symbols used within the module in the 
listing
file.
VARBANKING &#8224; Object Use library set for variable banking support.
WARNINGLEVEL &#8224; Listing Selects the level of Warning detection.
&#8224; These directives may be specified only once on the command line or at the 
beginning of a source
file using in the #pragma statement. They may not be used more than once in a 
source file.
具体的讲就是在程序中加:
#pragma SRC 
用C51编译一遍后去掉该行将编译输出的SRC文件再用ASM51编译一边

  
10楼:东海飘萍客 2001年9月29日15:25
 你说的太笼统了,能不能说详细点,帮助里的我看过,不太明白!

>>>>>>对该主题发表你的看法

本主题贴数10,分页: [第1页]


[上一篇主题]:初学者:请教老古

[下一篇主题]:老古,再收邮件。