📄 exp2.html
字号:
<html><head><meta http-equiv="Content-Type"content="text/html; charset=iso-8859-1"><meta name="GENERATOR" content="Microsoft FrontPage Express 2.0"><title></title></head><body><p><font size="5"><strong>Experiments for Chapter 2</strong></font></p><blockquote> <p align="left"><a href="exp2.zip">Download Chapter 2 experimental software programs</a></p></blockquote><p align="left"><a href="#top"><font size="1">Back to Top</font></a><input type="button" value="go back" onclick="history.go(-1)"> </p><hr><p align="left"><font size="4"><strong>Assembly programming</strong></font></p><blockquote> <blockquote> <p align="left">There are 2experiments in this chapter:</p> <blockquote> <ol> <li><p align="left">Experiment 2A - Interfacing C with Assembly Code</p> </li> <li><p align="left">Experiment 2B - Addressing Modes</p> </li> </ol> </blockquote> <p align="left">These experiments provide the basic programming exercises using the TMS320C55x assembly language with interface with C language. </p> <form method="POST"> <hr> <p><font color="#0000FF" size="4"><strong>Experiment 2A - Interfacing C with Assembly code</strong></font></p> <p align="left">The first experiment demonstrates how to interface an assembly routine with a C function using TMS320C55x DSP. The main C function <a href="exp2/exp2a.c"><em>exp2a.c</em></a> in Table E2-1 and assembly routine <a href="exp2/exp2_sum.asm"><em>exp2_sum.asm</em></a> is given by Table E2-2.</p> <p align="left"> </p> <p align="center">Table E2-1 The list of C function for Experiment 2A.</p> <p align="center"><textarea name="Exp2a" rows="7" cols="70">/* exp2a.c - Interfacing C with Assembly language*//* Assembly routine */extern int sum(int *); /* define x1[] as global array */int x[2]={0x1234,0x4321}; /* define result s as global variable */int s;void main(){ s = sum (x); /* return sum product */} </textarea> </p> <p align="center"> </p> <p align="center">Table E2-2 The TMS320C55x assembly routine, <em>exp2_sum.asm</em>.</p> <p align="center"><textarea name="exp2_sum.asm" rows="7" cols="70">* * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** exp2_sum.asm SUM subroutine* * called by exp2a.c* Input: Array pointer* Output: Return sum result in T0** * * * * * * * * * * * * * * * * * * * * * * * * * * * * .global _sum_sum mov *AR0+,AC0 ; AC0 = x[1] add *AR0+,AC0 ; AC0 = x[1]+x[2] mov AC0,T0 ret ; Return T0 .end</textarea> </p> <p align="center"> </p> <p>To conduct Experiment 2A, following these steps:</p> <ol> <li>Using CCS to create the project, <em>exp2a</em>. </li> <li>Include the linker command file <font face="Courier New">exp2.cmd</font>, the function <font face="Courier New">exp2a.c</font>, and the assembly routine <font face="Courier New">exp2_sum.asm</font>.</li> <li>Use <font face="Courier New">rts55.lib</font> for <font face="Courier New">main()</font> function initialization and build the project.</li> <li>Compile and debug the code, then load <font face="Courier New">exp2a.out</font> and issue Go-Main command.</li> <li>Watch AC0, AR0, and T0 in the CPU register window. Watch memory location "<font face="Courier New">s</font>" and "<font face="Courier New">x</font>".</li> <li>Single step through the assembly code.</li> <li>Examine the assembly code, <font face="Courier New">exp2a.asm</font> that the C compiler generated. How is the return value passed to the C calling function?</li> </ol> </form> </blockquote></blockquote><p align="left"><a href="#top"><font size="1">Back to Top</font></a><input type="button" value="go back" onclick="history.go(-1)"> </p><hr><form method="POST"> <p align="center"><font color="#0000FF" size="4"><strong>Experiment 2B - Addressing Modes </strong></font></p> <blockquote> <blockquote> <p>The purpose of Experiment 2B is to understand the addressing modes that the TMS320C55x supports. The C function <a href="exp2/exp2b.c"><em>exp2b.c</em></a> is listed in Table E5-3 for reference. Experiment 2B consists of several sub-routines to demonstrate different addressing modes. The assembly routine <a href="exp2/exp2b_1.asm"><em>exp2b_1.asm</em></a> uses the absolute addressing mode and it is given in Table E2-4. The assembly routine <a href="exp2/exp2b_2.asm"><em>exp2b_2.asm</em></a> uses the direct addressing mode and it is shown in Table E2-5. The assembly routine <a href="exp2/exp2b_3.asm"><em>exp2b_3.asm</em></a> uses the indirect addressing mode to perform the dot-product calculation and it can be found in Table E2-6. Finally, the assembly routine <a href="exp2/exp2b_4.asm"><em>exp2b_4.asm</em></a> uses the indirect addressing mode in conjunction with parallel instructions to improve the dot-product calculation efficiency. It is listed in Table E2-7. </p> </blockquote> </blockquote> <p align="center"> </p> <p align="center">Table E2-3 List of C function for Experiment 2B.</p> <p align="center"><textarea name="exp2b.c" rows="7" cols="70">/* --------------------------------------- exp2b.c Interfacing C with Assembly Langugage and using Different Addressing Modes------------------------------------------*/extern void exp2b_1(void);extern void exp2b_2(void); extern int exp2b_3(int *, int *);extern int exp2b_4(int *, int *); int Ai[8];int Xi[8]; int result1,result2;void main(){ exp2b_1(); exp2b_2(); result1 = exp2b_3(Ai, Xi); result2 = exp2b_4(Ai, Xi);} </textarea> </p> <p align="center"> </p> <p align="center">Table E2-4 Assembly routine demonstrates the absolute addressing mode.</p> <p align="center"><textarea name="exp2b_1.asm" rows="7" cols="70">* * * * * * * * * * * * * * * * * * * * * * * * * * *** exp2b_1: Absolute Addressing Mode** * * * * * * * * * * * * * * * * * * * * * * * * * * .def _exp2b_1 .ref _Ai .text_exp2b_1 ;; (1) Absolute addressing; mov #1,*(_Ai) ; Absolute addressing mode mov #2,*(_Ai+1) ; Initialize Ai[8]={1,2,3,4,5,6,7,8} mov #3,*(_Ai+2) mov #4,*(_Ai+3) mov #5,*(_Ai+4) mov #6,*(_Ai+5) mov #7,*(_Ai+6) mov #8,*(_Ai+7) ret .end</textarea> </p> <p align="center"> </p> <p align="center">Table E2-5 Assembly routine demonstrates the direct addressing mode.</p> <p align="center"><textarea name="exp2b_2.asm" rows="7" cols="70">* * * * * * * * * * * * * * * * * * * * * * * * * * *** exp2b_2: Direct Addressing Mode** * * * * * * * * * * * * * * * * * * * * * * * * * * .def _exp2b_2 .ref _Xi .text_exp2b_2 ;; Direct addressing; btstclr #14,*(ST1),TC1 ; Turn off CPL bits for direct addressing mode amov #_Xi,XDP ; Load direct addressing data-page pointer .dp _Xi mov #9,@_Xi ; Direct addressing mode mov #3,@_Xi+1 ; Initialize Xi[8]={9,3,2,0,1,9,7,1} mov #2,@_Xi+2 mov #0,@_Xi+3 mov #1,@_Xi+4 mov #9,@_Xi+5 mov #7,@_Xi+6 mov #1,@_Xi+7 xcc continue,TC1 bset CPL ; Turn CPL bit back on continue ret .end </textarea> </p> <p align="center"> </p> <p align="center">Table E2-6 Assembly routine demonstrates the indirect addressing mode.</p> <p align="center"><textarea name="exp2b_3.asm" rows="7" cols="70">* * * * * * * * * * * * * * * * * * * * * * * * * * *** exp2b_3: Indirect Addressing Mode* * * * * * * * * * * * * * * * * * * * * * * * * * * * .def _exp2b_3 .text_exp2b_3 ;; Indirect addressing; mpym *AR0+,*AR1+,AC0 add AC1,AC0 mpym *AR0+,*AR1+,AC1 add AC1,AC0 mpym *AR0+,*AR1+,AC1 add AC1,AC0 mpym *AR0+,*AR1+,AC1 add AC1,AC0 mpym *AR0+,*AR1+,AC1 add AC1,AC0 mpym *AR0+,*AR1+,AC1 add AC1,AC0 mpym *AR0+,*AR1+,AC1 add AC1,AC0 mpym *AR0+,*AR1+,AC1 add AC1,AC0 mov AC0,T0 ret .end</textarea> </p> <p align="center"> </p> <p align="center">Table E2-7 Assembly routine uses the indirect addressing mode with parallel instructions.</p> <p align="center"><textarea name="exp2b_4.asm" rows="7" cols="70">* * * * * * * * * * * * * * * * * * * * * * * * * * *** exp2b_4: Paralle Processing** * * * * * * * * * * * * * * * * * * * * * * * * * * .def _exp2b_4 .text_exp2b_4 ;; Indirect addressing with paralle processing; mpym *AR0+,*AR1+,AC0|| rpt #6 macm *AR0+,*AR1+,AC0 mov AC0,T0 ret .end</textarea> </p> <blockquote> <blockquote> <p>To conduct Experiment 2B, following these steps:</p> <ol> <li>Create the project, <em>exp2b</em> and include the linker command file <em>exp2.cmd</em>, the function <font face="Courier New">exp2b()</font>, assembly routine <font face="Courier New">exp2b_1.asm</font>, <font face="Courier New">exp2b_2.asm</font>, <font face="Courier New">exp2b_3.asm</font>, and <font face="Courier New">exp2b_4.asm</font>.</li> <li>Use <font face="Courier New">rts55.lib</font> for <font face="Courier New">main()</font> function initialization and build the project.</li> <li>Watch how the arrays A and X are initialized in data memory.</li> <li>Open the CPU register window to observe how the dot-product is computed.</li> <li>Profile assembly routine <font face="Courier New">exp2b_3.asm</font> and <font face="Courier New">exp2b_4.asm</font>. and compare the memory usage of assembly routine <font face="Courier New">exp2b_3.asm</font> and <font face="Courier New">exp2b_4.asm</font></li> </ol> </blockquote> </blockquote></form><p align="left"><a href="#top"><font size="1">Back to Top</font></a><input type="button" value="go back" onclick="history.go(-1)"> </p><hr><p><a <u><font size="1"><i>copyright
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -