Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!apple!netcomsv!mcmahan From: mcmahan@netcom.COM (Dave Mc Mahan) Newsgroups: comp.dsp Subject: Re: bit reversal of a C array in '30 code Message-ID: <1991Jun26.052754.5772@netcom.COM> Date: 26 Jun 91 05:27:54 GMT References: <1991Jun25.082320.599@otago.ac.nz> Organization: Dave McMahan @ NetCom Services Lines: 58 In a previous article, psyxsgp@otago.ac.nz writes: >Hi, > Could anyone tell us how to zero align an array >generated in C, but calling an assembler routine in >tms320c30 code which does bit reversal. One way to long word-align an array is to put it in a seperate segment, and then ensure that the segement starts on the proper boundry. Failing that, you can do it at run-time. The code isn't pretty, but it does work. The trick to this is to declare an array that is 4 bytes larger than you really need. You then set a pointer to the first location in the array, add 4 to the pointer, and then logically AND the pointer with ~(3) to force it to contain a value that MUST fall on the proper boundry. This gets a little messy if you have strict type-checking, but fortunately 'C' doesn't do that. The code might be something like this: #define MYSIZE 100 /* Size in bytes you want, not size of longwords you will eventually use. */ static char dumb_array[MYSIZE+4]; long *ptr_to_use; main() { /* Notice the use of casting to prevent the compiler from complaining about the fast-and-loose type conversions. */ ptr_to_use = (long *)(&dumb_array[4]); ptr_to_use = (long *)((long)ptr_to_use & ~3L); ptr_to_use[0] = 6; ptr_to_use[24] = 9943; /* This is the last element of the array that you can safely use. Anything bigger may fall outside the declared array. */ } Caveat: I haven't compiled this example, but it should work. I have used this technique before when I had to force alignment within my data and couldn't get the compiler to do it for me. >Stephen Pearce -dave -- Dave McMahan mcmahan@netcom.com {apple,amdahl,claris}!netcom!mcmahan