Search code examples
assemblymemory-alignmentbinutils

'AS' align plus incbin is not producing the expected alignment


I'm having problem at making my personal project work on real hardware due to data alignment problems; due to the way the hardware works, the images must by 16-bit aligned.

I have tried to specify the alignment through the '.align' directive:

.text
.align 2

.globl _vg_lecturehall
.globl _vg_sylvie_giggle
.globl _vg_club

_vg_lecturehall:
.align 2
.incbin "build/lecturehall.apg"

_vg_sylvie_giggle:
.align 2
.incbin "build/sylvie_giggle.apg"

_vg_club:
.align 2
.incbin "build/club.apg"

But, as can be seem by the memory map, the data is still placed at odd addresses:

 .text          0x000000000200aa00    0x12aac build/generated_images.o
                0x000000000200aa00                _vg_lecturehall
                0x0000000002012d11                _vg_sylvie_giggle
                0x0000000002014f2b                _vg_club

Does anyone have any idea of what is being done wrong? Is there a way to ensure that a included binary is positioned at an even address?


Solution

  • You are placing your labels BEFORE the .align directives. At that point, there is no particular alignment in effect - it will depend on whether the preceding .incbin generated an odd or an even number of bytes. Move the labels down one line, so that you are actually labeling the included data.