| The Datasheet Archive - 100 Million Datasheets from 7500 Manufacturers. |
Yves Gagniere Dirk Langmesser Digital Signal Processing Solutions
Top Searches for this datasheetInterface Assembly Language with TMS320 Floating Point Compiler Yves Gagniere Dirk Langmesser Digital Signal Processing Solutions Abstract Texas Instruments (TITM) TMS320 digital signal processor (DSP) floating-point ANSI compiler generally uses conventional mechanism passing arguments allocating local variables. Nevertheless, programmer several options pass arguments function, allocate automatic variables return value from called function. programmer uses only language, compiler manages dedicated mechanism depending selected options compile time. mechanism regulates data flow between calling called function. These strict conventions transparent user. user plans interface assembly functions routines program, straightforward follow calling returning conventions well calling called function's responsibilities regarding saving restoring registers. This application report offers simple approach using case studies describe main choices available programmer interface assembly language. This report based revision Texas Instruments TMS320 floating-point tools. Contents Memory Model RAM/ROM Model.2 Function Call Digital Signal Processing Solutions December 1998 Memory Model TMS320 floating-point family supports different memory models that affect global static variables accessed. Generally, direct addressing data word memory realized through paging concatenation (TMS320C3x) (TMS320C4x) least significant bits data page pointer (DP) with least significant bits instruction word. From that, size data pages 64K-words. number pages C4x, respectively. main point that small memory model complete .bss section, which standard C-section global static variables, will accessed without ever changing pointer. This means evidently that program space cycle count might saved through this method. With small memory model, only bits instruction word used addressing. From that, there requirement that entire collection global static variables within page, which 64K-word contiguous memory space that should aligned 64K-word boundary this means that .bss section linked appropriately. small memory option default forces compiler initialize data page pointer during runtime initialization point beginning .bss section. compiler access objects located .bss section using direct addressing without ever modifying data page pointer. other hand, memory model does limit size .bss section therefore number global static variables only memory space available target system causes restriction. compiler accesses objects located .bss section with direct addressing, modifying data page pointer before each access causing least additional operation cycle. memory model option selected with command-line switch. Observe that large globally declared static array objects such table[100000] will force memory model. more efficient implementation allocates such array dynamically: *table; table (int malloc (100000 sizeof(int)); global declaration allocation main program data object then allocated heap. size heap determined linker command file with -heap option. heap identical .sysmem-section, which located memory system also through linker command file. access heap elements realized indirect with pointer addressing. RAM/ROM Model Code should generally linked with either option. compiler then produces code linked with standard library function called boot.asm located runtime support library (rts.lib). Depending option chosen link time, initialization variables will performed boot function either load time (-cr: model) runtime (-c: model). Interface Assembly Language with TMS320 Floating Point Compiler model selected, will responsibility smart loader initialize variables memory (built-in simulator debugger). model selected, .cinit section used store initialization data global static variables ROM, which will copied automatically boot routine appropriate locations within .bss before entering main routine. interfaced with assembly code that uses .bss section, will necessary create .cinit table .bss section entry assembly code according conventions. .bss .cinit definitions should have following format assembly used loader boot code routine: .bss .sect .word .word .word _variablename, size ".cinit" size _variablename value0, value1,. _variablename reference name data structure used code; size number words; section that contains tables with values initializing variables constants; size number bits words data structure; _variablename reference name data structure; values which will assigned _variablename structure; Function Call compiler imposes strict rules function calls. Failure adhere these rules disrupt environment cause program fail. programmer choose between runtime models function calls. first model, stack argument runtime model, intensively uses stack pass arguments between calling called function. called function additionally uses stack local frame temporary variables well pass arguments soon becomes calling function own. second model called register argument runtime model uses register pass arguments from calling called function. stack passing convention applies those arguments which enough registers available pass them those that compatible with register definition. stack argument runtime model default mode. more efficient register argument runtime model activated with command-line switch compiler. Preserving Registers language based function calls, where first function called from boot routine "main" function. Entering assembly context from routine makes necessary preserve environment. Basically this means that those registers used environment must saved across calls: these registers called register variables. called function's responsibility preserve contents these registers they used inside function. This type preserving scheme commonly called save-onentry. compiler remaining registers evaluate expressions store temporary results. This strategy allows compiler reuse register data, take advantage efficient register addressing modes, avoid unnecessary accesses local frame. contents these registers preserved across calls therefore must saved local frame caller function. Interface Assembly Language with TMS320 Floating Point Compiler save-on-entry registers (AR3, AR4-AR7, (C4x only)) saved called function after entry provided they used inside function. optimizer tries allocate variables registers optimizer used, compiler forced through register keyword assign save-onentry registers variable. following table summarizes usage registers highlights save-onentry registers: Register without Optimizer with Optimizer Called Function Responsibility Save Entry integer part floating part yes/no** integer part R2-R3 R4-R5 R6-R7 AR0-AR1 AR4-AR7 RC,RS R9-R11* Integer float expressions scalar return values Integer float expressions Integer float expressions Integer register variables Float register variables Pointer expressions Pointer expressions Frame pointer (FP) Pointer register variables Extended frame offsets Extended frame offsets used Block (structure) copy used Stack pointer Integer float expressions scalar return values Integer float expressions Integer float register variables Integer float register variables Integer float register variables Pointer expressions Integer pointer register variables Frame pointer (FP) Pointer register variables Extended frame offsets Integer register variables Integer register variables Block (structure) copy Block repeat loop integer register variables Stack pointer Accessing global variables (big Accessing global variables (big model only) model only) Integer register variables Integer float variables Integer float register variables Integer float variables only small model/no model special case implementation interrupt service routine, registers used inside routine must saved stack. interrupt pragma program interrupt service routine necessary preserving registers will then done automatically. Stack Argument Runtime Model TMS320 floating point compiler uses conventional mechanism manage stack passing arguments allocating space local variables function. stack pointer hardware register. stack grows toward higher addresses stack pointer always points last element pushed onto stack, i.e., stack. size stack determined through linker command file with stack option. Interface Assembly Language with TMS320 Floating Point Compiler second register called Frame Pointer (FP) points local frame called function. Basically, this pointer reference address access both arguments local frame. seen that local frame accessed indirect manner with pointer offset addressing. From that, restriction caused maximum offset size eight bits. Consequently, number local variables that accessed without overhead also restricted: local frame should excess words. this restriction cannot met, most often used variables should declared first. access local frame across word boundary causes extra cycle loading offset index register plus additional pipeline delay cycles. been defined with syntactic replacement readability purposes: .set AR3. This means that processor register that used convention this purpose nickname compiler. following code "example0.c" shown here learning exercise. func(int c=3,d=4; void main(void) a=1,b=2; (;;) func(c,d); func (int return(x); function that arguments that returns integer result; this function local variable; parameters; automatic variable constant; return result caller; prototype func; global variables; first function called; automatic local variables; infinite loop; increment global variable; call function that arguments that should return integer; local variable; compiler call cl30 example0.c produces following assembly code. options are: Stack argument runtime model Small memory model optimization From that, some parts code could implemented more efficiently; however, readability would worse. TMS320C3x/4x ANSI Code Generator Version 5.00 Date/Time created: 14:43:05 1997 .regalias enable floating point register aliases .set .set GLOBAL FILE PARAMETERS Interface Assembly Language with TMS320 Floating Point Compiler Optimization Always Choose Smaller Code Size Memory Small Memory Model Float-to-Int Normal Conversions (round toward -inf) Multiply Software bits) Memory Info Unmapped Memory Exists Repeat Loops RPTS and/or RPTB Calls Normal Library call Debug Info Debug Info C:\C3xTOOLS\ac30.exe example0.c C:\temp\example0.if .sect .field .field .field .sect ".cinit" 1,32 _c+0,32 3,32 ".text" definitions .cinit tables .global .bss _c,1 .sect .field .field .field .sect ".cinit" 1,32 _d+0,32 4,32 ".text" reservation un-initialized space global variable .global .bss _d,1 .sect ".text" reservation un-initialized space global variable .global _main FUNCTION NAME: _main Architecture TMS320C30 Calling Convention Stack Parameter Convention Function Uses Regs r0,r1,sp Regs Saved Stack Frame Full (Frame Pointer AR3) Total Frame Size Call Parm Auto words _main: step performed call _main boot routine push step save local frame ldiu sp,fp initialize ldiu 1,r1 addi 2,sp step allocate local frame ldiu 2,r0 r1,*+fp(1) step initialize local frame r0,*+fp(2) initialize local frame ldiu 1,r0 addi @_d+0,r0 access (defined .bss) with direct addressing r0,@_d+0 write back push step revised pushed stack Interface Assembly Language with TMS320 Floating Point Compiler ldiu push call ldiu addi subi @_c+0,r0 _func 2,r1 r0,*+fp(1) *+fp(1),r1 r1,*+fp(2) 2,sp access with direct addressing step pushed stack step call _func function save return address stack Call Occurs places return value (r0) location branch delayed beginning for(;;) loop computed result stored location step pops arguments Branch Occurs return boot routine does occur here since main program looping endlessly .sect ".text" .global _func FUNCTION NAME: _func Architecture TMS320C30 Calling Convention Stack Parameter Convention Function Uses Regs r0,r1 Regs Saved Stack Frame Full (Frame Pointer AR3) Total Frame Size Call Parm Auto words _func: push step save local frame ldiu sp,fp initialize addi 1,sp step allocate local frame ldiu 2,r0 ldiu *-fp(3),r1 load argument addi *-fp(2),r1 load argument r1,*+fp(1) store result into location addi *+fp(1),r0 compute r0,*+fp(1) write back (might optimized) also contains return value function ldiu *-fp(1),r1 load return address into branch delayed return address subi 3,sp step local frame location, return address removed from stack ldiu *fp,fp restore into Branch Occurs Within this code basically three sections: .cinit, .bss, .text. .cinit section contains tables with values initialize global variables. .text section contains program. code global variables called assembly name preceded with underscore: .cinit section, these variables defined using specific format seen previously. Example .cinit table definition: .sect .field ".cinit" 1,32 definitions .cinit tables there value just indicates length bit-field) Interface Assembly Language with TMS320 Floating Point Compiler .field .field _c+0,32 3,32 value copied location value which should copied .bss section, compiler reserves memory space variables, which will initialized either boot routine specific loader. Example .bss definition: .bss _c,1 address un-initialized location before entering main() will initialized with value coming from .cinit section loader boot routine been defined syntactic replacement register used reference pointer address either arguments automatic variables, i.e. variables that come into existence only when appropriate function called disappear when function exited. boot routine called "boot.asm", which standard replaced userdefined equivalent. "boot.asm" should generally perform following tasks: Reset status register zero. Initialize stack pointer. page address .cinit section. Check whether user selected model. user selected model, then .bss will auto-initialized; otherwise, this done external loader. data page pointer (DP) point .bss section (used only small memory model). Call code (call _main). This ensures that entry point user code _main reached with function call. Because been accessed with call, processor automatically saves stack return address caller (step called function save previous Frame Pointer following reasons: restore context exit (step initialize point frame pointer (ldiu allocate space local frame automatic variables initialize them Because actually points first local variable addressed *+fp(1) second variable *+fp(2) (sti *+fp(1) *+fp(2) seen step Afterward, global variable incremented pushed together with onto stack arguments (step important notice that arguments pushed reverse order; i.e., rightmost declared argument pushed first, leftmost pushed last. This makes straightforward indirectly access arguments through because leftmost only offset minus rightmost maximum offset. This method called standard runtime model. Interface Assembly Language with TMS320 Floating Point Compiler call func then occurs (step return address automatically saved onto stack this final action done caller. responsibility called function save frame pointer onto stack (step Frame Pointer current (ldiu fp). local frame allocated here adding because there only local variable (step called function access arguments, which addressed *-fp(2) *fp(3) respectively, value computed stored local frame (sti *+fp(1)). called function returns integer therefore return value located more information, section, Return Function. called function executed code returns caller. This action performed within four steps: return address loaded into register (ldiu *-fp(1), r1), local frame return address de-allocated from stack (step restored (ldiu *fp, fp). delayed branch return address already been performed.) program control then passed back caller function. returned value _func stored local frame (sti r0,*+fp(1)). local variable computed according code before being stored local frame (sti *+fp(2)). arguments that were passed through stack (step de-allocated. core loop (for (;;)) been executed program branches delayed next iteration (bud L2), which will same way. this example loop infinite therefore main routine will never exit. following table shows that stack evolution been recapitulated with filling stack left side release data right side: Interface Assembly Language with TMS320 Floating Point Compiler Stack (Top) Stack Call Step Call Step Return Stack Return Free Free Free Free Automatic variable allocated (local frame) Save entry been done called function Function _func called therefore return address automatically saved stack CALL Argument passed stack Argument passed stack Automatic variable allocated (local frame) Automatic variable allocated (local frame) Save entry been done called function Automatically save stack CALL _main instruction boot routine Last occupied stack location before entering Stack (bottom) This caller function responsibility This called function responsibility Ffunction _func returned therefore local frame (_x) released Function _func returned therefore released Function _func returned therefore return address caller released Argument that passed popped from stack Argument that passed popped from stack save Return address caller save Return address boot routine Came back context Register Argument Runtime Model register argument runtime model, compiler uses dedicated registers pass arguments called function. arguments within dedicated register because type incompatibility number registers been exhausted, remaining arguments pushed onto stack following stack argument runtime model convention discussed previous section. Interface Assembly Language with TMS320 Floating Point Compiler registers used pass arguments are: ar2, first pass, allocated floating-point numbers argument list starting from left. second pass, integer pointer type arguments allocated remaining registers left-to-right manner. exception these rules ellipsis declaration, such example function table below, where number arguments fixed declaration therefore number passed arguments must equal exceed number function parameters. Here last explicitly declared argument passed stack that stack address acts reference accessing possible other arguments. examples below describe allocation parameters function calls: allocation type float arguments integer arguments remaining arguments global allocation function definition f0(int pass pass left right Stack Stack Stack Stack pass left right pass right left final f1(int float struct float float arguments integer arguments remaining arguments global allocation Stack Stack pass left right pass left right pass right left final f2(float float float float arguments integer arguments remaining arguments global allocation Stack Stack pass left right pass left right pass right left final f3(struct d,.); float arguments integer arguments remaining arguments global allocation Stack Stack Stack Stack pass left right pass left right pass right left final following example uses assembly interface. main program calls function that calculates figures from This function coded assembly language assumes that register argument runtime model access arguments. program named example1.c assembly program called sum.asm. command line compiler must cl30 example1.c sum.asm option introduces usage register argument runtime model. code below, function defined external. From that reference will solved link time. exit() function used return caller main function, which boot routine. Interface Assembly Language with TMS320 Floating Point Compiler Example1.c program: extern s(int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8,int a9); description function coded language s(int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8,int a9); s(int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8,int main() sum; exit(0); assembly-coded version described below. defined coherency with convention. function referenced through because compiler appends underscore beginning identifiers. global definition defines symbol external allows linker resolve references first arguments assigned registers used pass arguments (ar2, re). remaining arguments pushed reverse order onto stack following stack argument runtime convention. These actions executed caller. called function only preserve frame pointer initialize access arguments that have been stacked. After computation been done, function must restore environment return result caller. sum.asm example: .set .globl ;>>>> FUNCTION PUSH SP,FP assigned parameter assigned parameter assigned parameter assigned parameter assigned parameter assigned parameter ;>>>> ADDI R2,AR2,R0 ;R0=a0+a1 ADDI R3,R0 ;R0+=a2 ADDI RC,R0 ;R0+=a3 ADDI RS,R0 ;R0+=a4 ADDI *-FP(2),R0 ;R0+=a6 ADDI *-FP(3),R0 ;R0+=a7 ADDI *-FP(4),R0 ;R0+=a8 ADDI *-FP(5),R0 ;R0+=a9 *-FP(1),R1 ;branch delay return address *FP,FP take benefit branch delay restore Interface Assembly Language with TMS320 Floating Point Compiler ADDI SUBI RE,R0 2,SP take benefit branch delay perform last store returned result into R0+=a5 de-allocates location return address caller sequence generated compiler will look follows: local frame management local variables ;>>>> ldiu push ldiu push ldiu push ldiu ldiu ldiu ldiu ldiu ldiu ldiu call ir0,r0 *+fp(9),r0 *+fp(8),r0 *+fp(7),r0 *+fp(1),ar2 *+fp(6),re *+fp(4),rc *+fp(5),rs *+fp(2),r2 *+fp(3),r3 Call Occurs load from temporary register push this sequence might optimized with load into push pass first arguments through registers following rules discussed this paragraph load remaining parameters appropriate registers function used argument function, such quick-sort algorithm: void qsort(void *v[], left, right, (*comp)(void void *)); address function will passed accordingly just another pointer type argument. Naturally calling called function must compiled with same argument runtime model well with same memory model. assembly code, this reflected using conditional programming with predefined symbols, .REGPARM (==1 indicates register argument runtime model) BIGMODEL (==1 indicates usage memory model). Return Function return value function scalar type data like integer value, pointer, floating-point number, will placed register This demonstrated sample file example0.c previously. register-argument runtime model used, pointer will returned register. return value structure, memory space allocated heap structure copied this memory space. address this structure then passed register. Interface Assembly Language with TMS320 Floating Point Compiler References B.W. Kernighan, D.M. Ritchie: Programming Language; Prentice Hall 1988 TMS320C3x User's Guide; Texas Instruments 1997 TMS320C3x/C4x Optimizing Compiler User's Guide; Texas Instruments 1997 INTERNET www.ti.com Register with TI&ME build custom information pages receive product updates automatically email. Semiconductor Home Page http://www.ti.com/sc Distributors PRODUCT INFORMATION CENTERS Europe, Middle East, Africa Phone Deutsch +49-(0) 8161 3311 English +44-(0) 1604 3399 Francais +33-(0) 1-30 Italiano +33-(0) 1-30 +33-(0) 1-30-70 Email epic@ti.com Japan Phone International Domestic International Domestic Email Asia Phone International Domestic Australia TMS320 Hotline email Americas Phone Email +81-3-3457-0972 +0120-81-0026 +81-3-3457-1259 +0120-81-0036 pic-japan@ti.com (281) 274-2320 (281) 274-2324 (281) 274-2323 dsph@ti.com +1(972) 644-5580 +1(972) 480-7800 sc-infomaster@ti.com +886-2-3786800 1-800-881-011 Asia (continued) Number China Number Hong Kong Number India Number Indonesia Number Korea Malaysia Number Zealand Number Philippines Number Singapore Number Taiwan Thailand Number -800-800-1450 10811 -800-800-1450 800-96-1111 -800-800-1450 000-117 -800-800-1450 001-801-10 -800-800-1450 080-551-2804 1-800-800-011 -800-800-1450 +000-911 -800-800-1450 105-11 -800-800-1450 800-0111-111 -800-800-1450 080-006800 0019-991-1111 -800-800-1450 Texas Instruments (TI) reserves right make changes products discontinue semiconductor product service without notice, advises customers obtain latest version relevant information verify, before placing orders, that information being relied current complete. warrants performance semiconductor products related software specifications applicable time sale accordance with TI's standard warranty. Testing other quality control techniques utilized extent deems necessary support this warranty. Specific testing parameters each device necessarily performed, except those mandated government requirements. Certain application using semiconductor products involve potential risks death, personal injury, severe property environmental damage ("Critical Applications"). SEMICONDUCTOR PRODUCTS DESIGNED, INTENDED, AUTHORIZED, WARRANTED SUITABLE LIFE-SUPPORT APPLICATIONS, DEVICES SYSTEMS OTHER CRITICAL APPLICATIONS. Inclusion products such applications understood fully risk customer. products such applications requires written approval appropriate officer. Questions concerning potential risk applications should directed through local sales office. order minimize risks associated with customer's applications, adequate design operating safeguards should provided customer minimize inherent procedural hazards. assumes liability applications assistance, customer product design, software performance, infringement patents services described herein. does warrant represent that license, either express implied, granted under patent right, copyright, mask work right, other intellectual property right covering relating combination, machine, process which such semiconductor products services might used. Copyright 1998, Texas Instruments Incorporated trademark Texas Instruments Incorporated. Other brands names property their respective owners. IMPORTANT NOTICE Interface Assembly Language with TMS320 Floating Point Compiler Other recent searchesSF868M35 - SF868M35 SF868M35 Datasheet PS022509-0305 - PS022509-0305 PS022509-0305 Datasheet FTR-1519-V2 - FTR-1519-V2 FTR-1519-V2 Datasheet FDS6690A - FDS6690A FDS6690A Datasheet ENA0480 - ENA0480 ENA0480 Datasheet FSS173 - FSS173 FSS173 Datasheet EL7232C - EL7232C EL7232C Datasheet 1N5400G - 1N5400G 1N5400G Datasheet 1N5408G - 1N5408G 1N5408G Datasheet
Privacy Policy | Disclaimer |