<< Chapter < Page Chapter >> Page >

Assembly functions

Let's examine the calls to the assembly functions init_filter and filter . The assembly file containing these functions is v:\ece320\54x\dspclib\lab3filt.asm

1 ; Lab 3 assembly module 2 3 .copy "v:\ece320\54x\dspclib\core.inc" 4 ; Useful macros for C interfacing 5 6 .global _dec_rate ; Decimation rate - in lab3main.c 7 .global _filter ; Filter code in this file 8 .global _init_filter 9 10 FIR_len .set 13 11 12 .sect ".data" 13 14 .align 16 ; Align to a multiple of 16 15 firstate 16 .space 16*13 ; Allocate 13 words of storage for 17 ; filter state. 18 .align 16 19 coef .copy "coef1.asm" 20 21 stateptr .word 0 22 23 _dec_rate .word 4 24 25 .sect ".text" 26 27 _init_filter ; need the leading _ for a C name. 28 ENTER_ASM 29 30 stm #firstate, AR3 31 mvmd AR3, stateptr ; Save AR3 32 33 LEAVE_ASM 34 ret 35 36 _filter 37 ENTER_ASM 38 ; Input in low part of A accumulator 39 40 mvdm stateptr, AR3 ; Restore state pointer 41 42 stm #FIR_len,BK ; initialize circular buffer length 43 stm #coef,AR2 ; initialize coefficient pointer 44 stm #1,AR0 ; initialize AR0 for pointer increment 45 46 stl A,*AR3+% ; store current input into state buffer 47 rptz A,(FIR_len-1) ; clear A and repeat 48 mac *AR2+0%,*AR3+0%,A ; multiply coefficient by state & accumulate 49 50 rnd A ; Round off value in 'a' to 16 bits 51 52 sfta a,-16 ; Shift output to low part of accumulator 53 54 mvmd AR3, stateptr ; Save state pointer 55 56 ; Output in low part of A accumulator 57 58 LEAVE_ASM 59 ret

The assembly file contains two main parts, the data section starting with .sect ".data" and the program section starting with .sect ".text" . Every function and variable accessed in C must be preceded by asingle underscore _ in assembly and a .global _name must be placed in the assembly file for linking. In this example, filter is an assembly function called from the C program with a label _filter in the text portion of the assembly file and a .global _filter declaration. In each assembly function, the macro ENTER_ASM is called upon entering and LEAVE_ASM is called upon exiting. These macros are defined in v:\ece320\54x\dspclib\core.inc . The ENTER_ASM macro saves the status registers and AR1 , AR6 , and AR7 when entering a function as required by the register use conventions. The ENTER_ASM macro also sets the status registers to the assembly conventions we have beenusing ( i.e , FRCT =1 for fractional arithmetic and CPL =0 for DP referenced addressing). The LEAVE_ASM macro just restores the saved registers.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Ece 320 - spring 2003. OpenStax CNX. Jan 22, 2004 Download for free at http://cnx.org/content/col10096/1.2
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Ece 320 - spring 2003' conversation and receive update notifications?

Ask