www.ti.com
2.4ProgramMemory
2.5ROM-ability
ProgramMemory
Likethedatamemoryrequirementsdescribedintheprevioussection,itisimportantthatall
eXpressDSP-compliantalgorithmsarefullyrelocatable;i.e.,thereshouldneverbeanyassumptionabout
thespecificplacementofanalgorithmataparticularaddress.Alignmentonaspecifiedpagesizeis
permitted,however.
Rule4
Allalgorithmcodemustbefullyrelocatable.Thatis,therecanbenohardcodedprogrammemory
locations.
Aswiththedatamemoryrequirements,thisruleonlyrequiresthatCodeberelocatedviaalinker.For
example,itisnotnecessarytoalwaysusePC-relativebranches.Thisrequirementallowsthesystem
developertooptimallyallocateprogramspacetothevariousalgorithmsinthesystem.
AlgorithmmodulessometimesrequireinitializationCodethatmustbeexecutedpriortoanyother
algorithmmethodbeingusedbyaclient.OftenthisCodeisonlyrunonceduringthelifetimeofan
application.ThisCodeiseffectively"dead"onceithasbeenrunatstartup.Thespaceallocatedforthis
Codecanbereusedinmanysystemsbyplacingthe"run-once"Codeindatamemoryandusingthedata
memoryduringalgorithmoperation.
Asimilarsituationoccursin"finalization"Code.Debugversionsofalgorithms,forexample,sometimes
implementfunctionsthat,whencalledwhenasystemexits,canprovidevaluabledebuginformation;e.g.,
theexistenceofobjectsorobjectsthathavenotbeenproperlydeleted.Sincemanysystemsaredesigned
toneverexit(i.e.,exitbypower-off),finalizationCodeshouldbeplacedinaseparateobjectmodule.This
allowsthesystemintegratortoavoidincludingCodethatcanneverbeexecuted.
Guideline2
Eachinitializationandfinalizationfunctionshouldbedefinedinaseparateobjectmodule;these
modulesmustnotcontainanyothercode.
Insomecases,itisawkwardtoplaceeachfunctioninaseparatefile.Doingsomayrequiremakingsome
identifiersgloballyvisibleorrequiresignificantchangestoanexistingCodebase.TheTICcompiler
supportsapragmadirectivethatallowsyoutoplacespecifiedfunctionsindistinctCOFFoutputsections.
Thispragmadirectivemaybeusedinlieuofplacingfunctionsinseparatefiles.Thetablebelow
summarizesrecommendedsectionnamesandtheirpurpose.
SectionNamePurpose
.text:initRun-onceinitializationcode
.text:exitRun-oncefinalizationcode
.text:createRun-timeobjectcreation
.text:deleteRun-timeobjectdeletion
Thereareseveraladdressingmodesusedbyalgorithmstoaccessdatamemory.Sometimesthedatais
referencedbyapointertoabufferpassedtothealgorithm,andsometimesanalgorithmsimplyreferences
globalvariablesdirectly.Whenanalgorithmreferencesglobaldatadirectly,theinstructionthatoperates
onthedataoftencontainstheaddressofthedata(ratherthananoffsetfromadatapageregister,for
example).Thus,thisCodecannotbeplacedinROMwithoutalsorequiringthatthereferenceddatabe
placedinafixedlocationinasystem.Ifamodulehasconfigurationparametersthatresultinvariable
lengthdatastructuresandthesestructuresaredirectlyreferenced,suchCodeisnotconsidered
ROM-able;theoffsetsintheCodearefixedandtherelativepositionsofthedatareferencesmaychange.
Alternatively,algorithmCodecanbestructuredtoalwaysuseoffsetsfromadatapageforallfixedlength
referencesandplaceapointerinthispagetoanyvariablelengthstructures.Inthiscase,itispossibleto
configureandlocatethedataanywhereinthesystem,providedthedatapageisappropriatelyset.
SPRU352G–June2005–RevisedFebruary2007GeneralProgrammingGuidelines23
SubmitDocumentationFeedback