motorola digital signal processing development software motorola dsp assembler reference manual motorola, incorporated semiconductor products sector dsp division 6501 william cannon drive west austin, tx, 78735-8598 f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
specification and information herein are subject to change without notice. motorola re- serves the right to make changes without further notice to any products described in this document to improve reliability, function, or design. motorola does not assume any liability arising out of the application or use of any product or circuit described herein, neither does it convey any license under its patent rights or the rights of others. motorola is a registered trademark of motorola, inc. motorola, inc. is an equal employment/affirmative action em- ployer. this manual documents the assembler as of version 6.0 of the software. ? copyright motorola, inc. 1996. all rights reserved. asm56000, sim56000, asm96000, sim96000, asm56100, sim56100, asm56300, sim56300, asm56800 and sim56800 are trademarks of motorola. ms-dos and windows are trademarks of microsoft corporation. sun-4 and sunos are trademarks of sun microsystems, inc. macintosh and mpw are trademarks of apple computer. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
motorola dsp assembler writing assembly language programs expressions software project management macros and conditional assembly assembler characters and directives structured control statements ascii character codes directive summary assembler messages assembler listing file format motorola dsp object file format (coff) device-dependent information index host-dependent information 1 2 3 4 5 6 7 a c d e f b g i f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
motorola dsp assembler writing assembly language programs expressions software project management macros and conditional assembly assembler characters and directives structured control statements ascii character codes directive summary assembler messages assembler listing file format motorola dsp object file format (coff) device-dependent information index host-dependent information 1 2 3 4 5 6 7 a c d e f b g i f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
preface motorola dsp assembler reference manual i notation the notational conventions used in this manual are: directive all assembler mnemonics and directives are shown in bold upper case to highlight them. however, the assembler will recognize both upper and lower case for mne- monics and directives. { } contains a list of elements or directives, one of which must be selected. each choice will be separated by a vertical bar. for example, { r i l } indicates that either r or l must be selected. [ ] contains one or more optional elements. if more than one optional element is shown, the required element separators are indicated. all elements outside of the angle brackets (< >) must be specified as they appear. for example, the syntacti- cal element [,] requires the comma to be specified if the optional element is selected. preface f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
ii dsp assembler reference manual motorola preface < > the element names are printed in lower case and contained in angle brackets. some common elements used to describe directives are: a statement comment a statement label or an assembler expression a numeric constant a string of ascii characters enclosed in quotes a delimiter character an assembler option or an assembler symbol supporting publications dsp56000 family manual. motorola, inc. 1992. dsp96002 users manual. motorola, inc. 1989. dsp56100 family manual. motorola, inc. 1993. dsp56300 family manual. motorola, inc. 1995. dsp56800 family manual. motorola, inc. 1996. motorola dsp simulator reference manual. motorola, inc. 1996. motorola dsp linker/librarian reference manual. motorola, inc. 1996. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
motorola dsp assembler reference manual iii table of contents preface table of contents list of figures chapter 1 motorola dsp assembler 1.1 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1 1.2 assembly language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1 1.3 installing the assembler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1 1.4 running the assembler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1 1.5 assembler options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3 1.6 assembler processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9 1.7 definition of terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9 1.8 assembler support for digital signal processing . . . . . . 1-10 chapter 2 writing assembly language programs 2.1 input file format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1 2.2 symbol names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1 2.3 strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 2.4 source statement format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 2.4.1 label field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3 2.4.2 operation field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 2.4.3 operand field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5 2.4.4 operation 2 field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5 2.4.5 operand 2 field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5 2.4.6 data transfer fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5 2.4.7 comment field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6 2.5 assembler output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6 chapter 3 expressions 3.1 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-1 f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
table of contents iv dsp assembler reference manual motorola 3.2 absolute and relative expressions . . . . . . . . . . . . . . . . . . . . . . 3-1 3.3 expression memory space attribute . . . . . . . . . . . . . . . . . . . . . 3-1 3.4 internal expression representation . . . . . . . . . . . . . . . . . . . . . 3-3 3.5 constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3 3.5.1 numeric constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3 3.5.2 string constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4 3.6 operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4 3.6.1 unary operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4 3.6.2 arithmetic operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5 3.6.3 shift operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5 3.6.4 relational operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6 3.6.5 bitwise operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6 3.6.6 logical operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7 3.7 operator precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7 3.8 functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7 3.8.1 mathematical functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8 3.8.2 conversion functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9 3.8.3 string functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9 3.8.4 macro functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9 3.8.5 assembler mode functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10 chapter 4 software project management 4.1 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1 4.2 sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1 4.3 sections and data hiding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 4.3.1 sections and symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 4.3.2 sections and macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4 4.3.3 nested and fragmented sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4 4.4 sections and relocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5 4.5 address assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-6 4.5.1 the org directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-7 4.5.2 overlays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-9 4.5.3 address assignment examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10 4.5.4 circular buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-11 4.6 example 1: multi-programmer environment . . . . . . . . . . . . . . 4-13 4.6.1 absolute mode implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14 f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
table of contents motorola dsp assembler reference manual v 4.6.2 relative mode implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-15 4.7 example 2: overlays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-16 4.7.1 absolute mode implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-17 4.7.2 relative mode implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-18 4.8 example 3: bootstrap overlay . . . . . . . . . . . . . . . . . . . . . . . . . . 4-20 4.8.1 absolute mode implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21 4.8.2 relative mode implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21 chapter 5 macro operations and conditional assembly 5.1 macro operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1 5.2 macro libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 5.3 macro definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 5.4 macro calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4 5.5 dummy argument operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5 5.5.1 dummy argument concatenation operator - \ . . . . . . . . . . . . . . . . . . . . . 5-5 5.5.2 return value operator - ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6 5.5.3 return hex value operator - % . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-7 5.5.4 dummy argument string operator - ". . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-7 5.5.5 macro local label override operator - ^ . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8 5.6 dup, dupa, dupc, dupf directives . . . . . . . . . . . . . . . . . . . . . . . . . 5-9 5.7 conditional assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9 chapter 6 assembler significant characters and directives 6.1 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-1 6.2 assembler significant characters . . . . . . . . . . . . . . . . . . . . . . . 6-1 6.3 assembler directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2 6.3.1 assembly control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2 6.3.2 symbol definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3 6.3.3 data definition/storage allocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3 6.3.4 listing control and options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3 6.3.5 object file control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4 6.3.6 macros and conditional assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4 6.3.7 structured programming. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4 f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
table of contents vi dsp assembler reference manual motorola chapter 7 structured control statements 7.1 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-1 7.2 structured control directives . . . . . . . . . . . . . . . . . . . . . . . . . . 7-1 7.3 syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2 7.3.1 .break statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2 7.3.2 .continue statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3 7.3.3 .for statement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4 7.3.4 .if statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-5 7.3.5 .loop statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-6 7.3.6 .repeat statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-7 7.3.7 .while statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-7 7.4 simple and compound expressions . . . . . . . . . . . . . . . . . . . . . . . 7-8 7.4.1 simple expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-8 7.4.1.1 condition code expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-8 7.4.1.2 operand comparison expressions . . . . . . . . . . . . . . . . . . . . . . . . . . 7-9 7.4.2 compound expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-10 7.5 statement formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-10 7.5.1 expression formatting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-10 7.5.2 .for/.loop formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-11 7.5.3 assembly listing format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-11 7.6 effects on the programmers environment . . . . . . . . . . . . . 7-11 appendix a ascii character codes appendix b directive summary b.1 assembly control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b-1 b.2 symbol definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b-2 b.3 data definition/storage allocation. . . . . . . . . . . . . . . . . . . . . . b-2 b.4 listing control and options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b-2 b.5 object file control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b-3 b.6 macros and conditional assembly . . . . . . . . . . . . . . . . . . . . . . . b-3 b.7 structured programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b-3 f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
table of contents motorola dsp assembler reference manual vii appendix c assembler messages c.1 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-1 c.2 command line errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-2 c.3 warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-4 c.4 errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-13 c.5 fatal errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-44 appendix d assembler listing file format d.1 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . d-1 d.2 listing file commentary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . d-1 d.3 cross-reference format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . d-3 d.4 memory utilization report format . . . . . . . . . . . . . . . . . . . . . . d-3 d.5 assembler listing format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . d-5 appendix e motorola dsp object file format (coff) e.1 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-1 e.2 object file structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-1 e.3 object file components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-3 e.3.1 file header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-3 e.3.2 optional header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-4 e.3.3 sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-6 e.3.3.1 section headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-7 e.3.3.2 relocation information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-9 e.3.3.3 line numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-10 e.3.4 symbol table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-11 e.3.4.1 symbol name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-13 e.3.4.2 symbol value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-13 e.3.4.3 section number. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-14 e.3.4.4 symbol type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-14 e.3.4.5 symbol storage class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-16 e.3.4.6 auxiliary entries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-20 e.3.4.6.1 filenames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-21 e.3.4.6.2 sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-21 e.3.4.6.3 tag names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-23 f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
table of contents viii dsp assembler reference manual motorola e.3.4.6.4 end of structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-23 e.3.4.6.5 functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-24 e.3.4.6.6 arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-25 e.3.4.6.7 end of blocks and functions . . . . . . . . . . . . . . . . . . . . . . . . . . e-25 e.3.4.6.8 beginning of blocks and functions . . . . . . . . . . . . . . . . . . . . . e-26 e.3.4.6.9 structure, union, and enumeration names . . . . . . . . . . . . . . . e-26 e.3.4.7 object file comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-27 e.3.5 string table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-27 e.4 differences in dsp object format and standard coff . . e-27 e.4.1 multiple memory spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-28 e.4.2 object file transportability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-29 e.4.3 structure size fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-30 e.4.4 relocation information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-30 e.4.5 block data sections. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-31 e.4.6 other extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-31 e.5 object file data expression format . . . . . . . . . . . . . . . . . . . . e-31 e.5.1 data expression generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-32 e.5.2 data expression interpretation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-32 e.5.2.1 user expression - { ... } . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-33 e.5.2.2 relocatable expression - [ ... ] . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-33 e.5.2.3 memory space operator - @ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-33 e.5.2.4 bit size operator - #. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-33 e.5.2.5 memory attribute operator - :. . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-34 e.5.2.6 line number operator - ! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-34 e.5.2.7 bfxxx instruction mask function - @fbf() . . . . . . . . . . . . . . . . . . e-35 e.5.2.8 local relocatable reference function - @lrf() . . . . . . . . . . . . . e-35 e.5.2.9 alternate encoding function - @enc() . . . . . . . . . . . . . . . . . . . . . e-35 appendix f device-dependent information f.1 introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-1 f.2 dsp56000 information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-2 f.2.1 instruction set summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-2 f.2.1.1 arithmetic instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .f-3 f.2.1.2 logical instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .f-4 f.2.1.3 bit manipulation instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . .f-4 f.2.1.4 loop instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .f-4 f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
table of contents motorola dsp assembler reference manual ix f.2.1.5 move instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-4 f.2.1.6 program control instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . f-5 f.2.2 register names and usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-6 f.2.3 condition code mnemonics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-7 f.3 dsp96000 information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-8 f.3.1 instruction set summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-8 f.3.1.1 arithmetic instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-8 f.3.1.2 logical instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-10 f.3.1.3 bit manipulation instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . f-10 f.3.1.4 loop instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-10 f.3.1.5 move instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-11 f.3.1.6 program control instructions . . . . . . . . . . . . . . . . . . . . . . . . . . f-12 f.3.2 register names and usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-13 f.3.3 condition code mnemonics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-14 f.4 dsp56100 information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-15 f.4.1 instruction set summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-15 f.4.1.1 arithmetic instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-15 f.4.1.2 logical instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-16 f.4.1.3 bit manipulation instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . f-17 f.4.1.4 loop instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-17 f.4.1.5 move instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-17 f.4.1.6 program control instructions . . . . . . . . . . . . . . . . . . . . . . . . . . f-18 f.4.2 register names and usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-18 f.4.3 condition code mnemonics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-19 f.5 dsp56300 information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-20 f.5.1 instruction set summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-20 f.5.1.1 arithmetic instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-21 f.5.1.2 logical instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-22 f.5.1.3 bit manipulation instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . f-22 f.5.1.4 loop instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-23 f.5.1.5 move instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-23 f.5.1.6 program control instructions . . . . . . . . . . . . . . . . . . . . . . . . . . f-24 f.5.2 register names and usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-25 f.5.3 condition code mnemonics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-26 f.6 dsp56800 information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-27 f.6.1 instruction set summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-27 f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
table of contents x dsp assembler reference manual motorola f.6.1.1 arithmetic instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .f-28 f.6.1.2 logical instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .f-29 f.6.1.3 bit manipulation instructions . . . . . . . . . . . . . . . . . . . . . . . . . . .f-29 f.6.1.4 loop instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .f-29 f.6.1.5 move instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .f-30 f.6.1.6 program control instructions . . . . . . . . . . . . . . . . . . . . . . . . . . .f-30 f.6.2 macro instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-31 f.6.3 register names and usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-32 f.6.4 condition code mnemonics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f-32 appendix g host-dependent information g.1 introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-1 g.2 dos/386 environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-1 g.2.1 hardware requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-1 g.2.2 installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-2 g.2.3 source file text. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-2 g.2.4 invoking the assembler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-2 g.3 sunos environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-3 g.3.1 hardware requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-3 g.3.2 installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-3 g.3.3 source file text. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-4 g.3.4 invoking the assembler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-4 g.4 hp 700 environment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-4 g.4.1 hardware requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-4 g.4.2 installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-5 g.4.3 source file text. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-5 g.4.4 invoking the assembler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-5 g.5 macintosh environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-6 g.5.1 hardware requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-6 g.5.2 installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-6 g.5.3 source file text. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-6 g.5.4 invoking the assembler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . g-7 index f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
list of figures motorola dsp assembler reference manual xi list of figures d-1 assembler listing format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . d-5 d-2 assembler cross-reference listing format . . . . . . . . . . . . . . . . . . . . . . . d-14 d-3 assembler listing line format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . d-15 d-4 memory utilization report format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . d-16 d-5 memory utilization report source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . d-18 e-1 coff file basic structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-2 e-2 file header format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-3 e-3 file header flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-4 e-4 motorola dsp optional link header format . . . . . . . . . . . . . . . . . . . . . . . e-5 e-5 motorola dsp optional runtime header format . . . . . . . . . . . . . . . . . . . . e-6 e-6 section header format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-7 e-7 section header flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-9 e-8 relocation entry format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-10 e-9 line number entry format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-10 e-10 line number grouping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-11 e-11 coff symbol table ordering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-12 e-12 symbol table entry format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-13 e-13 fundamental types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-15 e-14 derived types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-16 e-15 storage classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-17 e-16 storage class and value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-19 e-17 filename symbol auxiliary entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-21 e-18 section symbol auxiliary entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-21 e-19 relocatable section auxiliary entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-22 e-20 relocatable buffer/overlay auxiliary entry . . . . . . . . . . . . . . . . . . . . . . . e-22 e-21 tag name symbol auxiliary entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-23 e-22 end of structure auxiliary entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-24 f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
list of figures xii dsp assembler reference manual motorola e-23 function symbol auxiliary entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-24 e-24 array symbol auxiliary entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-25 e-25 end of block or function auxiliary entry . . . . . . . . . . . . . . . . . . . . . . . . . e-25 e-26 beginning of block or function auxiliary entry . . . . . . . . . . . . . . . . . . . . e-26 e-27 structure, union, or enumeration name auxiliary entry . . . . . . . . . . . . . e-27 e-28 core_addr format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-28 e-29 memory mapping enumerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-29 e-30 motorola dsp coff byte ordering . . . . . . . . . . . . . . . . . . . . . . . . . . . . e-30 f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
motorola dsp assembler reference manual 1-1 chapter 1 motorola dsp assembler 1.1 introduction the motorola dsp assemblers are programs that process assembly language source statements written for motorolas family of digital signal processors. the assembler trans- lates these source statements into object programs compatible with other motorola dsp software and hardware products. 1.2 assembly language the assembly language provides mnemonic operation codes for all machine instructions in the digital signal processor instruction set. in addition, the assembly language contains mnemonic directives which specify auxiliary actions to be performed by the assembler. these directives are not always translated into machine language. the assembly lan- guage enables the programmer to define and use macro instructions which replace a sin- gle statement with a predefined sequence of statements found in the macro definition. conditional assembly also is supported. 1.3 installing the assembler the assembler is distributed on various media and in different formats depending on the host environment. see appendix g, host-dependent information, for details on installing and operating the assembler on your particular machine. 1.4 running the assembler the general format of the command line to invoke the assembler is: dspasm [options] where: dspasm the name of the motorola dsp assembler program appropriate for the tar- get processor (see appendix f, device-dependent information). for exam- f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
motorola dsp assembler running the assembler 1-2 dsp assembler reference manual motorola ple, for the motorola dsp56000 processor the name of the assembler executable is asm56000 . [options] any of the following command line options. these can be in any order, but must precede the list of source filenames. some options can be given more than once; the individual descriptions indicate which options may be speci- fied multiple times. option letters can be in either upper or lower case. command options that are used regularly may be placed in the environment variable dspasmopt . if the variable is found in the environment the as- sembler adds the associated text to the existing command line prior to pro- cessing any options. see your host documentation for instructions on how to define environment variables. option arguments may immediately follow the option letter or may be sepa- rated from the option letter by blanks or tabs. however, an ambiguity arises if an option takes an optional argument. consider the following command line: asm56000 -b main io in this example it is not clear whether the file main is a source file or is meant to be an argument to the -b option. if the ambiguity is not resolved the assembler will assume that main is a source file and attempt to open it for reading. this may not be what the programmer intended. there are several ways to avoid this ambiguity. if main is supposed to be an argument to the -b option it can be placed immediately after the option letter: asm56000 -b main io if there are other options on the command line besides those that take op- tional arguments the other options can be placed between the ambiguous option and the list of source file names: asm56000 -b main -v io an alternative is to use two successive hyphens to indicate the end of the option list: asm56000 -b -- main io in this latter case the assembler interprets main as a source file name and uses the default naming conventions for the -b option. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
motorola dsp assembler assembler options motorola dsp assembler reference manual 1-3 1.5 assembler options -a indicates that the assembler should run in absolute mode, generating an absolute object file when the -b command line option is given. by default the assembler produces a relocatable object file that is subsequently pro- cessed by the motorola dsp linker. see chapter 4, software project man- agement, for more information on assembler modes. -b [] this option specifies that an object file is to be created for assembler output. can be any legal operating system filename, including an optional pathname. a hyphen also may be used as an argument to indicate that the object file should be sent to the standard output. the type of object file produced depends on the assembler operation mode. if the -a option is supplied on the command line, the assembler operates in absolute mode and generates an absolute object (.cld) file. if there is no -a option on the command line, the assembler operates in relative mode and creates a relocatable object (.cln) file. if a pathname is not specified, the file will be created in the current directory. if no filename is specified, the assembler will use the basename (filename without extension) of the first filename encountered in the source input file list and append the appropriate file type (.cln or .cld) to the basename. if the -b option is not specified, then the assembler will not generate an object file. the -b option should be specified only once. if the file named in the -b option already exists, it will be overwritten. example: asm56000 -b filter main.asm fft.asm fio.asm in this example, the files main.asm, fft.asm, and fio.asm are assembled together to produce the relocatable object file filter.cln. -d this is equivalent to a source statement of the form: define must be preceded by a blank and should be enclosed in single quotes if it contains any embedded blanks. note that if single quotes are used they must be passed to the assembler intact, e.g. some host com- mand interpreters will strip single quotes from around arguments. the f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
motorola dsp assembler assembler options 1-4 dsp assembler reference manual motorola -d sequence can be repeated as often as desired. see the define directive (chapter 6) for more information. example: asm96000 -d points 16 prog.asm all occurrences of the symbol points in the program prog.asm will be replaced by the string 16. -ea -ew these options allow the standard error output file to be reassigned on hosts that do not support error output redirection from the command line. must be present as an argument, but can be any legal operating system file- name, including an optional pathname. the -ea option causes the standard error stream to be written to ; if exists, the output stream is appended to the end of the file. the -ew option also writes the standard error stream to ; if exists it is rewound (truncated to zero), and the output stream is written from the be- ginning of the file. note that there must be white space separating either option from the filename argument. example: asm96000 -ew errors prog.asm redirect the standard error output to the file errors. if the file al- ready exists, it will be overwritten. -f indicates that the assembler should read command line input from . can be any legal operating system filename, including an optional pathname. is a text file containing further options, arguments, and filenames to be passed to the assembler. the arguments in the file need be separated only by some form of white space (blank, tab, newline). a semi- colon ( ; ) on a line following white space makes the rest of the line a com- ment. the -f option was introduced to circumvent the problem of limited line lengths in some host system command interpreters. it may be used as often as desired, including within the argument file itself. command options may also be supplied using the dspasmopt environment variable. see the dis- cussion of dspasmopt under [options] at the beginning of this section. example: asm96000 -f opts.cmd invoke the assembler and take command line options and source filenames from the command file opts.cmd. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
motorola dsp assembler assembler options motorola dsp assembler reference manual 1-5 -g send source file line number information to the object file. this option is val- id only in conjunction with the -b command line option. the generated line number information can be used by debuggers to provide source-level de- bugging. example: asm56000 -b -g myprog.asm assemble the file myprog.asm and send source file line number information to the resulting object file myprog.cln. -i when the assembler encounters include files, the current directory (or the directory specified in the include directive) is first searched for the file. if it is not found and the -i option is specified, the assembler prefixes the file- name (and optional pathname) specified in the include directive with and searches the newly formed directory pathname for the file. the pathname must be a legal operating system pathname. the -i option may be repeated as many times as desired. the directories will be searched in the order specified on the command line. example: asm56000 -i \project\ testprog this example uses ibm pc pathname conventions, and would cause the assembler to prefix any include files not found in the current directory with the \project\ pathname. -l this option specifies that a listing file is to be created for assembler output. can be any legal operating system filename, including an optional pathname. a hyphen also may be used as an argument to indicate that the listing file should be sent to the standard output, although the listing file is routed to standard output by default. if a pathname is not specified, the file will be created in the current directory. if no filename is specified, the assembler will use the basename (filename without extension) of the first filename encountered in the source input file list and append .lst to the basename. if the -l option is not specified, then the assembler will route listing output to the standard output (usually the console or terminal screen) by default. the -l option should be specified f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
motorola dsp assembler assembler options 1-6 dsp assembler reference manual motorola only once. if the file named in the -l option already exists, it will be overwritten. example: asm96000 -l filter.asm gauss.asm in this example, the files filter.asm and gauss.asm are assem- bled together to produce a listing file. because no filename was giv- en with the -l option, the output file will be named using the basename of the first source file, in this case filter. the listing file will be called filter.lst. -m this is equivalent to a source statement of the form: maclib the pathname must be a legal operating system pathname. the -m option may be repeated as many times as desired. the directories will be searched in the order specified on the command line. see the maclib directive (chapter 6) for more information. example: asm56000 -m fftlib/ trans.asm this example uses unix pathname conventions, and would cause the assembler to look in the fftlib subdirectory of the current directory for a file with the name of the currently invoked macro found in the source file. -o [,,...,] this is equivalent to a source statement of the form: opt [,,...,] can be any of the options that are available with the opt directive (see chapter 6). if multiple options are specified, they must be separated by commas. the -o sequence can be repeated for as many options as desired. example: asm96000 -os,cre myprog.asm this will activate the symbol table and cross reference listing options. -p run the assembler with the specified processor revision level enhance- ments. this is for backward compatibility so that the assembler will flag new constructions as illegal. can be any of the processor identifiers given f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
motorola dsp assembler assembler options motorola dsp assembler reference manual 1-7 below. note that if this option is not used the assembler runs with all latest revision level enhancements on by default. processor identifier dsp56001 rev. c 56001c dsp56002 56002 dsp56004 56004 dsp56166 56166 dsp96001 rev. b 96001b dsp96002 96002 example: asm56000 -p 56001c myprog.asm assemble myprog.asm with the dsp56000 revision c enhance- ments. -q on some hosts the assembler displays a banner on the console when in- voked. this option inhibits the banner display. it has no effect on hosts where the signon banner is not displayed by default. example: asm56000 -q myprog.asm assemble the file myprog.asm but do not display the signon ban- ner on the console. -r run the assembler without the specified processor revision level enhance- ments. this is for backward compatibility so that the assembler will flag new constructions as illegal. can be any of the revision specifiers given be- low, but must be appropriate for the target processor. this option is superseded by the -p option. processor revision dsp56001 rev. c c dsp56002 2 dsp56004 4 dsp56166 6 dsp96000 rev. b b dsp96001 1 example: asm56000 -rc myprog.asm assemble myprog.asm without the dsp56000 revision c en- hancements. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
motorola dsp assembler assembler options 1-8 dsp assembler reference manual motorola -v this option causes the assembler to report assembly progress (beginning of passes, opening and closing of input files) to the standard error output stream. this is useful to insure that assembly is proceeding normally. example: asm56000 -v myprog.asm assemble the file myprog.asm and send progress lines to the standard error output. -z this option causes the assembler to strip symbol information from the ab- solute load file. normally symbol information is retained in the object file for symbolic reference purposes. note that this option is valid only when the assembler is in absolute mode via the -a command line option and when an object file is created ( -b option). example: asm56000 -a -b -z myprog.asm assemble the file myprog.asm in absolute mode and strip symbol information from the load file created as output. a list of operating system compatible filenames (including optional path- names). if no extension is supplied for a given file, the assembler first will attempt to open the file using the filename as supplied. if that is not success- ful the assembler appends .asm to the filename and attempts to open the file again. if no pathname is specified for a given file, the assembler will look for that file in the current directory. the list of files will be processed sequen- tially in the order given and all files will be used to generate the object file and listing. the assembler will redirect the output listing to the standard output if the output listing is not suppressed with the il option, or if it is not redirected via the -l command line option described above. the standard output generally goes to the console or terminal screen by default, but can be diverted to a file or to a printer by using the i/o redirection facilities of the host operating system, if available. error messages will always appear on the stan- dard output, regardless of any option settings. note that some options ( -b , -l ) allow a hyphen as an optional argument which indicates that the corresponding output should be sent to the standard output stream. unpredictable results may occur if, for example, the object file is explicitly routed to standard output while the listing file is allowed to default to the same output stream. for more details on assembler operation in a particular machine environment see appen- dix g, host-dependent information. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
motorola dsp assembler assembler processing motorola dsp assembler reference manual 1-9 1.6 assembler processing the motorola dsp assembler is a two-pass assembler. during the first pass the source program is read to build the symbol and macro tables. during the second pass the object file is generated (assembled) with reference to the tables created during pass one. it is also during the second pass that the source program listing is produced. each source statement is processed completely before the next source statement is read. as each line is read in, any translations specified by the define directive are applied. each statement is then processed, and the assembler examines the label, operation code, operand, and data transfer fields. the macro definition table is scanned for a match with the operation code. if there is no match, the operation code and directive tables are scanned for a match with a known opcode. any errors detected by the assembler are displayed before the actual line containing the error is printed. errors and warnings are accumulated, and a total number of errors and warnings is printed at the end of the source listing. if no source listing is produced, error messages are still displayed to indicate that the assembly process did not proceed nor- mally. the number of errors is returned as an exit status when the assembler returns con- trol to the host operating system. 1.7 definition of terms since the motorola dsp architectures are different from normal microprocessors, the pro- grammer may not be familiar with some of the terms used in this document. the following discussion serves to clarify some of the concepts discussed later in this manual. the motorola dsp architecture can have as many as five separate memory spaces re- ferred to as the x , y , l , p ( p rogram), and e (emi - extended memory interface) memory spaces. l memory space is a concatenation of x and y data memory and is considered by the assembler as a superset of the x and y memory spaces. e memory is specific to the dsp56004 processor, and provides for different data representations for various memory hardware configurations. the assembler will generate object code for each memory space, but object code can only be generated for one memory space at a time. the memory space and address location into which the object code generated by the as- sembler will be loaded are referred to as the load memory space and load address , re- spectively. because the dsp architecture allows data transfers between memory spaces, sometimes object code is loaded into an address of one memory space but will later be transferred to a different memory space and address before the program is run. one ex- ample of this might be a program located in an external eprom that will be transferred into external program ram before it is run. the transfer of code/data from one memory space/address to a different memory space/address is called an overlay . when the object code for a part of the program is generated that later will be used as an overlay, the load memory space and load address do not correspond to the memory space and address where the program will be run. the memory space and address loca- tion where the code/data will be located when the program is run are referred to as the f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
motorola dsp assembler assembler support for digital signal processing 1-10 dsp assembler reference manual motorola runtime memory space and runtime address , respectively. if the assembler only used the load address to assign values to labels, then the program would not contain the cor- rect label references when it was transferred to the runtime memory space and the run- time address. during the assembly process, the assembler uses location counters to record the ad- dresses associated with the object code. in order to facilitate the generation of object code for overlays, the assembler maintains two different location counters, the load location counter , which determines the address into which the object code will be loaded and the runtime location counter , which determines the address assigned to labels. in addition, the assembler keeps track of the load memory space , which is the memory space into which the object code will be loaded, and the runtime memory space , which is the mem- ory space to which an overlay will be transferred and the memory space attribute that will be assigned to labels. see chapter 4, software project management, for a practical dis- cussion of the use of memory spaces and location counters. the motorola digital signal processors are capable of performing operations on modulo and reverse-carry buffers , two data structures useful in digital signal processing applica- tions. the dsp assembler provides directives for establishing buffer base addresses, al- locating buffer space, and initializing buffer contents. for a buffer to be located properly in memory the lower bits of the starting address which encompass one less than the buffer size must be zero. for example, the lowest address greater than zero at which a buffer of size 32 may be located is 32 (20 hexadecimal). more generally, the buffer base address must be a multiple of 2 k , where 2 k is greater than or equal to the size of the buffer. buffers can be allocated manually or by using the assembler buffer directives (see chapter 6). the assembler operates in either absolute or relative mode, depending on the presence of the command line -a option. in relative mode the assembler creates relocatable object files. these files can be combined and relocated using the motorola dsp linker. in ab- solute mode the assembler generates absolute object files. absolute files cannot be re- located but can be loaded directly for execution. by default the assembler runs in relative mode. 1.8 assembler support for digital signal processing as mentioned previously, the assembler offers facilities commonly found in other macro assemblers, such as nested macro capabilities, include files, and conditional assembly. the assembler must also provide extensions in support of the unconventional architec- ture of the motorola digital signal processors, as well as aids for programming dsp-spe- cific applications. some of these features are discussed briefly below; see the appropriate chapters later in this manual for more information. the assembler supports the use of arbitrary algebraic expressions as arguments to vari- ous directives and as immediate operands in certain instructions. terms of these expres- sions may consist of the assemblers own built-in functions, which perform data conversion, comparison, and computational operations. in the digital signal processing domain transcendental functions for computing sine, cosine, and natural logarithm are f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
motorola dsp assembler assembler support for digital signal processing motorola dsp assembler reference manual 1-11 useful for initializing data values in memory, such as sine/cosine tables for fft algo- rithms. also, there are functions for easily converting values expressed in decimal floating point to their binary or fractional equivalents. this conversion is done automatically for im- mediate instruction operands and arguments to the dc directive (see chapter 6). see chapter 3 for more information on assembler expressions, operators, and built-in func- tions. the register set of the motorola digital signal processors allows for efficient use of modulo and reverse-carry buffers for fft applications. the assembler supports this architecture by providing several special-purpose directives for allocating circular buffers. the baddr , buffer , dsm , and dsr directives automatically advance the program counter to the next appropriate base address given the buffer size, and perform various boundary and magnitude checks to insure that the buffer is valid. the bsm and bsr provide for automatic alignment and block initialization of dsp buffers. since a buffer allocated in this fashion can cause alignment gaps in memory, the mu option (see the opt directive, chapter 6) may be used to generate a full memory utilization report. see chapter 6 for more information on assembler directives and options. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
motorola dsp assembler reference manual 2-1 chapter 2 writing assembly language programs 2.1 input file format programs written in assembly language consist of a sequence of source statements. any source statement can be extended to one or more lines by including the line continuation character ( \ ) as the last character on the line to be continued. a source statement (first line and any continuation lines) can be a maximum of 512 characters long. upper and lower case letters are considered equivalent for assembler mnemonics and directives, but are considered distinct for labels, symbols, directive arguments, and literal strings. if the source file contains horizontal tabs (ascii $09), the assembler will expand these to the next fixed tab stop located at eight character intervals (column 1, 9, 17...), unless reset using the tab directive (see chapter 6). this is only significant if tab characters are em- bedded within literal strings. for more information on source input file format, see appendix g, host-dependent infor- mation. 2.2 symbol names symbol names can be from one to 512 characters long. the first character of a symbol must be alphabetic (upper or lower case); any remaining characters can be either alpha- numeric (a-z, a-z, 0-9) or the underscore character ( _ ). upper and lower case letters in symbols are considered distinct unless the ic option is in effect (see the opt directive, chapter 6). valid: loop_1 invalid: 1_loop entry loop.e a_b_c certain identifiers are reserved by the assembler and cannot be used. these identifiers are the upper or lower case name of any motorola dsp processor register. see appendix f for a list of the register names of the appropriate target processor. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
writing assembly language programs strings 2-2 dsp assembler reference manual motorola 2.3 strings one or more ascii characters enclosed by single quotes ( ' ) constitute a literal ascii string. in order to specify an apostrophe within a literal string, two consecutive apostro- phes must appear where the single apostrophe is intended. strings are used as operands for some assembler directives and also can be used to a limited extent in expressions. a string may also be enclosed in double quotes ( " ) in which case any define directive symbols contained in the string would be expanded. the double quote should be used with care inside macros since it is used as a dummy argument string operator (see chap- ter 5). in that case the macro concatenation operator can be used to escape the double- quoted string if desired. two strings separated by the string concatenation operator ( ++ ) will be recognized by the assembler as equivalent to the concatenation of the two strings. for example, these two strings are equivalent: 'abc'++'def' = 'abcdef' the assembler has a substring extraction capability using the square brackets ( [ ] ). here is an example: ['dsp56000',3,5] = '56000' substrings may be used wherever strings are valid and can be nested. there are also functions for determining the length of a string and the position of one string within anoth- er. see chapter 3 for more information on string functions. 2.4 source statement format each source statement may include up to six fields (eight for the dsp96000) separated by one or more spaces or tabs: a label field, an operation field, an operand field, an addi- tional opcode and operand field for the dsp96000, up to two data transfer fields, and a comment field. only fields preceding the comment field are considered significant to the f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
writing assembly language programs source statement format motorola dsp assembler reference manual 2-3 assembler; the comment field is ignored. for example, the following source statement shows all eight possible fields for the dsp96000: ent fmpy d8,d6,d2 fadd.s d3,d0 x:(r0),d4.s d2.s,y:(r5)+ ;text in general, the contents of each field other than the comment field cannot contain embed- ded whitespace characters, since these characters are used as field delimiters. two ex- ceptions are blanks and tabs in quoted strings and the syntax of structured control statements (see chapter 7). 2.4.1 label field the label field occurs as the first field of a source statement, and can take one of the fol- lowing forms: 1. a space or tab as the first character on a line ordinarily indicates that the label field is empty, and that the line has no label. 2. an alphabetic character as the first character indicates that the line contains a symbol called a label . 3. an underscore ( _ ) as the first character indicates that the label is a local label . labels may be indented if the label symbol is immediately followed by a colon ( : ). if the first non-blank field on a line complies with either forms 2 or 3 above and the field ends with a colon, the assembler regards this as the label field, even if it does not start with the first character on the line. however, all characters preceding the label on the source line must be whitespace characters (spaces or tab characters). there should be no interven- ing blanks or tabs between the end of the label symbol and the appended colon character. local labels are any normal symbol name preceded (with no intervening blanks) by an underscore ( _ ). except for the special case of macros (described below), local labels have a limited scope bounded by any two non-local labels. the local label can be referred to or defined only in source statements that are between two source lines containing non- local labels. local labels are useful in defining program locations where a unique label name is required but is not considered useful in documenting the source file (for example, label opcode operand opcode 2 operand 2 x field y field comment f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
writing assembly language programs source statement format 2-4 dsp assembler reference manual motorola the terminating address of a do loop). note that the maximum length of a local label in- cludes the leading underscore ( _ ) character. use of local labels in macros represents a special case. all local labels within a macro are considered distinct for the currently active level of macro expansion (unless the macro lo- cal label override operator is used; see chapter 5). these local labels are valid for the en- tire macro expansion and are not considered bounded by non-local labels. therefore, all local labels within a macro must be unique. this mechanism allows the programmer to freely use local labels within a macro definition without regard to the number of times that the macro is expanded. non-local labels within a macro expansion are considered to be normal labels and therefore cannot occur more than once unless used with the set di- rective (see chapter 6). a label may occur only once in the label field of an individual source file unless it is used as a local label, a label local to a section, or is used with the set directive. if a non-local label does occur more than once in a label field, each reference to that label after the first will be flagged as an error. a line consisting of a label only is a valid line and has the effect of assigning the value of the location counter to the label. with the exception of some directives, a label is assigned the value of the location counter of the first word of the instruction or data being assem- bled. 2.4.2 operation field the operation field appears after the label field, and must be preceded by at least one space or tab. entries in the operation field may be one of three types: opcode - mnemonics that correspond directly to dsp machine instructions. directive - special operation codes known to the assembler which control the assembly process. macro call - invocation of a previously defined macro which is to be inserted in place of the macro call. the assembler first searches for operation codes in an internal macro definition table. if no match is found, the table of machine operation codes and assembler directives is searched. if neither of the tables holds the specified operation code, an error message is generated (this sequence can be altered with the maclib directive). macro names can therefore replace standard machine operation codes and assembler directives, although a warning will be issued if such a replacement occurs. the warning can be avoided by use of the rdirect directive. see chapter 6 for more information on the maclib and rdi- rect directives. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
writing assembly language programs source statement format motorola dsp assembler reference manual 2-5 2.4.3 operand field the interpretation of the operand field is dependent on the contents of the operation field. the operand field, if present, must follow the operation field, and must be preceded by at least one space or tab. the operand field may contain a symbol, an expression, or a com- bination of symbols and expressions separated by commas. there should be no inter- vening whitespace characters separating operand elements. the operand field of machine instructions is used to specify the addressing mode of the instruction, as well as the operand of the instruction. the format of the operand field for a particular instruction is given in appendix a of the user manual for the dsp in question (.e.g. dsp56000/dsp56001 users manual ). the operand fields of assembler directives are described in chapter 6. the operand fields of macros (chapter 5) depend on the def- inition of the macro. 2.4.4 operation 2 field dsp96000 only. the second operation field occurs after the first operand field, and only in conjunction with an fmpy instruction. the field must be preceded by at least one space or tab. the second operation field may consist only of the instructions fadd , fsub , and faddsub . 2.4.5 operand 2 field dsp96000 only. the interpretation of the second operand field is dependent on the con- tents of the second operation field. the second operand field, if present, must follow the second operation field, and must be preceded by at least one space or tab. the operand field may contain only those register combinations appropriate to the second operation field. the operand field of machine instructions is used to specify the addressing mode of the instruction, as well as the operand of the instruction. the format of the operand field for each dsp96000 instruction is described in appendix a of the dsp96002 users manual . 2.4.6 data transfer fields most opcodes can specify one or more data transfers to occur during the execution of the instruction. these data transfers are indicated by two addressing mode operands sepa- rated by a comma, with no embedded blanks. if two data transfers are specified, they must be separated by one or more blanks or tabs. see the appropriate dsp users man- ual for a complete discussion of addressing modes that are applicable to data transfer specifications. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
writing assembly language programs assembler output 2-6 dsp assembler reference manual motorola 2.4.7 comment field comments are not considered significant to the assembler, but can be included in the source file for documentation purposes. a comment field is composed of any characters (not part of a literal string) that are preceded by a semicolon ( ; ). a comment starting in the first column of the source file will be aligned with the label field in the listing file. otherwise, the comment will be shifted right and aligned with the comment field in the listing file, un- less the nopp option is used (see the opt directive, chapter 6). comments preceded by two consecutive semicolons ( ;; ) will not be reproduced on the assembler listing and will not be saved as part of a macro definition. 2.5 assembler output the assembler output consists of an optional listing of the source program and an optional object file. appendix d contains the description of the source listing format and appendix e contains the description of the object file format. the assembly source program listing contains the original source statements, formatted for easier reading, as well as additional information which is generated by the assembler. most lines in the listing correspond directly to a source statement. lines which do not cor- respond directly to source statements include page headings, error messages, and ex- pansions of macro calls or directives such as dc ( d efine c onstant; see chapter 6). the assembly listing optionally may contain a symbol table or a cross-reference table of all non-local symbols appearing in the program. these are always printed after the end of source input or the end directive (whichever occurs first) if either the symbol table or cross-reference table options are in effect (see the opt directive, chapter 6). the symbol table contains the name of each symbol, along with its defined value. the cross-reference table additionally contains the assembler-maintained source line number of every refer- ence to every non-local symbol (local symbols may be included in the cross-reference list- ing by using the loc option; see the opt directive, chapter 6). the format of the cross- reference table is shown in appendix d. if the mu option is enabled (see the opt directive, chapter 6), the assembler generates a report of load and runtime memory utilization. the report shows beginning and ending addresses of allocated memory areas, along with their lengths and associated symbol names, if applicable. a separate report is generated for each memory space where data has been reserved for use by the program. the format of the report is given in appendix d. the assembler object file is a binary coff (common object file format) file, with exten- sions and adaptations to support symbolic debugging and to make dsp object files trans- portable among host platforms. coff is a formal definition for the structure of machine code files. it is derived from at&t unix system v and represents a quasi-de facto stan- dard for object file formats. refer to appendix e for more information on motorola dsp coff structure and layout. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
motorola dsp assembler reference manual 3-1 chapter 3 expressions 3.1 introduction an expression represents a value which is used as an operand in an assembler instruc- tion or directive. an expression is a combination of symbols, constants, operators, and parentheses. expressions may contain user-defined labels and their associated integer or floating point values, and/or any combination of integers, floating point numbers, or ascii literal strings. in general, white space (a blank or tab) is not allowed between the terms and operators of an assembler expression. expressions otherwise follow the con- ventional rules of algebra and boolean arithmetic. 3.2 absolute and relative expressions an expression may be either relative or absolute . an absolute expression is one which consists only of absolute terms, or is the result of two relative terms with opposing signs. a relative expression consists of a relative term by itself or only in combination with abso- lute terms. when the assembler is operating in relative mode all address expressions must adhere to the above definitions for absolute or relative expressions. this is because only these types of expressions will retain a meaningful value after program relocation. for example, when relative terms are paired with opposing signs, the result is the difference between the two relative terms, which is an absolute value. however, if two positive relative terms are added together the result is unpredictable based on the computed values of the terms at relocation time. 3.3 expression memory space attribute a symbol is associated with either an integer or a floating point value which is used in place of the symbol during the expression evaluation. each symbol also carries a memory space attribute of either x , y , l , p rogram, e mi, or n one. constants and floating point ex- pressions always have a memory space attribute of n one. the result of an expression will always have a memory space attribute associated with it. the unary logical negate oper- ator, relational operators, and some functions return values that have a memory space at- tribute of n . the result of an expression that has only one operand (and possibly the unary negate or unary minus operator) always has the memory attribute of that operand. ex- f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
expressions expression memory space attribute 3-2 dsp assembler reference manual motorola pressions that involve two or more operands and operators other than those mentioned above derive the memory space attribute of the result by examining the operands on the left and right side of an operator as shown in the following chart: left operand memory space attribute xylpen right operand x x* x* *x memory space attribute y * yy* *y l xyl * *l p ***p*p e ****ee n xyl pen * = represents an illegal operation that will result in an error. notice that l memory space is regarded as a union of both x and y space. in expressions that have one element that has a memory space attribute of l and another element with a memory space attribute of either x or y , the result will have the more restrictive memory space attribute ( x or y ). the memory space attribute is regarded by the assembler as a type, in the same sense that high level languages use type for variables. symbols that are assigned memory space attributes of x , y , l , p , or e are assumed to be addresses and therefore can only have values between zero and the maximum address of the target processor. only sym- bols that have a memory space attribute of n can have values greater than the maximum address of the target machine. memory space attributes become important when an expression is used as an address. errors will occur when the memory space attribute of the expression result does not match the explicit or implicit memory space specified in the source code. memory spaces are explicit when the address has any of the following forms: x: y: l: p: e: the memory space is implicitly p when an address is used as the operand of a do , branch, or jump-type instruction. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
expressions internal expression representation motorola dsp assembler reference manual 3-3 expressions used for immediate addressing can have any memory space attribute. 3.4 internal expression representation expression value representation internal to the assembler is dependent on the word size of the target processor. the assembler supports a word and a double word integer format internally. the actual storage size of an expression value is dependent upon the magni- tude of the result, but the assembler is capable of representing signed integers up to 64 bits in length. these longer integer representations are useful when performing data ini- tialization in l memory space. internal floating point representation is almost entirely dependent upon the host environ- ment, but in general floating point values are stored in double precision format. this means that there are ordinarily 64 bits of storage allotted for a floating point number by the assembler, with 11 bits of exponent, 53 bits of mantissa, and an implied binary point. 3.5 constants constants represent quantities of data that do not vary in value during the execution of a program. 3.5.1 numeric constants numeric constants can be in one of three bases: binary binary constants consist of a percent sign ( % ) followed by a string of binary digits (0,1). example: %11010 hexadecimal hexadecimal constants consist of a dollar sign ( $ ) followed by a string of hexadecimal digits (0-9, a-f, a-f). example: $12ff, $12ff decimal decimal constants can be either floating point or integer. integer decimal constants consist of a string of decimal (0-9) digits op- tionally preceded by a grave accent ( ` ). floating point constants are indicated either by a preceding, following, or included decimal point or by the presence of an upper or lower case e followed by the exponent. example: 12345 (integer) 6e10 (floating point) f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
expressions operators 3-4 dsp assembler reference manual motorola .6 (floating point) 2.7e2 (floating point) a constant may be written without a leading radix indicator if the input radix is changed using the radix directive. for example, a hexadecimal constant may be written without the leading dollar sign ( $ ) if the input radix is set to16 (assuming an initial radix of 10). the default radix is10. see chapter 6 on the radix directive for more information. 3.5.2 string constants string constants that are used in expressions are converted to a concatenated sequence of ascii bytes (right aligned), as shown below. strings used in expressions are limited to the long word size of the target processor; subsequent characters in the string are ig- nored. null strings (strings that have no characters) have a value of 0. string constants greater than the maximum number of characters can be used in expres- sions, but the assembler will truncate the value and will use only those characters that will fit in a dsp long word. in this case, a warning will be printed. this restriction also applies to string constants using the string concatenation operator. handling of string constants by the dc and dcb directives is an exception to this rule; see chapter 6 for a description. examples: 'abcd' ($41424344) '''79' ($00273739) 'a' ($00000041) '' ($00000000) - null string 'abcdef' ($61626364) 'abc'++'de' ($61626364) 3.6 operators some of the assembler operators can be used with both floating point and integer values. if one of the operands of the operator has a floating point value and the other has an in- teger value, the integer will be converted to a floating point value before the operator is applied and the result will be floating point. if both operands of the operator are integers, the result will be an integer value. similarly, if both the operands are floating point, the result will be a floating point value. 3.6.1 unary operators plus ( + ) minus ( - ) ones complement ( ~ ) - integer only logical negate ( ! ) f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
expressions operators motorola dsp assembler reference manual 3-5 the unary plus operator returns the value of its operand. the unary minus operator returns the negative of its operand. the ones complement operator returns the ones complement of its operand. it cannot be used with a floating point operand. the unary logical negation operator returns an integer 1 (memory space attribute n one) if the value of its operand is 0 and will return a 0 otherwise. for example, if the symbol buf had a value of 0, then ! buf would have a value of 1. if buf had a value of 1000, ! buf would have a value of 0. 3.6.2 arithmetic operators addition ( + ) subtraction ( - ) multiplication ( * ) division ( / ) mod ( % ) the addition operator yields the sum of its operands. the subtraction operator yields the difference of its operands. the multiplication operator yields the product of its operands. the divide operator yields the quotient of the division of the first operand by the second. for integer operands the divide operation will produce a truncated integer result. the mod operator applied to integers will yield the remainder from the division of the first operand by the second. if the mod operator is used with floating point operands, the mod operator will apply the following rules: y % z = y if z = 0 = x if z <> 0 where x has the same sign as y, is less than z, and satisfies the relationship: y = i * z + x where i is an integer. 3.6.3 shift operators shift left ( << ) - integer only shift right ( >> ) - integer only f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
expressions operators 3-6 dsp assembler reference manual motorola the shift left operator causes the left operand to be shifted to the left (and zero-filled) by the number of bits specified by the right operand. the shift right operator causes the left operand to be shifted to the right by the number of bits specified by the right operand. the sign bit will be extended. shift operators cannot be applied to floating point operands. 3.6.4 relational operators less than ( < ) less than or equal ( <= ) greater than ( > ) greater than or equal ( >= ) equal ( == ) not equal ( != ) relational operators all work the same way. if the indicated condition is true, the result of the expression is an integer 1. if it is false, the result of the expression is an integer 0. in either case, the memory space attribute of the result is n one. for example, if d has a value of 3 and e has a value of 5, then the result of the expression d < e is 1, and the result of the expression d > e is 0. each operand of the conditional op- erators can be either floating point or integer. test for equality involving floating point val- ues should be used with caution, since rounding error could cause unexpected results. relational operators are primarily intended for use with the conditional assembly if direc- tive, but can be used in any expression. 3.6.5 bitwise operators and ( & ) - integer only or ( | ) - integer only exclusive or ( ^ ) - integer only the bitwise and operator yields the bitwise and function of its operands. the bitwise or operator yields the bitwise or function of its operands. the bitwise exclusive or operator yields the bitwise exclusive or function of its oper- ands. bitwise operators cannot be applied to floating point operands. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
expressions operator precedence motorola dsp assembler reference manual 3-7 3.6.6 logical operators logical and ( && ) logical or ( || ) the logical and operator returns an integer 1 if both of its operands are nonzero; other- wise, it returns an integer 0. the logical or operator returns an integer 1 if either of its operands is nonzero; otherwise it returns an integer 0. the types of the operands may be either integer or floating point; the memory space at- tribute of the result is n one. logical operators are primarily intended for use with the con- ditional assembly if directive, but can be used in any expression. 3.7 operator precedence expressions are evaluated with the following operator precedence: 1. parenthetical expression (innermost first) 2. unary plus, unary minus, ones complement, logical negation 3. multiplication, division, mod 4. addition, subtraction 5. shift 6. relational operators: less, less or equal, greater, greater or equal 7. relational operators: equal, not equal 8. bitwise and, or, eor 9. logical and, or operators of the same precedence are evaluated left to right. valid operands include nu- meric constants, literal ascii strings, and symbols. the ones complement, shift, and bit- wise operators cannot be applied to floating point operands. that is, if the evaluation of an expression (after operator precedence has been applied) results in a floating point number on either side of any of these operators, an error will be generated. 3.8 functions the assembler has several built-in functions to support data conversion, string compari- son, and transcendental math computations. functions may be used as terms in any ar- bitrary expression. functions may have zero or more arguments, but must always be followed by open and closed parentheses. function arguments which are expressions must be absolute expressions except where noted. arguments containing external refer- ences are not allowed. there must be no intervening spaces between the function name f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
expressions functions 3-8 dsp assembler reference manual motorola and the opening parenthesis, and there must be no spaces between comma-separated arguments. assembler functions can be grouped into five types: 1. mathematical functions 2. conversion functions 3. string functions 4. macro functions 5. assembler mode functions 3.8.1 mathematical functions the mathematical functions comprise transcendental, random value, and min/max func- tions, among others: abs - absolute value acs - arc cosine asn - arc sine at2 - arc tangent atn - arc tangent cel - ceiling function coh - hyperbolic cosine cos - cosine flr - floor function l10 - log base 10 log - natural logarithm max - maximum value min - minimum value pow - raise to a power rnd - random value sgn - return sign sin - sine snh - hyperbolic sine sqt - square root tan - tangent tnh - hyperbolic tangent xpn - exponential function f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
expressions functions motorola dsp assembler reference manual 3-9 3.8.2 conversion functions the conversion functions provide conversion between integer, floating point, and fixed point fractional values: cvf - convert integer to floating point cvi - convert floating point to integer cvs - convert memory space fld - shift and mask operation frc - convert floating point to fractional lfr - convert floating point to long fractional lng - concatenate to double word lun - convert long fractional to floating point rvb - reverse bits in field unf - convert fractional to floating point 3.8.3 string functions string functions compare strings, return the length of a string, and return the position of a substring within a string: len - length of string pos - position of substring in string scp - compare strings 3.8.4 macro functions macro functions return information about macros: arg - macro argument function cnt - macro argument count mac - macro definition function mxp - macro expansion function f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
expressions functions 3-10 dsp assembler reference manual motorola 3.8.5 assembler mode functions miscellaneous functions having to do with assembler operation: ccc - cumulative cycle count chk - current instruction/data checksum ctr - location counter type def - symbol definition function exp - expression check int - integer check lcv - location counter value lst - list directive flag value msp - memory space rel - relative mode function individual descriptions of each of the assembler functions follow. they include usage guidelines, functional descriptions, and examples. @abs( ) returns the absolute value of as a floating point value. the memory space attribute of the result will be n one. example: move # @abs( val ) ,d4.s ; load absolute value @acs( ) returns the arc cosine of as a floating point value in the range zero to pi. the result of must be between -1 and 1. the memory space attribute of the result will be n one. example: acos = @acs( -1.0 ) ; acos = 3.141593 @arg( | ) returns integer 1 if the macro argument represented by or is present, 0 otherwise. if the argument is a symbol it must be single-quoted and refer to a dummy argument name. if the argument is an expression it refers to the ordinal position of the argument in the macro dummy argument list. a warning will be issued if this function is used when no macro expansion is active. the memory space attribute of the result will be n one. example: if @arg( twiddle ) ; twiddle factor provided? f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
expressions functions motorola dsp assembler reference manual 3-11 @asn( ) returns the arc sine of as a floating point value in the range -pi/2 to pi/2. the result of must be between -1 and 1. the memory space attribute of the result will be n one. example: arcsine set @asn( -1.0 ) ; arcsine = -1.570796 @at2( ) returns the arc tangent of / as a floating point value in the range -pi to pi. expr1 and expr2 must be separated by a comma. the memory space attribute of the result will be n one. example: atan equ @at2( -1.0,1.0 ) ; atan = -0.7853982 @atn( ) returns the arc tangent of as a floating point value in the range -pi/ 2 to pi/2. the memory space attribute of the result will be n one. example: move # @atn( 1.0 ) ,d0.s ; load arc tangent @ccc() returns the cumulative cycle count as an integer. useful in conjunction with the cc , nocc , and contcc assembler options (see the opt directive). the mem- ory space attribute of the result will be n one. example: if @ccc() > 200 ; cycle count > 200? @cel( ) returns a floating point value which represents the smallest integer greater than or equal to . the memory space attribute of the result will be n one. example: ceil set @cel( -1.05 ) ; ceil = -1.0 f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
expressions functions 3-12 dsp assembler reference manual motorola @chk() returns the current instruction/data checksum value as an integer. useful in con- junction with the ck , nock , and contck assembler options (see the opt direc- tive). note that assignment of the checksum value with directives other than set could cause phasing errors due to different generated instruction values between passes. the memory space attribute of the result will be n one. example: chksum set @chk() ; reserve checksum value @cnt() returns the count of the current macro expansion arguments as an integer. a warning will be issued if this function is used when no macro expansion is active. the memory space attribute of the result will be n one. example: argcnt set @cnt() ; squirrel away arg count @coh( ) returns the hyperbolic cosine of as a floating point value. the mem- ory space attribute of the result will be n one. example: hycos equ @coh( val ) ; compute hyperbolic cosine @cos( ) returns the cosine of as a floating point value. the memory space attribute of the result will be n one. example: dc - @cos( @cvf(count)*freq ) ; compute cosine value @ctr( { l | r } ) if l is specified as the argument, returns the counter number of the load location counter. if r is specified, returns the counter number of the runtime location counter. the counter number is returned as an integer value with memory space of n one. example: cnum = @ctr( r ) ; runtime counter number f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
expressions functions motorola dsp assembler reference manual 3-13 @cvf( ) converts the result of to a floating point value. the memory space attribute of the result will be n one. example: float set @cvf( 5 ) ; float = 5.0 @cvi( ) converts the result of to an integer value. this function should be used with caution since the conversions can be inexact (e.g., floating point values are truncated). the memory space attribute of the result will be n one. example: int set @cvi( -1.05 ) ; int = -1 @cvs( { x | y | l | p | e | n }, ) converts the memory space attribute of to that specified by the first argument; returns . see section 3.3 for more information on memory space attributes. the may be relative or absolute. example: loaddr equ @cvs( x,target ) ; set loaddr to x:target @def( ) returns an integer 1 (memory space attribute n ) if has been defined, 0 otherwise. may be any label not associated with a macro or section directive. if is quoted it is looked up as a define symbol; if it is not quot- ed it is looked up as an ordinary label. example: if @def( angle ) ; assemble if angle defined @exp( ) returns an integer 1 (memory space attribute n ) if the evaluation of would not result in errors. returns 0 if the evaluation of would cause an error. no error will be output by the assembler if contains an er- ror. no test is made by the assembler for warnings. the may be relative or absolute. example: if ! @exp( @frc(val) ) ; skip on error f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
expressions functions 3-14 dsp assembler reference manual motorola @fld( ,,[,] ) shift and mask into for bits beginning at bit . if is omitted, zero (least significant bit) is assumed. all arguments must be positive integers and none may be greater than the target word size. returns the shifted and masked value with a memory space attribute of n one. example: switch equ @fld( tog,1,1,7 ) ; turn eighth bit on @flr( ) returns a floating point value which represents the largest integer less than or equal to . the memory space attribute of the result will be n one. example: floor set @flr( 2.5 ) ; floor = 2.0 @frc( ) for binary fractional dsps (dsp56000) this functions performs scaling and con- vergent rounding to obtain the fractional representation of the floating point as an integer. for floating point dsps (dsp96000) this function simply returns the binary representation of as an integer. the memory space attribute of the result will be n one. example: frac equ @frc( flt ) +1 ; compute saturation @int( ) returns an integer 1 (memory space attribute n ) if has an integer re- sult, 0 otherwise. the may be relative or absolute. example: if @int( term ) ; insure integer value @l10( ) returns the base 10 logarithm of as a floating point value. must be greater than zero. the memory space attribute of the result will be n one. example: log equ @l10( 100.0 ) ; log = 2 f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
expressions functions motorola dsp assembler reference manual 3-15 @lcv( { l | r }[,{ l | h | }] ) if l is specified as the first argument, returns the memory space attribute and value of the load location counter. if r is specified, returns the memory space attribute and value of the runtime location counter. the optional second argument indicates the l ow, h igh, or numbered counter and must be separated from the first argument by a comma. if no second argument is present the default counter (counter 0) is assumed. the @lcv function will not work correctly if used to specify the runtime counter value of a relocatable overlay. this is because the resulting value is an overlay ex- pression, and overlay expressions may not be used to set the runtime counter for a subsequent overlay. see the org directive (chapter 6) for more information. also, @lcv ( l ,...) will not work inside a relocatable overlay. in order to obtain the load counter value for an overlay block, origin to the load space and counter imme- diately before the overlay and use @lcv(l) to get the beginning load counter val- ue for the overlay. example: addr = @lcv( r ) ; save runtime address @len( ) returns the length of as an integer. the memory space attribute of the result will be n one. example: slen set @len( 'string' ) ; slen = 6 @lfr( ) for binary fractional dsps (dsp56000) this functions performs scaling and con- vergent rounding to obtain the fractional representation of the floating point as a long integer. for floating point dsps (dsp96000) this function simply returns the binary representation of as a long integer. the memory space attribute of the result will be n one. example: lfrac equ @lfr( lflt ) ; store binary form f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
expressions functions 3-16 dsp assembler reference manual motorola @lng( , ) concatenates the single word and into a double word value such that is the high word and is the low word. the memory space attribute of the result will be n one. example: lword dc @lng( hi,lo ) ; build long word @log( ) returns the natural logarithm of as a floating point value. must be greater than zero. the memory space attribute of the result will be n one. example: log equ @log( 100.0 ) ; log = 4.605170 @lst() returns the value of the list directive flag as an integer, with a memory space at- tribute of n one. whenever a list directive is encountered in the assembler source, the flag is incremented; when a nolist directive is encountered, the flag is decremented. example: dup @cvi(@abs( @lst() )) ; list unconditionally @lun( ) converts the double-word to a floating point value. for fractional dsps (dsp56000) should represent a binary fraction. for floating point dsps (dsp96000) should represent a binary floating point number. the memory space attribute of the result will be n one. example: dblfrc equ @lun( $3fe0000000000000 ) ;dblfrc = 0.5 @mac( ) returns an integer 1 (memory space attribute n ) if has been defined as a macro name, 0 otherwise. example: if @mac( domul ) ; expand macro f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
expressions functions motorola dsp assembler reference manual 3-17 @max( [,...,] ) returns the greatest of ,..., as a floating point value. the memory space attribute of the result will be n one. example: max dc @max( 1.0,5.5,-3.25 ) ; max = 5.5 @min( [,...,] ) returns the least of ,..., as a floating point value. the memory space attribute of the result will be n one. example: min dc @min( 1.0,5.5,-3.25 ) ; min = -3.25 @msp( ) returns the memory space attribute of as an integer value: none = 0 x space = 1 y space = 2 l space = 3 p space = 4 e space = 5 the may be relative or absolute. example: mem set @msp( origin ) ; save memory space @mxp() returns an integer 1 (memory space attribute n ) if the assembler is expanding a macro, 0 otherwise. example: if @mxp() ; macro expansion active? @pos( ,[,] ) returns the position of string in as an integer, starting at position . if is not given the search begins at the beginning of . if the f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
expressions functions 3-18 dsp assembler reference manual motorola argument is specified it must be a positive integer and cannot exceed the length of the source string. the memory space attribute of the result will be n one. example: id equ @pos( 'dsp96000','96' ) ; id = 3 @pow( , ) returns raised to the power as a floating point value. and must be separated by a comma. the memory space attribute of the result will be n one. example: buf equ @cvi( @pow( 2.0,3.0 ) ) ; buf = 8 @rel() returns an integer 1 (memory space attribute n ) if the assembler is operating in relative mode, 0 otherwise. example: if @rel() ; in relative mode? @rnd() returns a random value in the range 0.0 to 1.0. the memory space attribute of the result will be n one. example: seed dc @rnd() ; save initial seed value @rvb( [,] ) reverse the bits in delimited by the number of bits in . if is omitted the field is bounded by the target word size. both expressions must be single word integer values. example: rev equ @rvb( val ) ; reverse all bits in value f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
expressions functions motorola dsp assembler reference manual 3-19 @scp( , ) returns an integer 1 (memory space attribute n ) if the two strings compare, 0 oth- erwise. the two strings must be separated by a comma. example: if @scp( str,'main' ) ; does str equal main? @sgn( ) returns the sign of as an integer: -1 if the argument is negative, 0 if zero, 1 if positive. the memory space attribute of the result will be n one. the may be relative or absolute. example: if @sgn( input ) ; is sign positive? @sin( ) returns the sine of as a floating point value. the memory space at- tribute of the result will be n one. example: dc @sin( @cvf(count)*freq ) ; compute sine value @snh( ) returns the hyperbolic sine of as a floating point value. the memory space attribute of the result will be n one. example: hsine equ @snh( val ) ; hyperbolic sine @sqt( ) returns the square root of as a floating point value. must be positive. the memory space attribute of the result will be n one. example: sqrt equ @sqt( 3.5 ) ; sqrt = 1.870829 f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
expressions functions 3-20 dsp assembler reference manual motorola @tan( ) returns the tangent of as a floating point value. the memory space attribute of the result will be n one. example: move # @tan( 1.0 ) ,d1.s ; load tangent @tnh( ) returns the hyperbolic tangent of as a floating point value. the memory space attribute of the result will be n one. example: htan = @tnh( val ) ; hyperbolic tangent @unf( ) converts to a floating point value. for fractional dsps (dsp56000) should represent a binary fraction. for floating point dsps (dsp96000) should represent a binary floating point number. the memory space attribute of the result will be n one. example: frc equ @unf( $400000 ) ; frc = 0.5 @xpn( ) returns the exponential function (base e raised to the power of ) as a floating point value. the memory space attribute of the result will be n one. example: exp equ @xpn( 1.0 ) ; exp = 2.718282 f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
motorola dsp assembler reference manual 4-1 chapter 4 software project management 4.1 introduction the motorola dsp assemblers provide several directives designed to assist in the devel- opment of large software projects. complex software projects often are divided into small- er program units. these subprograms may be written by a team of programmers in parallel, or they may be programs written for a previous development effort that are going to be reused. the assembler provides directives to encapsulate program units and permit the free use of symbol names within subprograms without regard to symbol names used in other programs. these encapsulated program units are called sections . sections are also the basis for relocating blocks of code and data, so that concerns about memory placement are postponed until after the assembly process. 4.2 sections a section is bounded by a section directive and an endsec directive. for example: section [global | static | local] . . section source statements . . endsec all symbols that are defined within a section have the associated with them. this serves to protect them from like-named symbols elsewhere in the program. by default, a symbol defined inside any given section is private to that section unless the global or local qualifiers accompany the section directive. more information on the global and local qualifiers can be found in sections and data hiding, below. any code or data inside a section is considered an indivisible block with respect to relo- cation. code or data associated with a section is independently relocatable within the memory space to which it is bound, unless the static qualifier follows the section di- rective on the instruction line. more information on the static qualifier is available in sections and relocation, below. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management sections and data hiding 4-2 dsp assembler reference manual motorola 4.3 sections and data hiding symbols within a section are generally distinct from other symbols used elsewhere in the source program, even if the symbol name is the same. this is true as long as the section name associated with each symbol is unique, the symbol is not declared public ( xdef or global ), and the global or local qualifiers are not used in the section declaration (see below). symbols that are defined outside of a section are considered global symbols and have no explicit section name associated with them. global symbols may be refer- enced freely from inside or outside of any section, as long as the global symbol name does not conflict with another symbol by the same name in a given section. consider the fol- lowing example: sym1 equ 1 sym2 equ 2 section example sym1 equ 3 move #sym1,r0 move #sym2,r1 endsec move #sym1,r2 sym1 and sym2 are global symbols, initially defined outside of any section. then in sec- tion example another instance of sym1 is defined with a different value. because sym1 was redefined inside the section, the value moved to r0 will be 3. since sym2 is a global symbol the value moved to r1 will be 2. the last move to r2 is outside of any section and thus the global instance of sym1 is used; the value moved to r2 is 1. 4.3.1 sections and symbols symbols may be shared among sections through use of the xdef and xref directives. the xdef directive instructs the assembler that certain symbol definitions that occur within the current section are to be accessible by other sections: xdef ,,..., the xref directive instructs the assembler that all references to within the cur- rent section are references to a symbol that was declared public within another section with the xdef directive: xref ,,..., f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management sections and data hiding motorola dsp assembler reference manual 4-3 xdef ed symbols by default are recognized only in other sections which xref them. they can be made fully global (recognizable by sections which do not xref them) by use of the xr option (see the opt directive, chapter 6). alternatively the global directive (see chapter 6) may be used within a section to make the named symbols visible outside of the section. both the xdef and xref directives must be used before the symbols to which they refer are defined or used in the section. here is another example: sym1 equ 1 section sect1 xdef sym2 sym1 equ 2 sym2 equ 3 endsec section sect2 xref sym2 move #sym1,r0 move #sym2,r1 endsec move #sym2,r2 sym1 is first defined outside of any section. then in section sect1 sym2 is declared public with an xdef directive. sym1 is also defined locally to section sect1. in section sect2 sym2 is declared external via the xref directive, followed by a move of sym1 to r0. since sym1 was defined locally to section sect1, the assembler uses the global value and moves a 1 to r0. because sym2 was declared external in section sect1 the value moved to r1 is 3. if sym2 had not been xref ed in section sect2 the value moved to r1 would have been unknown at this point. in the last instruction it is not known what value will be moved to r2 since sym2 was not defined outside of any section or was not declared global within a section. if the global qualifier follows the in the section directive, then all symbols defined in the section until the next endsec directive are considered global. the effect is as if every symbol in the section were declared with the global directive. this is useful when a section needs to be independently relocatable, but data hiding is not required. if the local qualifier follows the in the section directive, then all sym- bols defined in the section until the next endsec directive are visible to the immediately enclosing section. the effect is as if every symbol in the section were defined within the parent section. this is useful when a section needs to be independently relocatable, but data hiding within an enclosing section is not required. symbols that are defined with the set directive can be made visible with xdef only in absolute mode, and the section name associated with the symbol will be the section name of the section where the symbol was first defined. this will be true even if the symbol value is changed in another section. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management sections and data hiding 4-4 dsp assembler reference manual motorola 4.3.2 sections and macros the division of a program into sections controls not only labels and symbols, but also mac- ros and define directive symbols. macros defined within a section are private to that section and are distinct from macros defined in other sections even if they have the same macro name. macros defined outside of sections are considered global and may be used within any section. similarly, define directive symbols defined within a section are pri- vate to that section and define directive symbols defined outside of any section are glo- bally applied. there are no directives that correspond to xdef for macros or define symbols, therefore macros and define symbols defined in a section can never be ac- cessed globally. if global accessibility is desired, the macros and define symbols should be defined outside of any section. here is an example: define defval '1' section sect1 define defval '2' move #defval,r0 endsec move #defval,r1 the second definition of defval is visible only inside sect1, so the value moved to r0 will be 2. however, the second move instruction is outside the scope of sect1 and will therefore use the initial definition of defval. this means that the value 1 will be moved to r1. 4.3.3 nested and fragmented sections sections can be nested to any level. when the assembler encounters a nested section, the current section is stacked and the new section is used. when the endsec directive of the nested section is encountered, the assembler restores the old section and uses it. the endsec directive always applies to the most recent section directive. nesting sections provides a measure of scoping for symbol names, in that symbols defined within a given section are visible to other sections nested within it. for example, if section b is nested inside section a, then a symbol defined in section a can be used in section b with- out xdef ing in section a or xref ing in section b. this scoping behavior can be turned off and on with the nons and ns options respectively (see the opt directive, chapter 6). sections may also be split into separate parts. that is, can be used mul- tiple times with section and endsec directive pairs. if this occurs, then these separate (but identically named) sections can access each others symbols freely without the use of the xref and xdef directives. if the xdef and xref directives are used within one section, they apply to all sections with the same section name. the reuse of the section name is allowed to permit the program source to be arranged in an arbitrary manner (for example, all statements that reserve x space storage locations grouped together), but re- tain the privacy of the symbols for each section. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management sections and relocation motorola dsp assembler reference manual 4-5 4.4 sections and relocation when the assembler operates in relative mode (the default), sections act as the basic grouping for relocation of code and data blocks. for every section defined in the source a set of location counters is allocated for each dsp memory space. these counters are used to maintain offsets of data and instructions relative to the beginning of the section. at link time sections can be relocated to an absolute address, loaded in a particular order, or linked contiguously as specified by the programmer. sections which are split into parts or among files are logically recombined so that each section can be relocated as a unit. sections may be relocatable or absolute. in the assembler absolute mode (command line -a option) all sections are considered absolute. in relative mode, all sections are initially relocatable. however, a section or a part of a section may be made absolute either im- plicitly by using the org directive, or explicitly through use of the mode directive. if the assembler encounters an org directive with an absolute runtime address specifi- cation it switches to absolute mode and begins generating absolute addresses within the enclosing section. note that the mode change is effective only if the assembler was start- ed in relative mode; if the -a command line option is used the assembler always gener- ates absolute addresses. the assembler continues to generate absolute code until an endsec directive is encountered, or the mode is explicitly changed via the mode direc- tive. the mode directive allows for arbitrary switching between absolute and relocatable code generation: mode the mode directive may be issued at any time in the assembly source to alter the set of location counters used for section addressing. code generated while in absolute mode will be placed in memory at the location determined during assembly. relocatable code and data within a section are combined at link time, even if absolute blocks are inter- f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management address assignment 4-6 dsp assembler reference manual motorola spersed among relocatable blocks. the mode directive has no effect when the com- mand line -a option is active. the following is an example: section example ; relocatable section ; code/data generated here is relocatable mode absolute ; code/data generated here is absolute; it will be ; placed in memory at the location specified during ; assembly mode rel ; back to relocatable; code/data generated here ; will be combined with the previous relocatable block, ; as long as memory space and mappings are compatible org p:$200 ; code/data generated here will be absolute ; until endsec directive is found endsec more information on the org and mode directives can be found in address assignment and under the individual directive descriptions in chapter 6. if the static qualifier follows the in the section directive, then all code and data defined in the section until the next endsec directive are relocated in terms of the immediately enclosing section. the effect with respect to relocation is as if all code and data in the section were defined within the parent section. this is useful when a sec- tion needs data hiding, but independent relocation is not required. 4.5 address assignment the motorola dsp assembler can support absolute address assignment at assembly time or generation of relocatable program addresses which are resolved during the linking phase. the org directive is used to specify memory space changes, mappings to phys- ical memory, and absolute address assignment. various memory layouts require special handling for data generation or location counter updating. in the case of l memory, two words of code or data are produced for each in- f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management address assignment motorola dsp assembler reference manual 4-7 crement of the location counter. there are many kinds of e memory depending on the characteristics of the ram devices used. in most cases e memory implies splitting the generated word into 8-bit triplets or 8 and 16-bit pairs on output, and adjusting the location counter appropriately. the assembler allows for two sets of program counters per memory space, a set of load counters and a set of runtime counters. the distinction between load and runtime counters is maintained so that the assembler can support overlays , or runtime transfers of code/data from one memory space to another. in these cases code or data might be loaded in one memory space at a given address, but then copied to a different memory space and address for execution. the assembler can produce output for either absolute or relocatable overlays. motorola dsps are capable of performing special-purpose addressing on data structures suited to digital signal processing applications. two such data structures are the modulo buffer and the reverse-carry buffer, collectively referred to as circular buffers . due to the way they are accessed and manipulated, these buffers generally are constrained to a par- ticular size or starting address. the assembler provides directives for aligning buffer base addresses, allocating buffer space, and initializing buffer contents. 4.5.1 the org directive the org directive specifies which memory space will be the runtime memory space and which counter (the h , l , default, or numbered runtime counter associated with that mem- ory space and section) will be the runtime location counter. at the same time, the org directive indicates which memory space will be the load memory space and which counter (the h , l , default, or numbered load counter associated with that memory space and sec- tion) will be used as the load location counter. in addition, the org directive can be used to specify a physical mapping to dsp memory and to assign initial values to the runtime and load location counters. the names of the counters ( h igh, l ow, and default) are symbolic only, and the assembler performs no checks to insure that the value assigned to the h igh counter is greater than the l ow. moreover, there is no inherent relationship among numbered counters, except that counters 0, 1, and 2 correspond to the default, l ow, and h igh counters, respectively. counters are useful for providing mnemonic links between runtime and load memory spaces or among individual memory blocks. separate counters can be used to obtain blocks within a common section which are accessed from one memory space but mapped to separate physical memories. also counters are necessary for handling relocatable overlays at link time, as the dsp linker does not support the notion of separate load and runtime counters. see the examples below for more information on location counter us- age. the org directive is organized as follows: org [][]:[][,[][]:[]] f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management address assignment 4-8 dsp assembler reference manual motorola or alternatively: org [][()]:[][,[][()]:[]] which memory space (x, y, l, p, or e) will be used as the runtime memory space. if the memory space is l , any allocated datum with a value greater than the target word size will be extended to two words; otherwise, it is trun- cated. if the memory space is e , then depending on the memory space qual- ifier, any generated words will be split into bytes, one byte per word, or a 16/ 8-bit combination. which runtime counter h, l, or default (if neither h or l is specified), that is associated with the will be used as the runtime location counter. indicates the runtime physical mapping to dsp memory: i - internal, e - ex- ternal, r - rom, a - port a, b - port b. if not present, no explicit mapping is done. non-negative absolute integer expression representing the counter number to be used as the runtime location counter. must be enclosed in parenthe- ses. should not exceed the value 65535. initial value to assign to the runtime counter used as the . if is a relative expression the assembler uses the relative location counter. if is an absolute expression the assembler uses the absolute loca- tion counter. if is not specified, then the last value and mode that the counter had will be used. which memory space (x, y, l, p, or e) will be used as the load memory space. if the memory space is l , any allocated datum with a value greater than the target word size will be extended to two words; otherwise, it is trun- cated. if the memory space is e , then depending on the memory space qual- ifier, any generated words will be split into bytes, one byte per word, or a 16/ 8-bit combination. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management address assignment motorola dsp assembler reference manual 4-9 which load counter, h, l, or default (if neither h or l is specified), that is as- sociated with the will be used as the load location counter. indicates the load physical mapping to dsp memory: i - internal, e - exter- nal, r - rom, a - port a, b - port b. if not present, no explicit mapping is done. non-negative absolute integer expression representing the counter number to be used as the load location counter. must be enclosed in parentheses. should not exceed the value 65535. initial value to assign to the load counter used as the . if is a relative expression the assembler uses the relative location counter. if is an absolute expression the assembler uses the absolute loca- tion counter. if is not specified, then the last value and mode that the counter had will be used. the org directive is useful in multi-programmer projects because it provides a means for the individual programmer to specify in which memory space and which segment of that memory space the code being written will be located without specifying an absolute ad- dress. absolute address assignment can be deferred until the various components of the program are brought together. the utility of the org directive is not limited to multi-pro- grammer projects. even in single programmer projects, the org directive supports ma- nipulation of overlays and the intermixing of label definition and code generation in multiple memory spaces without having to reinitialize a location counter every time the load memory space is changed. 4.5.2 overlays if the last half of the operand field in an org directive dealing with the load memory space and counter is not specified, then the assembler will assume that the load memory space and load location counter are the same as the runtime memory space and runtime loca- tion counter. in this case, object code is being assembled to be loaded into the address and memory space where it will be when the program is run, and is not an overlay. if the load memory space and counter are given in the operand field, then the assembler always generates code for an overlay. whether the overlay is absolute or relocatable de- pends upon the current operating mode of the assembler and whether the load counter value is an absolute or relative expression. if the assembler is running in absolute mode, or if the load counter expression is absolute, then the overlay is absolute. if the assembler f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management address assignment 4-10 dsp assembler reference manual motorola is in relative mode and the load counter expression is relative, the overlay is relocatable. runtime relocatable overlay code is addressed relative to the location given in the runtime location counter expression. this expression, if relative, may not refer to another overlay block. see section 1.7 for more information on location counters and overlays. the values and memory space attributes of both the load and runtime location counters can be accessed with the @lcv function (see section 3.8). this is particularly useful when assigning the load location counter value to a label as a reference point for the over- lay manager part of the program. the h igh, l ow, default, or numbered counter assign- ment can be determined by using the @ctr function (section 3.8). 4.5.3 address assignment examples some examples of the org directive are as follows: org p:$1000 sets the runtime memory space to p. selects the default runtime counter (counter 0) associated with p space to use as the runtime location counter and initializes it to $1000. the load memory space is implied to be p, and the load location counter is assumed to be the same as the runtime location counter. org phe: sets the runtime memory space to p. selects the h load counter (counter 2) as- sociated with p space to use as the runtime location counter. the h counter will not be initialized, and its last value will be used. code generated hereafter will be mapped to external (e) memory. the load memory space is implied to be p, and the load location counter is assumed to be the same as the runtime location counter. org pi:ovl1,y: indicates code will be generated for an overlay. the runtime memory space is p, and the default counter is used as the runtime location counter. it will be reset to the value of ovl1. if the assembler is in absolute mode via the -a command line option then ovl1 must be an absolute expression. if ovl1 is an absolute expres- sion the assembler uses the absolute runtime location counter. if ovl1 is a relo- catable value the assembler uses the relative runtime location counter. in this case ovl1 must not itself be an overlay symbol (e.g. defined within an overlay block). the load memory space is y. since neither h, l, nor any counter expression was specified as the load counter, the default load counter (counter 0) will be used as the load location counter. the counter value and mode will be whatever it was the last time it was referenced. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management address assignment motorola dsp assembler reference manual 4-11 org xl:,e8: sets the runtime memory space to x. selects the l counter (counter 1) associated with x space to use as the runtime location counter. the l counter will not be ini- tialized, and its last value will be used. the load memory space is set to e, and the qualifier 8 indicates a bytewise ram configuration. instructions and data will be generated eight bits per output word with byte-oriented load addresses. the de- fault load counter will be used and there is no explicit load origin. org p(5):,y:$8000 indicates code will be generated for an absolute overlay. the runtime memory space is p, and the counter used as the runtime location counter is counter 5. it will not be initialized, and the last previous value of counter 5 will be used. the load memory space is y. since neither h, l, nor any counter expression was specified as the load counter, the default load counter (counter 0) will be used as the load location counter. the default load counter will be initialized to $8000. if the last example shown was used in the following code sequence (assume the runtime counter associated with p space had a previous value of $0010), org p(5):,y:$8000 rlmul move x:(r0),d4.s y:(r4),d7.s fmpy.s d4,d7,d0 move d0.s,x:(r1) then the label rlmul would have a value of $0010 and a memory space attribute of p space; the code generated would load into y memory starting at $8000; and the runtime address associated with the code would start at $0010. 4.5.4 circular buffers to take advantage of the special dsp addressing capabilities a circular buffer must be aligned on an appropriate address boundary with respect to its size. for a buffer to be located properly in memory the lower bits of the starting address which encompass one less than the buffer size must be zero. for example, the lowest address greater than zero at which a buffer of size 32 may be located is 32 (20 hexadecimal). more generally, the buffer base address must be modulo the buffer size, or a multiple of 2 k , where 2 k is greater than or equal to the size of the buffer. buffers may be allocated manually or by using one of the assemblers special buffer di- rectives: org x:$100 buf1 ds 24 buf2 dsm 32 f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management address assignment 4-12 dsp assembler reference manual motorola the org statement sets the origin to hexadecimal 100 in x memory. the first buffer buf1 is manually allocated with a size of 24. since the starting address is hex 100 the buffer is already suitably aligned. the label buf1 is assigned the runtime counter value at the beginning of the buffer. the second buffer is allocated using the dsm directive, which automatically sets the buffer starting address before reserving space. in this case, the first buffer ended at location 117 hexadecimal, so the assembler advances the pro- gram counter to location 120 hex before assigning a value to the buffer label buf2. buffers are special-purpose data structures, but they are named and accessed with labels like any other data block. they therefore adhere to the same rules governing data hiding in sections that any other segment of code or data would follow. a buffer allocated when the assembler is in absolute mode (either via -a or an absolute org or mode directive) is placed in memory according to the absolute value of the runtime location counter at as- sembly time. a buffer allocated in relative mode (a relocatable buffer ) is suitably aligned within its relocation section at assembly time. during the link phase a section enclosing any relocatable buffers is located based on the largest relocatable buffer it contains, un- less the buffers inside the section are auto-aligned. this insures that any smaller buffers within the section are properly aligned. if any buffers in the section are auto-aligned, they will be relocated independent of any other code or data in the section. note that reposi- tioning of any buffer, whether relocatable or absolute, may result in alignment gaps in memory depending on the layout of data surrounding the buffer blocks. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management example 1: multi-programmer environment motorola dsp assembler reference manual 4-13 4.6 example 1: multi-programmer environment typical multi-programmer projects are often split into tasks representing functional units. for discussion purposes, suppose a project has been divided into three tasks - i/o, filter, and main. each task will be written by a separate programmer as a separate section. for example, when the i/o task has been written, there will be a file called io.asm. this file will have the following form: section i_o xref i_port,o_port org xl: . . . . org p: . . . . endsec in this example, because the x space storage locations were defined within the section i_o, they will be private storage locations that are accessible only by the i_o handler, and cannot be referenced by other sections. if global memory resource management is de- sired, then the i_o section would not have defined any storage locations, and these would have been defined as xref . the x space data will be addressed through the l ow runtime counter. the p memory code is also private to the i_o section and uses the de- fault runtime location counter for address generation. in the discussion below, assume that the programmers responsible for the filter and main sections have similar program structures located in files named filter.asm and main.asm respectively. the program units can be combined either by invoking a final assembly step to assign absolute addresses, or by assembling the modules separately and then linking. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management example 1: multi-programmer environment 4-14 dsp assembler reference manual motorola 4.6.1 absolute mode implementation to assemble the entire project source code, a new file called project.asm would be created and would have the form: org xle:$0000 . . org yle:$0000 . . org yh:$ffc0 . . org xh:$ffc0 . . ; initialize internal low program memory location counter org pl:$1000 ; initialize external high program memory location counter org phe:$f000 include 'main.asm' include 'io.asm' include 'filter.asm' end entry this file provides the project manager with a mechanism to organize memory utilization to suit the application. for example, the external high p memory initialization statement might correspond to the memory location of an external eprom. after the location counters corresponding to the x, y, and p(rogram) memory spaces are initialized, the assembler is directed to take input from the main.asm file with the in- clude directive. within the main.asm file, the source statements are assembled and object code is generated. the x, y, l, and p(rogram) location counters (high, low) are advanced corresponding to the number of words generated for each memory space and location counter in use. when the end of the main.asm file is encountered, the assembler returns to the next se- quential statement in the project.asm file. this directs the assembler to start taking input from the io.asm file. within this file, the org pl: statement directs the assembler f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management example 1: multi-programmer environment motorola dsp assembler reference manual 4-15 to set the current memory space to p(rogram) and restore the last used p(rogram) l(ow) location counter. the shown previously will be assem- bled at the next available low program memory space. when the end of the io.asm file is encountered, the x, y, and p(rogram) location counters (high and low) will have been advanced corresponding to the number of words generated for each memory space. in a similar manner, the file filter.asm will be assembled. the last statement of the project.asm file informs the assembler that this is the last logical source statement, and the starting address for the object module will be a label called entry. in the exam- ple above, entry would have been a label defined in the section main and declared as global with the xdef directive. 4.6.2 relative mode implementation using the assembler default relative mode, each of the source files is assembled sepa- rately. for each section defined in the input files a separate set of location counters is maintained such that all memory spaces for each section begin at relative address zero. the linker is invoked to combine the files and establish base addresses: dsplnk -b -m -oxli:0 -oyli:0 -oyh:ffc0 -oxh:ffc0 \ -opl:1000 -ophe:a000 main io filter the linker reads the command input and sets up base values for all counters specified on the command line. in this example, the x and y low memory counters are initialized to ze- ro, whereas the x and y high memory counters are set to ffc0 hexadecimal. the pro- gram low and high memory counters are initialized similarly. when the linker creates the executable file it reads the input files and sets the starting address for all sections relative to the values obtained from the command line. as the main object file is read the linker increments the section counters for all appropriate memory spaces. after the main object file is processed, the io object file is read. the section named i_o contained an org directive indicating a switch to the low x data memory counter. recall that the assembler generated relocatable code for the i_o section source such that the low x data memory counter begins at zero. the linker adjusts the low x memory counter associated with section i_o to reflect any previous data generation performed in low x memory (e.g. in main). the filter module is linked in a similar fashion. another way for specifying base addresses, instead of lengthy command line options, is through a memory control file . the memory control file allows the programmer to indi- cate memory space starting addresses analogously to the command line approach. in ad- dition, the memory control file offers finer control over placement of sections in memory. see the motorola dsp linker/librarian reference manual for more information on the memory control file. the preceding examples described two methods for organizing a software project. refer to the descriptions of the org and section directives in chapter 6 for a more detailed discussion. see also the motorola dsp linker/librarian reference manual for more in- f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management example 2: overlays 4-16 dsp assembler reference manual motorola formation on relocation and linking. one other assembler directive that should be men- tioned (although not shown in the previous example) is the maclib directive which allows sections to share a common macro library. the maclib directive is discussed more fully in chapter 5. 4.7 example 2: overlays an overlay is a transfer of code or data from one memory space or address to another memory space or address at runtime. often the transfer involves copying different blocks of code or data over a common storage area as runtime circumstances dictate; hence the name overlay . overlays are useful for moving code into internal program memory from an external memory source such as eprom. they are also effective when implementing large programs with multiple segments which do not need to be accessed concurrently. consider the following program fragment contained in a file called over1.asm: section overlay1 xref ovlbase xdef ovl1,o1size org x: ovl1 org p:ovlbase,x: start . . . . end o1size equ end-start endsec this is a sample of overlay code bounded by a section directive. the overlay base, or the place to which this block of code will be moved for execution, is declared external at ovlbase (ovlbase is actually defined elsewhere). the label ovl1 is xdef ed to pro- vide a handle for moving the block at runtime, and o1size is also xdef ed so that the overlay management code knows how many words to move. note that the ovl1 label is placed before the org for the overlay so that it remains a valid address in x memory dur- ing execution. the overlay org directive insures that subsequent addresses will be based from ovlbase at runtime. the size of the overlay block (o1size) is computed by subtracting the start label value from the end label address. assume for purposes of discussion that there are other files containing similar overlay code with names over2.asm and over3.asm. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management example 2: overlays motorola dsp assembler reference manual 4-17 4.7.1 absolute mode implementation in order to avoid binding addresses within the individual overlay modules, the programmer could devise a preamble file called ovlproj.asm which sets the appropriate counters and establishes the overlay base address. note that the following code assumes a dsp96000, but similar instructions would apply for other target processors: section ovlproject xdef ovlbase xref ovl1,o1size xref ovl2,o2size xref ovl3,o3size org xe:$100 ; set absolute base for overlay sections org pi:$200 ; set absolute base address for overlay ovlbase ds $400 ; reserve space for overlay area moveov1 ; code to move first overlay segment move #ovl1,r0; load overlay code address move #ovlbase,r1; load overlay base address move #o1size,d1.m; load overlay code size do d1.m,_endloop; loop to move data words into p memory move x:(r0)+,d0.m; get word of overlay from data memory move d0.m,p:(r1)+; store word of overlay into p memory _endloop . . . endsec the overlay base address ovlbase is made global with the xdef statement. the over- lay segments and their sizes are made visible to the project section by using the xref directive. the first org establishes where the overlay segments will be placed in mem- ory contiguously at load time. the second org sets up the absolute base address for the overlay area common to all of the overlay segments. uninitialized space is allocated for the overlay area, immediately followed by code to move the overlay segments into the common area at runtime. the following assembler command line will process the header file and all overlay segments: asm96000 -a -b -l ovlproj over1 over2 over3 start the assembler is invoked in absolute mode ( -a option), and generates an executable and listing file. all files on the command line are processed as a single assembly run and all are used to produce the output. ovlproj.asm is read first and sets up the appropriate absolute addresses for later sections. then each overlay file is read and loaded one after the other at external x memory address 100 hexadecimal. however, since each overlay f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management example 2: overlays 4-18 dsp assembler reference manual motorola module was intended to run starting at ovlbase in p memory, all labels and jumps to those labels within the overlay code will be relative to the overlay base address. this means that the code in each of the overlay modules, when loaded by the overlay manage- ment code in the ovlproject section, will start executing at internal p memory address 200 hexadecimal. the file start.asm contains an end directive which indicates the program start address after loading. 4.7.2 relative mode implementation in relative mode each of the overlay files is assembled separately to create individual ob- ject files. the object files are combined to build a single executable file. a preamble file ovlproj.asm containing overlay management code might appear as follows. note that this code assumes a dsp96000, but similar instructions would apply for other target pro- cessors: section ovlproject xdef ovlbase xref ovl1,o1size xref ovl2,o2size xref ovl3,o3size org pi: ; set base address for overlay moveov1 ; code to move first overlay seg- ment move #ovl1,r0 ; load overlay code address move #ovlbase,r1 ; load overlay base address move #o1size,d1.m ; load overlay code size do d1.m,_endloop ; loop to move data words into p memory move x:(r0)+,d0.m ; get word of overlay from data memory move d0.m,p:(r1)+ ; store one word of overlay into p memory _endloop . . . ovlbase ds $400 ; reserve space for overlay area endsec f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management example 2: overlays motorola dsp assembler reference manual 4-19 note that the org to p space does not specify an absolute address. in order to obtain the same result from these files as in an absolute mode implementation the following link- er command line would be used: dsplnk -b -m -oxe:100 -opi:200 ovlproj over1 over2 over3 the linker scans the command line and sets the base addresses for x and p memory. here the x default counter is set to hex 100 and mapped to external memory; likewise the p default counter is set to hex 200 and mapped to internal memory. base addresses can also be established with the linker memory control file. the linker reads each input object file, placing the header file in internal p memory and combining the overlay modules into a contiguous block loaded into external x memory at location 100 hexadecimal. any labels or jumps within the overlay blocks are resolved to addresses relative to the relocatable symbol ovlbase. since ovlbase is the first load p memory address it is assigned the value 200 hexadecimal. the linker does not guaran- tee that a given symbol or section will begin at a particular location unless that information is explicitly specified in the linker memory control file. for more information on specific linker operations see the motorola dsp linker/librarian reference manual . f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management example 3: bootstrap overlay 4-20 dsp assembler reference manual motorola 4.8 example 3: bootstrap overlay many motorola dsp processors, specifically those with ram-based program memory, support a bootstrap mode of operation. this involves mapping a built-in rom-based boot- strap program into p memory, executing the program to move user-supplied code from another location (usually eprom) into program ram, then transferring control to the user program. because the user program is loaded in one location (e.g. eprom) but moved to another for execution, it is a natural application for assembly language overlay seman- tics. another wrinkle in bootstrap mode is that user instruction words are loaded in byte- wise fashion, such that the load location counter must be incremented by bytes rather than words. consider the following section fragments contained in two files called sect1.asm and sect2.asm respectively: section sect1 org pi(1):,pe(2) start1 . . . . end1 endsec . . . section sect2 org pi(1):,pe(2) start2 . . . . end2 endsec f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management example 3: bootstrap overlay motorola dsp assembler reference manual 4-21 4.8.1 absolute mode implementation in order to avoid binding addresses within the individual modules, the programmer could devise a preamble file called bootproj.asm which sets the appropriate options and establishes load and runtime base addresses: opt lb ; increment load counter by bytes org pi(1):$100,pe(2):$c000 ; set runtime ram address, ; bytewide load rom ad- dress the opt directive with the lb option indicates that the assembler should increment the load counter by the number of bytes in the target processor word. this guarantees that the eprom addresses will be correct for bytewide loading during bootstrap processing. in the org directive, the runtime location counter, tagged as 1 and mapped to internal memory, is set to hex 100. the load counter is tagged as 2, mapped to external memory, and set to hex c000, where the built-in bootstrap program will begin loading bytes after processor reset. the files are assembled using the command below: asm56100 -a -b -l bootproj sect1 sect2 the assembler is invoked in absolute mode ( -a option), and generates an executable and listing file. all files on the command line are processed as a single assembly run and all are used to produce the output. bootproj.asm is read first and sets up the appropriate absolute addresses for later sections. since no explicit base address was given in the sec- tion files, both load and runtime addresses will continue from one section to the other, e.g. they will be contiguous. for example, if only two words of instruction were between each of the start and end labels, the runtime value for end1 and start2 would be hex 102. however, the load address of the code associated with these labels, assuming a 16 bit target word size, would be c004 hexadecimal. similarly, the runtime value for end2 would be 104 hex and the corresponding load address would be c008 hexadecimal. 4.8.2 relative mode implementation in relative mode each of the source files is assembled separately to create individual ob- ject files. the object files are combined to build a single executable file. a preamble file is not necessary to handle bootstrap files in relative mode because the addresses are es- tablished at link time. in order to generate bytewide load addresses the lb option can be specified on the assembler command line using the -o command line option: asm56100 -b -l -olb sect1 this command assembles the file sect1.asm and creates a relocatable object file called sect1.cln. the listing file shows that the starting address of the section is zero; howev- er, because of the lb option on the command line the load counter will increment at twice the rate of the runtime counter (assuming a 16 bit dsp56100 family target processor). a f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
software project management example 3: bootstrap overlay 4-22 dsp assembler reference manual motorola similar command is used to assemble the sect2 module. the two files are linked as fol- lows: dsplnk -bbootproj.cld "-opi(1):100" "-ope(2):c000" sect1 sect2 the linker scans the command line and sets the base addresses for p internal and exter- nal memory. the quotes around the -o options are necessary to avoid interpretation of parentheses by some host command interpreters. here the p counter number 1 is set to hex 100 and mapped to internal memory; likewise the p counter number 2 is set to hex c000 and mapped to external memory. base addresses can also be established with the linker memory control file. since no explicit overlay base addresses were encountered in the source files, both load and runtime addresses for the sections will be adjacent and non-overlapping. assuming a code size of 2 for each section and a 16 bit word size, the value for label start1 will be hex 100 and the value for start2 will be hex 102; the corresponding load addresses will be c000 hex and c004 hex, respectively. the execut- able output will be written to the file bootproj.cld. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
motorola dsp assembler reference manual 5-1 chapter 5 macro operations and conditional assembly 5.1 macro operations programming applications frequently involve the coding of a repeated pattern or group of instructions. some patterns contain variable entries which change for each repetition of the pattern. others are subject to conditional assembly for a given occurrence of the in- struction group. in either case, macros provide a shorthand notation for handling these instruction patterns. having determined the iterated pattern, the programmer can, within the macro, designate selected fields of any statement as variable. thereafter by invoking a macro the programmer can use the entire pattern as many times as needed, substituting different parameters for the designated variable portions of the statements. when the pattern is defined it is given a name. this name becomes the mnemonic by which the macro is subsequently invoked (called). if the name of the macro is the same as an existing assembler directive or mnemonic opcode, the macro will replace the direc- tive or mnemonic opcode, and a warning will be issued. the warning can be avoided by the use of the rdirect directive, which is used to remove entries from the assemblers directive and mnemonic tables. if directives or mnemonics are removed from the assem- blers tables, then no warning will be issued when the assembler processes macros whose names are the same as the removed directive or mnemonic entries. however, if a macro is defined through the maclib directive which has the same name as an existing directive or opcode, it will not automatically replace that directive or opcode as previously described. in this case, the rdirect directive must be used to force the replacement. see the description of the maclib directive below. the macro call causes source statements to be generated. the generated statements may contain substitutable arguments. the statements produced by a macro call are rel- atively unrestricted as to type. they can be any processor instruction, almost any assem- bler directive, or any previously-defined macro. source statements resulting from a macro call are subject to the same conditions and restrictions that are applied to state- ments written by the programmer. to invoke a macro, the macro name must appear in the operation code field of a source statement. any arguments are placed in the operand field. by suitably selecting the ar- guments in relation to their use as indicated by the macro definition, the programmer causes the assembler to produce in-line coding variations of the macro definition. f r e e s c a l e s e m i c o n d u c t o r , i freescale semiconductor, inc. f o r m o r e i n f o r m a t i o n o n t h i s p r o d u c t , g o t o : w w w . f r e e s c a l e . c o m n c . . .
macro operations and conditional assembly macro libraries 5-2 dsp assembler reference manual motorola the effect of a macro call is to produce in-line code to perform a predefined function. the code is inserted in the normal flow of the program so that the generated instructions are executed with the rest of the program each time the macro is called. an important feature in defining a macro is the use of macro calls within the macro defini- tion. the assembler processes such nested macro calls at expansion time only. the nesting of one macro definition within another definition is permitted. however, the nested macro definition will not be processed until the primary macro is expanded. the macro must be defined before its appearance in a source statement operation field. 5.2 macro libraries the motorola dsp assembler allows for the maintenance of macro libraries with the ma- clib directive. this directive is used to specify the pathname (as defined by the host op- erating system) of a directory that contains macro definitions. each macro definition must be in a separate file, and the file must be named the same as the macro with the extension .asm added. for example, blockmv.asm would be a file that contained the definition of the macro called blockmv. if a maclib directive has been specified in the source code and the assembler encoun- ters a name in the operation field that is not a previously defined macro or is not contained in the directive or mnemonic tables, the directory specified in the maclib directive will be searched for a file of that name (with the .asm extension added). if such a file is found, the current source line will be saved, and the file will be opened for input as an include file. when the end of the file is encountered, the source line is restored and processing is resumed. because the source line is restored, the processed file must have a macro definition of the unknown name, or an error will result when the source line is restored and processed. however, the processed file is not limited to macro definitions, and can include any legal source code statements. multiple maclib directives may be given, in which case the as- sembler will search each directory in the order in which they were specified. 5.3 macro definition the definition of a macro consists of three parts: the header, which assigns a name to the macro and defines the dummy arguments; the body, which consists of prototype or skel- eton source statements; and the terminator. the header is the macro directive, its label, and the dummy argument list. the body contains the pattern of standard source state- ments. the terminator is the endm directive. the header of a macro definition has the form: macro [