ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Вторник
9 июля
267360 Топик полностью
мохоноги (16.08.2011 20:20 - 21.08.2011 00:43, просмотров: 129) ответил SciFi на У меня было последствие: ф-ция printf() неправильно выводила float, когда указатель стека при её вызове не был кратен 8. Но это было на ARM7TDMI.
Нашёл тред в почтовой рассылке CodeSourcery о сходной проблеме (sprintf, float, указатель стека не кратен 8) с Cortex-M3. Запомню. http://www.codesourcery.com/archives/arm-gnu/msg03115.html
Краткая выдержка из треда: [arm-gnu] sprintf issue on Cortex-M3
we are using arm-none-eabi-gcc (Sourcery G++ Lite 2009q3-68) 4.4.1. Formatting a floating point number with sprintf does not seem to work: char b[20]; float temperature = 0.4f; sprintf(b, "%6.1f ", temperature); prints " -0.0" into the buffer.
I remember hearing that later ARMs got really picky about keeping the stack aligned, and that failure to do so would cause weird problems with 64-bit vars (like doubles) - especially with odd call chains and interrupts.
I've just checked, and in both cases the stack is at least word aligned (without --gc-sections [when sprintf fails] it is even quad-word aligned), so I don't think that's the issue here.
According to ARM AAPCS: "5.2.1.2 Stack constraints at a public interface The stack must also conform to the following constraint at a public interface: SP mod 8 = 0. The stack must be double-word aligned."
OK - aligning the stack to 8bytes fixed the issue.