📄 freescale 汇编语言源程序标准.htm
字号:
<TBODY>
<TR bgColor=#f8f8f8>
<TD><STRONG><FONT color=#ff0000>博客信息</FONT></STRONG></TD></TR>
<TR bgColor=#ffffff>
<TD>
<P><FONT color=#ff0000>blog名称:匠人的百宝箱<br>日志总数:1837<br>评论数量:707<br>留言数量:24<br>访问次数:1352231<br>建立时间:2005年5月18日</FONT></P>
<P align=center><FONT size=3><A href="http://cxjr.21ic.org/" target=_blank><IMG style="BORDER-LEFT-COLOR: #000000; BORDER-BOTTOM-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-RIGHT-COLOR: #000000" src="http://blog.21ic.org/uploadfile-/20051217161245384.gif" border=0></A></FONT></P></TD></TR></TBODY></TABLE></P>
<TD vAlign=top align=middle width=660>
<P align=left>
<TABLE style="TABLE-LAYOUT: fixed; WORD-BREAK: break-all" cellSpacing=1 cellPadding=3 width="100%" bgColor=#cccccc border=0>
<TBODY>
<TR bgColor=#f8f8f8>
<TD><STRONG><FONT color=#ff0000>广告(2号位)</FONT></STRONG></TD></TR>
<TR bgColor=#ffffff>
<TD>
<DIV align=center>
<ADDRESS> <A href="http://www.3gmcu.com/" target=_blank><IMG style="BORDER-LEFT-COLOR: #000000; BORDER-BOTTOM-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-RIGHT-COLOR: #000000" src="http://blog.21ic.org/uploadfile-/2005122820932375.gif" border=0></A></ADDRESS></DIV></TD></TR></TBODY></TABLE></P>
<P align=left>
<TABLE style="TABLE-LAYOUT: fixed; WORD-BREAK: break-all" cellSpacing=1 cellPadding=3 width="100%" bgColor=#cccccc border=0>
<TBODY>
<TR bgColor=#f8f8f8>
<TD><STRONG><FONT color=#ff0000>酷贴推荐 <FONT color=#ff0000>[</FONT><A href="http://blog.21ic.org/more.asp?name=cxjr&id=7437" target=_blank><U><FONT color=#ff0000>更多…… </FONT></U></A><FONT color=#ff0000>]</FONT></FONT></STRONG></TD></TR>
<TR bgColor=#ffffff>
<TD>
<P align=left>
<TABLE borderColor=#cccccc cellSpacing=2 cellPadding=3 width="100%" bgColor=#ffffff border=1>
<TBODY>
<TR>
<TD>
<P align=center> [<A href="http://blog.21ic.com/more.asp?name=cxjr&id=16591"><U><FONT style="BACKGROUND-COLOR: #ffff00" color=#ff0000>岁月如歌——记匠人的百宝箱博客开通一周年</FONT></U></A>] [<A href="http://blog.21ic.com/more.asp?name=cxjr&id=17379"><U><FONT color=#0000ff>事件驅動觀念</FONT></U></A>] [<A href="http://blog.21ic.com/more.asp?name=cxjr&id=17377"><U><FONT color=#0000ff>单片机程序设计中运用事件驱动机制</FONT></U></A>]</P></TD>
<TR>
<TD>
<P align=center>[<A href="http://blog.21ic.com/more.asp?name=cxjr&id=18941"><U><FONT color=#0000ff>计算机族必喝的健康饮料</FONT></U></A>] [<A href="http://blog.21ic.com/more.asp?name=cxjr&id=18714"><U><FONT color=#0000ff>男人·女人·电脑</FONT></U></A>] [<A href="http://blog.21ic.com/more.asp?name=cxjr&id=18713"><U><FONT color=#0000ff>学编程的人不能不看的好文章</FONT></U></A>] [<A href="http://blog.21ic.com/more.asp?name=cxjr&id=18742"><U><FONT color=#0000ff>PIC机与MCS-51的区别</FONT></U></A>]</P></TD>
<TR>
<TD>
<P align=center>[<A href="http://blog.21ic.com/more.asp?name=cxjr&id=19794"><U><FONT color=#0000ff>一种软件去除键抖动的方法</FONT></U></A>] [<A href="http://blog.21ic.com/more.asp?name=cxjr&id=19752"><U><FONT color=#0000ff>司马光,你干嘛砸缸?</FONT></U></A>] [<A href="http://blog.21ic.com/more.asp?name=cxjr&id=19748"><U><FONT color=#0000ff>编码规范</FONT></U></A>] </P></TD>
<TR>
<TD>
<P align=center><FONT color=#ff0000>调查:[</FONT><A href="http://21icbbs.com/club/vote/showvote.asp?id=98" target=_blank><U><FONT color=#ff0000>您认为《匠人的百宝箱》如何?</FONT></U></A><FONT color=#ff0000>] [</FONT><A href="http://21icbbs.com/club/vote/showvote.asp?id=129" target=_blank><U><FONT color=#ff0000>您最喜欢《匠人的百宝箱》中哪个栏目?</FONT></U></A><FONT color=#ff0000>] [</FONT><A href="http://blog.21ic.com/more.asp?name=cxjr&id=18993"><U><FONT color=#ff0000>请网友来评选最佳队员专栏</FONT></U></A><FONT color=#ff0000>]</FONT> </P></TD></TR></TBODY></TABLE></P></TD></TR></TBODY></TABLE></P>
<P align=left>
<TABLE style="TABLE-LAYOUT: fixed; WORD-BREAK: break-all" cellSpacing=1 cellPadding=3 width="100%" bgColor=#cccccc border=0>
<TBODY>
<TR bgColor=#f8f8f8>
<TD>
<P align=left><FONT color=#ff0000 size=4><STRONG><img src=images/face/1.gif ><a href=blog.asp?name=cxjr&subjectid=66>[编程技巧]<a href=more.asp?name=cxjr&id=3562>Freescale 汇编语言源程序标准</a></STRONG></FONT><BR>程序匠人 2005-9-29 13:14:00 <a href=more.asp?name=cxjr&id=3562>阅读全文(932)</a> | <a href=more.asp?name=cxjr&id=3562#comment>回复(0)</a> | <a href=showtb.asp?id=3562 target=_blank>引用(0)</a><BR><FONT face=宋体 size=4><STRONG>[</STRONG></FONT><A href="http://blog.21ic.org/more.asp?name=cxjr&id=6250" target=_blank><FONT face=宋体 color=#ff0000 size=4><STRONG>广告8号位</STRONG></FONT></A><FONT face=宋体 size=4><STRONG>] [</STRONG></FONT><A href="http://blog.21ic.org/more.asp?name=cxjr&id=7705"><U><FONT style="BACKGROUND-COLOR: #000000" face=宋体 color=#ffffff size=4><STRONG>免责声明</STRONG></FONT></U></A><FONT face=宋体 size=4><STRONG>] [</STRONG><A href="http://blog.21ic.com/more.asp?name=cxjr&id=18993"><U><FONT style="BACKGROUND-COLOR: #ffff00" color=#ff0000 size=3><STRONG>请网友来评选最佳队员专栏!</STRONG></FONT></U></A><STRONG>]</STRONG></FONT></P></TD></TR>
<TR bgColor=#ffffff>
<TD height=0>
<DIV align=left><P>Freescale 汇编语言源程序标准<BR>------------------------------------------------------<BR>此标准包括:<BR> 行的长度限制<BR> 可接受的字符和字符格式<BR> 源程序列的分配<BR> 注释格式<BR>-------------------------------------------------------<BR>行的长度:<BR> 为了便于阅读和打印,Freescale使用mono-spaced字体,这种字体每个字符宽度相等.字体大小是9 point;最大行长为70个字符.<BR>示例如下:<BR><FONT face="Courier New">; 1 2 3 4 5 6 7<BR>;234567890123456789012345678901234567890123456789012345678901234567890<BR>asc2hex: bsr ishex ;check for valid hex # first<BR> bne dunA2asc ;if not just return<BR> cmp #'9' ;check for A-F ($41-$46)<BR> bls notA2F ;skip if not A-F</FONT><BR>列表输出文件示例如下:<BR><FONT face=Courier>; 1 2 3 4 5 6 7 8 9<BR>;23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123<BR> 551 C1D7 AD EA asc2hex: bsr ishex ;check for valid hex # first<BR> 552 C1D9 26 0A bne dunA2asc ;if not just return<BR> 553 C1DB A1 39 cmp #'9' ;check for A-F ($41-$46)<BR> 554 C1DD 23 02 bls notA2F ;skip if not A-F<BR></FONT>从以上可以看出列宽最大到93字符,因为列表输出文件并不能给读者提供更多的有用信息,因此Freescale最大用到每行93字符.<BR>-----------------------------------------------------------<BR>避免使用TAB字符<BR> TAB字符在不同的字处理软件中有不同的含义,当把源文件提交给其它文档时可能会出现问题,所以要避免使用TAB,而用多个空格代替.<BR>-----------------------------------------------------------<BR>源程序列分配<BR> 源程序由标号,助记符,操作数和注释组成一行;<BR> 标号在第1列开始<BR> 指令助记符在第13列开始<BR> 操作数在19列开始<BR> 注释在31列开始;如果操作数超过了30列,注释必须和操作数的最后一个字符分开1到2个空格.<BR> 如果一个标号超过11个字符,就应该另起一行,并在31列做注释.短标号也可以另起一行来突出它,这经常用在一个子程序开始处.见图3<BR><FONT face=Courier>; 1 2 3 4 5 6 7<BR>;234567890123456789012345678901234567890123456789012345678901234567890<BR>label: mne operand ;comment<BR> brset very,long,operand ;comment can’t start in col 31<BR>veryLongLabel: ;long label on separate line<BR> nop ;instruction with no operands<BR>short: ;short label may use a separate line<BR> mne operand ;code to which ‘short’ refers</FONT><BR>-----------------------------------------------------------<BR>大写和小写字符<BR> 源程序中协调一致的大小写可以增强可读性,并使程序变得容易理解.<BR> 标号<BR> 标号可以混和使用大小写,但无论在哪儿引用它都应该严格匹配其初始定义.<BR> 指令助记符<BR> 指令助记符,汇编指示和预处理应当使用小写字符.尽管他们可以使用大写字符,但是输入时要敲shift键,而且大写字符使读者变得不能专心阅读.<BR> 各种各样得文档中指令使用大写字符仅仅是为了突出他们.有经验得程序员使用小写字符不但容易输入而且容易阅读.<BR>寄存器和位<BR>Freescale的头文件中使用大写字符定义寄存器和位.位的定义有两种方法位号(0-7)和位屏蔽码.位操作指令使用位号;逻辑操作指令使用屏蔽码方式.屏蔽码在位号前面加一个小写字母m前缀.示例见图4<BR><FONT face=Courier>PTAD: equ $00 ;I/O port A data register<BR>; bit numbers for use in BCLR, BSET, BRCLR, and BRSET<BR>PTAD7: equ 7 ;bit #7<BR>PTAD6: equ 6 ;bit #6<BR>PTAD5: equ 5 ;bit #5<BR>PTAD4: equ 4 ;bit #4<BR>PTAD3: equ 3 ;bit #3<BR>PTAD2: equ 2 ;bit #2<BR>PTAD1: equ 1 ;bit #1<BR>PTAD0: equ 0 ;bit #0<BR>; bit position masks<BR>mPTAD7: equ %10000000 ;port A bit 7<BR>mPTAD6: equ %01000000 ;port A bit 6<BR>mPTAD5: equ %00100000 ;port A bit 5<BR>mPTAD4: equ %00010000 ;port A bit 4<BR>mPTAD3: equ %00001000 ;port A bit 3<BR>mPTAD2: equ %00000100 ;port A bit 2<BR>mPTAD1: equ %00000010 ;port A bit 1<BR>mPTAD0: equ %00000001 ;port A bit 0<BR></FONT>-----------------------------------------------------------<BR>标号<BR> 标号可以混和使用大小写,但避免使用下划线,我们推荐使用大写字符做为多字符标号的分界.例如:VeryLongLabel代替ery_long_label<BR> 标号定义并加一个冒号,尽管有很多编译器不需要这个冒号.</P>
<P>文件和子程序头<BR> 文件和子程序前面需要一个块来说明他的用途和目的,称为头<BR> 图5是典型的文件头<BR><FONT face="Courier New">;********************************************************************************************<BR>;* Title: 9S08GB60_v1r2.equ (c) FREESCALE Inc. 2003 All rights reserved.<BR>;********************************************************************************************<BR>;* Author: Jim Sibigtroth - Freescale TSPG<BR>;*<BR>;* Description: Register and bit name definitions for 9S08GB60<BR>;*<BR>;* Documentation: 9S08GB60 family Data Sheet for register and bit explanations<BR>;* HCS08 Family Reference Manual (HCS08RM1/D) appendix B for explanation of equate files<BR>;*<BR>;* Include Files: none<BR>;*<BR>;* Assembler: Metrowerks Code Warrior 3.0 (pre-release)<BR>;* or P&E Microcomputer Systems - CASMS08 (beta v4.02)<BR>;*<BR>;* Revision History:<BR>;* Rev # Date Who Comments<BR>;* ----- ----------- ------ --------------------------------------------<BR>;* 1.2 24-Apr-03 J-Sib correct minor typos in comments<BR>;* 1.1 21-Apr-03 J-Sib comments and modify for CW 3.0 project<BR>;* 1.0 15-Apr-03 J-Sib Release version for 9S09GB60<BR>;********************************************************************************************</FONT></P>
<P> 其中有些是必须的,有些可以省略<BR> 文件名:必须,包括文件名和后缀<BR> 版权声明:必须<BR> 作者:必须,有些文件可能重复使用数年,有时需要帮助时可以联系他们<BR> 描述:必须,但仅是摘要,更多信息应该在一个单独的文件中<BR> 文档:另外一个文件,她是对这个文件的详细说明<BR> 包含文件:需要时必须<BR> 汇编器:汇编器的厂商和版本,非常重要<BR> 版本历史:提供何时,何人,哪个文件被修改等信息</P>
<P> 图6是子程序头模板,可以根据子程序的复杂程度适当增减<BR><FONT face=Courier>;******************************************************************<BR>;* RoutineName - expanded name or phrase describing purpose<BR>;* Brief description, typically a few lines explaining the<BR>;* purpose of the program.<BR>;*<BR>;* I/O: Explain what is expected and what is produced<BR>;*<BR>;* Calling Convention: How is the routine called?<BR>;*<BR>;* Stack Usage: (when needed) When a routine has several variables<BR>;* on the stack, this section describes the structure of the<BR>;* information.<BR>;*<BR>;* Information about routines that are called and any registers<BR>;* that get destroyed. In general, if some registers are pushed at<BR>;* the beginning and pulled at the end, it is not necessary to<BR>;* describe this in the routine header.<BR>;******************************************************************</FONT></P>
<P><BR><FONT face="Courier New">;******************************************************************<BR>;* GetSRec - retrieve one S-record via SCI1<BR>;* Terminal program should delay after <cr> to allow programming<BR>;* recommended delay after <cr> is TBDms, no delay after chars.<BR>;* Only header (S0), data (S1), and end (S9) records accepted<BR>;*<BR>;* Calling Convention:<BR>;* ais #-bufferLength ;# of data bytes + 4 (typ.36)<BR>;* jsr GetSRec ;read S-record onto stack<BR>;* bne error ;Z=0 means record bad<BR>;*;<BR>;*; 'bufferLength' is defined in calling program not in this<BR>;*; subroutine, calling routine must also deallocate buffer space<BR>;*; after processing the information that was returned on the stack<BR>;*;<BR>;* ais #bufferLength ;deallocate buffer space<BR>;*<BR>;* Returns: all but CCR Z-bit returned on stack (see stack map)<BR>;* CCR Z-bit = 1 if valid S-record; CCR Z-bit = 0 if not valid<BR>;* S-record type @ sp+1 (1 ASCII byte) ($30, $31, or $39)<BR>;* S-record size @ sp+2 (1 hex byte) (# of data bytes 0-31)<BR>;* S-record addr @ sp+3 (2 hex bytes) (addr of 1st data value)<BR>;* S-record data @ sp+5..sp+36 (up to 32 hex data bytes)<BR>;*<BR>;* Stack map... S-record, return, and locals on stack<BR>;* | | <-sp (after local space allocated)<BR>;* H:X-> | SRecCount |<BR>;* | SRecChkSum | <-sp (after jsr)<BR>;* | ReturnAddr msb |<BR>;* | ReturnAddr lsb | <-sp (after rts)<BR>;* | SRecTyp |<BR>;* | SRecSize |<BR>;* H:X-> | SRecAddr msb |<BR>;* | SRecAddr lsb |<BR>;* | SRecData 00 |<BR>;* | SRecData 01 | etc... (up to 32 bytes)<BR>;*<BR>;* Data values are read as two ASCII characters, converted to<BR>;* hex digits, combined into 1 hex value, and stored on stack<BR>;*<BR>;* Calls: GetChar, PutChar, and GetHexByte<BR>;* Changes: A, H, and X<BR>;******************************************************************<BR></FONT> 图7是一个复杂的头,它使用堆栈传递参数并且附加的堆栈来分配局部变量.虽然可以描述很多的细节但我们规定头的描述最好限制在3到4行.如果要求更多的细节,可以使用一个的单独的文件,而不是描述在代码文件中.<BR> 调用协议是想当复杂的,因为用户必须分配传递参数的堆栈空间,堆栈内的参数包括用户填充的和本子程序返回的.当这个子程序放回后,一条BNE指令用来检查Z标志来检查本子程序是否成功得到一个S记录.当检查到一个错误或可处理的返回数据,调用程序必须处理调用前分配的传递参数的堆栈空间.<BR> 堆栈的用法也非常复杂,因为本子程序在堆栈上处理信息,所以给读者提供一个堆栈信息映像来帮助读者理解这个子程序是非常重要的.这个映像展示了一个最大的块,这个块是在调用子程序之前分配的.返回地址做为JSR指令的结果也存储在堆栈上.本子程序内部分配使用的2字节局部变量必须在返回调用程序之前处理完毕.<BR> 在这个子程序的头的最后<BR> 调用项:列出本子程序需要调用的子程序.<BR> 改变项:列出执行本子程序改变的寄存器<BR><FONT face=Courier>;******************************************************************<BR>;* GetChar - wait indefinitely for a character to be received<BR>;* through SCI1 (until RDRF becomes set) then read char into A<BR>;* and return. Reading character clears RDRF. No error checking.<BR>;*<BR>;* Calling convention:<BR>;* jsr GetChar<BR>;*<BR>;* Returns: received character in A<BR>;******************************************************************<BR></FONT> 图8展示一个简单的子程序头,这个头不包含堆栈信息,也不调用其它子程序,所以这些信息都不需要了.<BR>----------------------------------------------------------------<BR>注释:<BR> 注释是非常重要的,大多数注释格式是以分号并从31列开始直到行尾.避免注释重复说明指令内容.<BR> 例如:lda pta ;读A口数据.<BR> 取而代之注释应传递这样一些信息:为什么指令在这儿,指令如何描述程序功能或系统包含的嵌入式微控制器.<BR> 这是一个好的注释:<BR> lda PTAD ;check for low on bit 7 (step switch)<BR> 如果注释过长不能在一行完成,那么应该在第1列单独起一行,但不宜频繁使用以防淹没代码行.如果是多行注释可以写成注释块,注释块与代码行以空注释行相分隔如下所示:<BR><FONT face="Courier New">;<BR>; In-line comment block. On rare occasions, an extended comment<BR>; is needed to explain some important aspect of a program. Each<BR>; line of the extended comment starts with a semicolon. A line<BR>; with nothing but a semicolon in column 1 is used above and<BR>; below the block comment to set it apart from code.<BR>;</FONT></P>
<P>注释格式基础理论<BR> 注释或空行可以使程序组成逻辑段以提高可读性.子程序头块可以标识一个子程序的开始.类似的分隔也是非常有用的.<BR></P><BR></DIV></TD></TR></TBODY></TABLE><FONT color=#ff0000></FONT>
<P align=right><A href="http://blog.21ic.org/blog.asp?name=cxjr" target=_blank><FONT color=#ff0000>如果你的‘芯’是一座作坊,我愿做那不知疲倦的程序匠。打造一流博客,我们每天在努力!</FONT></A></P><A href="http://blog.21ic.org/blog.asp?name=cxjr" target=_blank><FONT color=#ff0000></FONT></A><br><a name='comment'></a><table width='90%' border='0' align='center' cellspacing='0' cellpadding='0'> <tr> <td><strong>发表评论:</strong></tr></td></table>
<table width='90%' border='0' align='center' cellspacing='0' cellpadding='0'> <tr> <td><table align='left' width='100%' border='0' cellspacing='0' cellpadding='0'>
<form action='more.asp?name=cxjr&id=3562&action=addcomment_ic' method='post' name='commentform' onSubmit='return Verifycomment()'>
<tr><td height='25' align='left'>昵称:<input name='UserName' type='text' id='UserName' size='15' maxlength='20' value=''></td></tr>
<tr><td height='25' align='left'>密码:<input name='Password' type='password' id='Password' size='15' maxlength='20' value=''> (游客无须输入密码)</td></tr>
<tr ><td height='25' align='left' >验证码:<input name='GetCode' type='text' id='GetCode' size='12' maxlength='20' /> <img src='inc/code.asp' width='40' height='10' border='0' /><td></tr><tr ><td height='25' align='left' >主页:<input name='homepage' type='text' id='homepage' size='42' maxlength='50' value='http://'><td></tr><tr ><td height='25' align='left' >标题:<input name='commenttopic' type='text' id='commenttopic' size='42' maxlength='50' value='回复:Freescale 汇编语言源程序标准'><td></tr><tr height='200'><td ><INPUT type='hidden' name='edit' id='edit' value=''>
<link rel="STYLESHEET" type="text/css" href="images/edit.css">
<Script Src="images/DhtmlEdit.js"></Script>
<table id="oblog_Container" class="oblog_Body" height=100% width=350 cellpadding=1 cellspacing=0 border=0 >
<tr>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -