Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array not crossing 256 byte boundary

Is it possible to create an array that doesn't cross 256 byte boundary? That is addresses of the individual array items only differ in the lower byte. This is weaker requirement than keeping the array aligned to 256 bytes. The only solution I could think of was aligning to next_power_of_two(sizeof(array)), but I'm not sure about the gaps that would appear this way.

It is for a library for AVR microcontrollers, and this would save me a few precious instructions in an interrupt handler.The array that should have this property is 54 byte long out of about 80 bytes of total static memory used by the library. I'm looking for a way that doesn't increase the memory requirements.

I'm using avr-as gnu assembler and avr-ld linker.

Example:If the array starts at address 0x00f0, then the higher word will change from 0x00 to 0x01 while traversing the array.

I don't really care whether it starts at address 0x0100 or 0x0101 as long as it doesn't cross the boundary.

like image 227
cube Avatar asked Nov 14 '22 06:11

cube


1 Answers

You only need 64 byte alignment to meet this requirement, so e.g. this should work:

uint8_t a[54] __attribute__ ((aligned(64)));
like image 186
Paul R Avatar answered Dec 28 '22 13:12

Paul R