I have two assembly files, a.s and b.s I want to combine both of them and create a new assembly file c.s The file c.s should have all the code in .text of a.s and then all then code in .text of b.s I want to do the same thing with .data section
# File a.s
VSUB.F32 S4, S5, S6
.data
.word 0x10000000
# File b.s
VADD.F32 S4, S5, S6
.data
.word 0x20000000
# File c.s
.include "a.s"
.include "b.s"
I want my output to look like this:
.text
VSUB.F32 S4, S5, S6
VADD.F32 S4, S5, S6
.data
.word 0x10000000
.word 0x20000000
However, this is what I see after dumping the object file.
Disassembly of section .text:
00000000 <.text>:
0: ee322ac3 vsub.f32 s4, s5, s6
00000000 <.data>:
0: 10000000 .word 0x10000000
4: ee710a21 vadd.f32 s1, s2, s3
8: 20000000 .word 0x20000000
thats exactly what a linker does what is the problem?
a.s
add r0,r0,r0
.data
aaa: .word 0xAAAAAAAA
b.s
add r1,r1,r1
.data
bbbb: .word 0xBBBBBBBB
build:
arm-none-eabi-as a.s -o a.o
arm-none-eabi-as b.s -o b.o
arm-none-eabi-ld -Ttext=0x1000 -Tdata=0x2000 a.o b.o -o ab.elf
arm-none-eabi-ld: warning: cannot find entry symbol _start; defaulting to 0000000000001000
disassemble:
arm-none-eabi-objdump -D ab.elf
Disassembly of section .text:
00001000 <.text>:
1000: e0800000 add r0, r0, r0
1004: e0811001 add r1, r1, r1
Disassembly of section .data:
00002000 <__data_start>:
2000: aaaaaaaa bge feaacab0 <_stack+0xfea2cab0>
00002004 <bbbb>:
2004: bbbbbbbb bllt feef0ef8 <_stack+0xfee70ef8>
completely useless code but its that simple. You can then complicate it more by using a linker script, etc.
Naturally the code needs to make sense it wants to branch or call functions locally or in other objects with a sane flow. But it is easy to see with this example that the linker simply put the .text sections together and the .data sections together.
Unless dictated by a linker script the order they land in the output so far as I have seen is determined by the order found on the linker command line.
Add .text
to the beginning of each file.
The assembler starts with the section set to .text
. However, when you use .include
, it is in the context of the including file (c.s in your case) which has the section set to .data
from the previous include.
Theoretically, you only have to add a .text
to the top of the b.s source, but it is always good practice to just always use a .text
declaration at the start of your asembler file. You might like .unified
, .thumb
, etc.
It is true that a linker will solve this issue, but a common practical case is mixing generated assembler with custom code. Generally, you just need driver.s to include generated.s and don't need the third file. The generated file is typical a table or data structure from another source such as 'C' structure offsets, conversion constants, etc.
User contributions licensed under CC BY-SA 3.0