⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 第七章 keil c51的代码效率.htm

📁 本文档详细介绍了怎样使用keil软件开发单片机程序
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0056)http://www.51kaifa.com/zxyd/read_z.php?ID=484&BigClass=6 -->
<HTML><HEAD><TITLE>第七章 Keil C51的代码效率- 无忧电子开发网-在线阅读</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="" name=Keywords><LINK href="第七章 Keil C51的代码效率.files/css.css" 
type=text/css rel=stylesheet>
<SCRIPT language=JavaScript>function fontzoom(size){ document.getElementById('fontzoom').style.fontSize=size+'px'}</SCRIPT>
<!-- <script language="Javascript">document.oncontextmenu=new Function("event.returnValue=false");document.onselectstart=new Function("event.returnValue=false");</script>  --><!-- 限制右键复制 -->
<META content="MSHTML 6.00.2900.2668" name=GENERATOR></HEAD>
<BODY topMargin=10 marginheight="10" marginwidth="10">
<TABLE cellSpacing=0 cellPadding=0 width=760 align=center border=0>
  <TBODY>
  <TR>
    <TD width="100%">
      <TABLE height=2 cellSpacing=0 cellPadding=0 width="100%" bgColor=#808080 
      border=0>
        <TBODY>
        <TR>
          <TD width="100%"></TD></TR></TBODY></TABLE>
      <TABLE height=80 cellSpacing=0 cellPadding=0 width="100%" border=0>
        <TBODY>
        <TR>
          <TD align=middle width=186><A href="http://www.51kaifa.com/"><IMG 
            height=65 src="第七章 Keil C51的代码效率.files/logo.jpg" width=186 
            border=0></A></TD>
          <TD align=middle width=574>
            <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
              <TBODY>
              <TR>
                <TD vAlign=bottom width=120><A 
                  href="http://www.51kaifa.com/zxyd/"><IMG height=67 
                  src="第七章 Keil C51的代码效率.files/logo_zxyd.gif" width=120 
                  border=0></A></TD>
                <TD width=454>
                  <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
                    <TBODY>
                    <TR>
                      <TD align=middle width="100%" colSpan=3 height=19>
                        <TABLE cellSpacing=0 cellPadding=0 width="100%" 
border=0>
                          <TBODY>
                          <TR>
                            <TD class=xyzx_top align=middle width="100%" 
                            height=19><A 
                              href="http://www.51kaifa.com/hyxw">综合资讯</A> <A 
                              href="http://www.51kaifa.com/jswz">技术文章</A> <A 
                              href="http://www.51kaifa.com/yyfa">原文阅读</A> <A 
                              href="http://www.51kaifa.com/shop">在线商城</A> <A 
                              href="http://www.51kaifa.com/zxxz">下载专区</A> <A 
                              href="http://www.51kaifa.com/datasheet">DATASHEET</A> 
                              <A href="http://www.51kaifa.com/bbs">技术论坛</A> <A 
                              href="http://www.51kaifa.com/MenberInfo">商务频道</A> 
                            </TD></TR></TBODY></TABLE></TD></TR>
                    <TR>
                      <TD width=47 
                      background="第七章 Keil C51的代码效率.files/R_list_3.gif"><IMG 
                        height=54 src="第七章 Keil C51的代码效率.files/R_list_2.gif" 
                        width=48 border=0></TD>
                      <TD class=xyzx_top_shadow width=402 
                      background="第七章 Keil C51的代码效率.files/R_list_3.gif">
                        <P style="LINE-HEIGHT: 150%"><A class=xyzx_top2 
                        href="http://www.51kaifa.com/zxyd/list.php?BigClass=2">电子技术</A><FONT 
                        color=#ffffff> | </FONT><A class=xyzx_top2 
                        href="http://www.51kaifa.com/zxyd/list.php?BigClass=3">技术资料</A><FONT 
                        color=#ffffff> | </FONT><A class=xyzx_top2 
                        href="http://www.51kaifa.com/zxyd/list.php?BigClass=11">嵌入式系统</A><FONT 
                        color=#ffffff> | </FONT><A class=xyzx_top2 
                        href="http://www.51kaifa.com/zxyd/list.php?BigClass=6">单片机专题</A><FONT 
                        color=#ffffff> | </FONT><A class=xyzx_top2 
                        href="http://www.51kaifa.com/zxyd/list.php?BigClass=10">DSP专题</A><BR><A 
                        class=xyzx_top2 
                        href="http://www.51kaifa.com/zxyd/list.php?BigClass=8">EDA/PLD专题</A><FONT 
                        color=#ffffff> | </FONT><A class=xyzx_top2 
                        href="http://www.51kaifa.com/zxyd/list.php?BigClass=12">电源技术专题</A><FONT 
                        color=#ffffff> | </FONT><A class=xyzx_top2 
                        href="http://www.51kaifa.com/zxyd/list.php?BigClass=7">电子制作专题</A><FONT 
                        color=#ffffff> | </FONT><A class=xyzx_top2 
                        href="http://www.51kaifa.com/zxyd/list.php?BigClass=4">其他综合</A><FONT 
                        color=#ffffff> | </FONT><A class=xyzx_top2 
                        href="http://www.51kaifa.com/zxyd/list.php?BigClass=13">芯片选型</A><BR></P></TD>
                      <TD width=5><IMG height=54 src="" width=5 
                    border=0></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
      <TABLE height=4 cellSpacing=0 cellPadding=0 width="100%" border=0>
        <TBODY>
        <TR>
          <TD width="100%"></TD></TR></TBODY></TABLE>
      <TABLE cellSpacing=0 cellPadding=0 width="98%" align=center border=0>
        <TBODY>
        <TR>
          <TD align=middle width="5%" height=25><IMG 
            src="第七章 Keil C51的代码效率.files/R_url.jpg"></TD>
          <TD width="95%">所在的位置:<A href="http://www.51kaifa.com/">首页</A></A> → 
            <A href="http://www.51kaifa.com/zxyd/">在线阅读</A></A> → <A 
            href="http://www.51kaifa.com/zxyd/list.php?BigClass=6">单片机专题</A> → 
            <A 
            href="http://www.51kaifa.com/zxyd/read.php?ID=81">KeilC51使用详解V1.0</A> 
            → <FONT color=#ff9900>正文</FONT> </TD></TR></TBODY></TABLE>
      <TABLE cellSpacing=0 cellPadding=0 width=760 align=center border=0>
        <TBODY>
        <TR>
          <TD width="100%" bgColor=#808080 colSpan=3 height=1></TD></TR>
        <TR>
          <TD vAlign=top width=590>
            <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
              <TBODY>
              <TR>
                <TD align=left width="100%"><!-- $sign哪个页面$digit位置$way等h不循环TR;X循环TR;$num显示个数 --></TD></TR></TBODY></TABLE>  

            <TABLE cellSpacing=0 cellPadding=0 width="94%" align=center 
