<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus MathML//EN" "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_mathml.dtd">
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="m10022">
  
  <name>FIR Filtering: Basic Assembly Exercise for TI TMS320C54x (中文版 Chinese Version)</name>

  <metadata>
  <md:version>1.6</md:version>
  <md:created>2004/04/10 13:06:42 GMT-5</md:created>
  <md:revised>2004/07/18 01:33:29.968 GMT-5</md:revised>
  <md:authorlist>
      <md:author id="klwang">
      <md:firstname>Kanglin</md:firstname>
      
      <md:surname>Wang</md:surname>
      <md:email>klwang@rice.edu</md:email>
    </md:author>
      <md:author id="jpfrantz">
      <md:firstname>Patrick</md:firstname>
      
      <md:surname>Frantz</md:surname>
      <md:email>jpfrantz@rice.edu</md:email>
    </md:author>
      <md:author id="bwade">
      <md:firstname>Brian</md:firstname>
      
      <md:surname>Wade</md:surname>
      <md:email>bwade@uiuc.edu</md:email>
    </md:author>
      <md:author id="dsachs">
      <md:firstname>Daniel</md:firstname>
      <md:othername>Grobe</md:othername>
      <md:surname>Sachs</md:surname>
      <md:email>sachs@uiuc.edu</md:email>
    </md:author>
      <md:author id="moussa">
      <md:firstname>Dima</md:firstname>
      
      <md:surname>Moussa</md:surname>
      <md:email>dmoussa@uiuc.edu</md:email>
    </md:author>
      <md:author id="kramer">
      <md:firstname>Michael</md:firstname>
      <md:othername>L.</md:othername>
      <md:surname>Kramer</md:surname>
      <md:email>kramer@ifp.uiuc.edu</md:email>
    </md:author>
      <md:author id="jake">
      <md:firstname>Jake</md:firstname>
      
      <md:surname>Janevitz</md:surname>
      <md:email>jake@janevitz.com</md:email>
    </md:author>
      <md:author id="markhaun">
      <md:firstname>Mark</md:firstname>
      <md:othername>A.</md:othername>
      <md:surname>Haun</md:surname>
      <md:email>markhaun@uiuc.edu</md:email>
    </md:author>
      <md:author id="mjberry">
      <md:firstname>Matthew</md:firstname>
      <md:othername>J.</md:othername>
      <md:surname>Berry</md:surname>
      <md:email>mjberry@uiuc.edu</md:email>
    </md:author>
      <md:author id="appadwed">
      <md:firstname>Swaroop</md:firstname>
      
      <md:surname>Appadwedula</md:surname>
      <md:email>appadwed@uiuc.edu</md:email>
    </md:author>
      <md:author id="dljones">
      <md:firstname>Douglas</md:firstname>
      <md:othername>L.</md:othername>
      <md:surname>Jones</md:surname>
      <md:email>dl-jones@uiuc.edu</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist>
    <md:maintainer id="klwang">
      <md:firstname>Kanglin</md:firstname>
      
      <md:surname>Wang</md:surname>
      <md:email>klwang@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="jpfrantz">
      <md:firstname>Patrick</md:firstname>
      
      <md:surname>Frantz</md:surname>
      <md:email>jpfrantz@rice.edu</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  <md:keywordlist>
    <md:keyword>assembly</md:keyword>
    <md:keyword>two's-compliment</md:keyword>
    <md:keyword>fractional arithmetic</md:keyword>
    <md:keyword>hexadecimal</md:keyword>
    <md:keyword>stl</md:keyword>
    <md:keyword>mac</md:keyword>
    <md:keyword>rptz</md:keyword>
    <md:keyword>DSP</md:keyword>
  </md:keywordlist>

  <md:abstract>You will work through a section of TI TMS320C54x assembly code by hand.  The instructions include multiplication of fractional numbers in two's complement representation.  
</md:abstract>
</metadata>



  
  <content>
    <section id="sec1">
      <name>汇编练习</name>
      <para id="p1">
	分析下面的程序代码。可以参考 <cnxn document="m10808">Two's Complement and Fractional Arithmetic
	for 16-bit Processors</cnxn>、<cnxn document="m10806">Addressing Modes for TI TMS320C54x</cnxn>、以及 <cite src="http://www-s.ti.com/sc/psheets/spru172c/spru172c.pdf">Mnemonic
	Instruction Set</cite> 等手册中的内容。
      </para>
      <code type="block">
	<![CDATA[
	1  FIR_len .set    3
	2
	3  ; Assume: 
	4  ;   BK = 3
	5  ;   AR0 = 1
	6  ;   AR2 = 1000h
	7  ;   AR3 = 1004h
	8  ;
	9  ;   FRCT = 1
	10
	11      stl     A,*AR3+%
	12      rptz    A,(FIR_len-1)
	13      mac     *AR2+0%,*AR3+0%,A
	]]>
      </code>
      <para id="p2">
	任何以"<code>;</code>" 开头的代码行均为注释。在这里，注释行告诉你在第一个指令<code>stl</code>执行前辅助寄存器<code>BK</code>、<code>AR0</code>、<code>AR2</code>和<code>AR3</code>中的内容。注意以 "<code>h</code>" 结尾或以 <code>0x</code> 开头的数字均为 <term>十六进制</term> 数值。
      </para>
      <example id="example1">
	<para id="p2b">
	  1000h 和0x1000 均表示十进制数值4096。
	</para>
      </example>
      <para id="p3">
	假设起始地址为<code>1000h</code>的内存中的初始数据为：
      </para>
      <figure id="tab1fig">
	<media type="image/png" src="reg1.png"/>
	<caption>内存中的数据分配（执行前）</caption> 
      </figure>
      <para id="p3b">
	在熟悉了<code>stl</code>、
	<code>rptz</code> 和 <code>mac</code> 等指令后，逐行执行代码并将累加器 <code>A</code> 及辅助寄存器
	<code>AR2</code> 和 <code>AR3</code> 中的数值记录在<cnxn target="table2fig"/>所提供的表格中。另外，在三行指令全部运行之后将内存中的数值记录在 <cnxn target="table3fig"/> 所提供的表格中。
      </para>
      <figure id="table2fig">
	<table id="table2" frame="all">
	  <tgroup cols="4">
	    <thead>
	      <row>
		<entry>A</entry>
		<entry>AR2</entry>
		<entry>AR3</entry>
		<entry/>
	      </row>
	    </thead>
	    <tbody>
	      <row>
		<entry><code>00 0000 8000h</code></entry>
		<entry><code>1000h</code></entry>
		<entry><code>1004h</code></entry>
		<entry>at start of code</entry>
	      </row>
	      <row>
		<entry/>
		<entry/>
		<entry/>
		<entry>after <code>stl</code> instruction</entry>
	      </row>
	      <row>
		<entry/>
		<entry/>
		<entry/>
		<entry>after <code>rptz</code> instruction</entry>
	      </row>
	      <row>
		<entry/>
		<entry/>
		<entry/>
		<entry>after first <code>mac</code> instruction</entry>
	      </row>
	      <row>
		<entry/>
		<entry/>
		<entry/>
		<entry>
		  after second <code>mac</code> instruction
		</entry>
	      </row>
	      <row>
		<entry/>
		<entry/>
		<entry/>
		<entry>after third <code>mac</code> instruction</entry>
	      </row>
	    </tbody>
	  </tgroup>
	</table>
	<caption>执行结果</caption>
      </figure>
      <para id="p4">
	在练习过程中要注意累加器 <code>A</code> 是40位寄存器，而且乘法器是工作在 <term>分数算法模式（fractional arithmetic mode）</term>下。在这种模式下，所有DSP中的整数都被当作分数来处理，ALU（运算器）中整数乘法器的运算结果都会被左移一位。（在没有特别指明的情况下，认为所有练习中的乘法器都是工作在分数算法模式下。）所以如果仅仅执行将两个整数相乘的操作，运算器（通过<code>mac</code>指令）所产生的结果将是实际值的两倍。DSP的数值表示及算法在<cnxn document="m10808">Two's Complement and Fractional Arithmetic
	for 16-bit Processors</cnxn>中有更详细的描述。
      </para>
      <figure id="table3fig">
	<media type="image/png" src="reg2.png"/> 
	<caption>内存中的数据分配（执行前）</caption>
      </figure>
    </section>
  </content>
</document>
