<?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</name>

  <metadata>
  <md:version>2.19</md:version>
  <md:created>2001/05/30</md:created>
  <md:revised>2003/07/31 09:38:21.523 GMT-5</md:revised>
  <md:authorlist>
    <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: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="moussa">
      <md:firstname>Dima</md:firstname>
      
      <md:surname>Moussa</md:surname>
      <md:email>dmoussa@uiuc.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="jake">
      <md:firstname>Jake</md:firstname>
      
      <md:surname>Janevitz</md:surname>
      <md:email>jake@janevitz.com</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="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="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:authorlist>

  <md:maintainerlist>
    <md:maintainer id="appadwed">
      <md:firstname>Swaroop</md:firstname>
      
      <md:surname>Appadwedula</md:surname>
      <md:email>appadwed@uiuc.edu</md:email>
    </md:maintainer>
    <md:maintainer 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:maintainer>
    <md:maintainer 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:maintainer>
    <md:maintainer 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:maintainer>
    <md:maintainer id="butala">
      <md:firstname>Mark</md:firstname>
      <md:othername>D.</md:othername>
      <md:surname>Butala</md:surname>
      <md:email>butala@uiuc.edu</md:email>
    </md:maintainer>
    <md:maintainer id="rars">
      <md:firstname>Ricardo</md:firstname>
      <md:othername>Anthony</md:othername>
      <md:surname>Radaelli-Sanchez</md:surname>
      <md:email>ricky@alumni.rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="rlmorris">
      <md:firstname>Robert</md:firstname>
      <md:othername>L.</md:othername>
      <md:surname>Morrison</md:surname>
      <md:email>rlmorris@uiuc.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>Assembly Exercise</name>
      <para id="p1">
	Analyze the following lines of code.  Refer to <cnxn document="m10808">Two's Complement and Fractional Arithmetic
	for 16-bit Processors</cnxn>, <cnxn document="m10806">Addressing Modes for TI TMS320C54x</cnxn>,
	and the <cite src="http://www-s.ti.com/sc/psheets/spru172c/spru172c.pdf">Mnemonic
	Instruction Set</cite> manual for help.
      </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">
	Anything following a "<code>;</code>" is considered a comment.
	In this case, the comments indicate the contents of the
	auxiliary registers, <code>BK</code>, <code>AR0</code>,
	<code>AR2</code>, and <code>AR3</code> before the execution of
	the first instruction, <code>stl</code>.  Note that any number
	followed by an "<code>h</code>" or preceded with a
	<code>0x</code> represents a <term>hexadecimal</term> value.
      </para>
      <example id="example1">
	<para id="p2b">
	  1000h and 0x1000 both refer to the decimal number 4096.
	</para>
      </example>
      <para id="p3">
	Assume that the data memory is initialized as follows starting
	at location <code>1000h</code>.
      </para>
      <figure id="tab1fig">
	<media type="image/png" src="reg1.png"/>
	<caption>Data Memory Assignment (before execution)</caption> 
      </figure>
      <para id="p3b">
	After familiarizing yourself with the <code>stl</code>,
	<code>rptz</code>, and <code>mac</code> instructions, step
	through each line of code and record the values of the
	accumulator <code>A</code> and auxiliary registers
	<code>AR2</code> and <code>AR3</code> in the spaces provided
	in <cnxn target="table2fig"/>.  Additionally, record the value
	of the memory contents after all three instructions have been
	"executed" in the blank data memory table provided in <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>Execution Results</caption>
      </figure>
      <para id="p4">
	When working through the exercise, take into account that the
	accumulator <code>A</code> is a 40-bit register, and that the
	multiplier is in the <term>fractional arithmetic mode</term>.
	In this mode, integers on the DSP are interpreted as
	fractions, and the multiplier will treat them accordingly.
	This is done by shifting the result of the integer multiplier
	in the ALU left one bit. (Assume the multiplier is in
	fractional arithmetic mode for all exercises, unless you are
	told otherwise.)  Therefore, multiplies performed by the ALU
	(via the <code>mac</code> instruction) produce a result that
	is twice what you would expect if you just multiplied the two
	integers together.  DSP numerical representation and
	arithmetic are described further in <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>Data Memory Assignment (after execution)</caption>
      </figure>
    </section>
  </content>
</document>