border=0>
              <TBODY>
              <TR>
                <TD align=middle width="100%"><FONT color=#05006c><B>第七章 Keil 
                  C51的代码效率</B></FONT></TD></TR>
              <TR>
                <TD width="100%" height=6></TD></TR>
              <TR>
                <TD align=middle width="100%" height=18>
                  <TABLE style="BORDER-TOP: #666666 1px solid" height=2 
                  cellSpacing=1 cellPadding=0 width="100%" border=0>
                    <TBODY>
                    <TR>
                      <TD align=middle width="100%" 
                    bgColor=#dce9fc></TD></TR></TBODY></TABLE></TD></TR>
              <TR>
                <TD width="100%" height=6></TD></TR>
              <TR>
                <TD class=p16 id=fontzoom style="LINE-HEIGHT: 1.5" vAlign=top 
                width="100%" height=300><BR><!--画中画广告开始-->
                  <TABLE cellSpacing=0 cellPadding=0 align=left border=0>
                    <TBODY>
                    <TR>
                      <TD><!-- 广告位 --><!-- $sign哪个页面$digit位置$way等h不循环TR;X循环TR;$num显示个数 --></TD></TR></TBODY></TABLE><!--画中画广告结束-->&nbsp;C51程序编译生成汇编代码的效率,是由许多因素共同决定的,对于Keil 
                  C51,主要受以下两种因素影响: 
                  <H2 style="MARGIN-LEFT: 0cm; TEXT-INDENT: 0cm"><A 
                  name=_Toc475103216><SPAN lang=EN-US 
                  style="FONT-SIZE: 16pt">第一节 </SPAN>存储模式的影响</A></H2>
                  <P class=MsoBodyTextFirstIndent><SPAN lang=EN-US><SPAN 
                  style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; 
                  </SPAN>存储模式决定了缺省变量的存储空间,而访问各空间变量的汇编代码的繁简程度决定了代码率的高低。</SPAN></P>
                  <P class=MsoBodyTextFirstIndent>例如:一个整形变量<SPAN 
                  lang=EN-US>i,如放于内存18H、19H空间,则++i的操作编译成四条语句:</SPAN></P>
                  <P class=MsoBodyTextIndent style="MARGIN-LEFT: 36.75pt"><SPAN 
                  lang=EN-US>INC<SPAN style="mso-spacerun: yes">&nbsp; 
                  </SPAN>0x19</SPAN></P>
                  <P class=MsoBodyTextIndent style="MARGIN-LEFT: 36.75pt"><SPAN 
                  lang=EN-US>MOV<SPAN style="mso-spacerun: yes">&nbsp; 
                  </SPAN>A,0x19</SPAN></P>
                  <P class=MsoBodyTextIndent style="MARGIN-LEFT: 36.75pt"><SPAN 
                  lang=EN-US>JNZ<SPAN style="mso-spacerun: yes">&nbsp; 
                  </SPAN>0x272D</SPAN></P>
                  <P class=MsoBodyTextIndent style="MARGIN-LEFT: 36.75pt"><SPAN 
                  lang=EN-US>INC<SPAN style="mso-spacerun: yes">&nbsp; 
                  </SPAN>0x18</SPAN></P>
                  <P class=MsoBodyTextIndent style="MARGIN-LEFT: 36.75pt"><SPAN 
                  lang=EN-US>0x272D:</SPAN></P>
                  <P class=MsoBodyTextFirstIndent>而如果放于外存空间<SPAN 
                  lang=EN-US>0000H、0001H则++i的操作编译成九条语句:</SPAN></P>
                  <P class=MsoBodyTextIndent style="MARGIN-LEFT: 36.75pt"><SPAN 
                  lang=EN-US>MOV DPTR,0001</SPAN></P>
                  <P class=MsoBodyTextIndent style="MARGIN-LEFT: 36.75pt"><SPAN 
                  lang=EN-US>MOVX A,@ DPTR</SPAN></P>
                  <P class=MsoBodyTextIndent style="MARGIN-LEFT: 36.75pt"><SPAN 
                  lang=EN-US>INC A</SPAN></P>
                  <P class=MsoBodyTextIndent style="MARGIN-LEFT: 36.75pt"><SPAN 
                  lang=EN-US>MOVX @ DPTR,A</SPAN></P>
                  <P class=MsoBodyTextIndent style="MARGIN-LEFT: 36.75pt"><SPAN 
                  lang=EN-US>JNz<SPAN style="mso-spacerun: yes">&nbsp; 
                  </SPAN>#5</SPAN></P>
                  <P class=MsoBodyTextIndent style="MARGIN-LEFT: 36.75pt"><SPAN 
                  lang=EN-US>MOV OPTR,#0000</SPAN></P>
                  <P class=MsoBodyTextIndent style="MARGIN-LEFT: 36.75pt"><SPAN 
                  lang=EN-US>MOVX A,@DPTR</SPAN></P>
                  <P class=MsoBodyTextIndent style="MARGIN-LEFT: 36.75pt"><SPAN 
                  lang=EN-US>INC A</SPAN></P>
                  <P class=MsoBodyTextIndent style="MARGIN-LEFT: 36.75pt"><SPAN 
                  lang=EN-US>MOVX @ DPTR,A</SPAN></P>
                  <P 
                  class=MsoBodyTextFirstIndent>就汇编之后的语句而言,对外部存储器的操作较内部存储器操作代码率要低得多,生成的语句为内存的两倍以上,而程序中有大量的这种操作,可见存储模式对代码率的响了。</P>
                  <P class=MsoBodyTextFirstIndent>因此程序设计的原则是</P>
                  <P class=MsoBodyTextIndent style="MARGIN-LEFT: 36.75pt"><SPAN 
                  lang=EN-US>1、存储模式从small-Compact-large依次选择,实在是变量太多,才选large模式。</SPAN></P>
                  <P class=MsoBodyTextIndent style="MARGIN-LEFT: 36.75pt"><SPAN 
                  lang=EN-US>2、即使选择了large模式,对一些常用的局部的或者可放于内存中的变量,最好放于内存中,以尽量提高程序的代码率。</SPAN></P>
                  <H2 style="MARGIN-LEFT: 0cm; TEXT-INDENT: 0cm"><A 
                  name=_Toc475103217><SPAN lang=EN-US 
                  style="FONT-SIZE: 16pt">第二节 </SPAN>程序结构的影响</A></H2>
                  <P 
                  class=MsoBodyTextFirstIndent>程序的结构单元包括模块、函数等等。同样的功能,如果结构越复杂,其所涉及的操作、变量、功能模块函数等就越多,较之结构性好,代码简单的程序其代码率自然就低得多。</P>
                  <P 
                  class=MsoBodyTextFirstIndent>此外程序的运行控制语句,也是影响代码率的关键因素,例如:<SPAN 
                  lang=EN-US>switch -case语句,许多编译器都把它们译得非常复杂,Keil 
                  C51也不例外,相对较为简易的Switch-case语句,编译成跳转指令形式,代码率较高,但对较为复杂的Switch-Case,则要调用一个系统库函数?C?ICASE进行处理,非常复杂。</SPAN></P>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -