How can I declare a zero initialized vector in Assembly AT&T in the .bss section?

360 Views Asked by At

I would like to declare a vector in the .bss segment, but I am not sure how to do so. I would like the vector to have 30000 bytes.

I have tried to compile some C code into assembly, but I don't quite understand how the generated code works, the result is:

.bss
.align 32
.type   v, @object
.size   v, 2000
v:
    .zero   2000
    .section    .rodata

I do not really understand all the instructions.

1

There are 1 best solutions below

1
Özgür Güzeldereli On
.bss
.align 32
.type   v, @object
.size   v, 2000
v:
    .zero   2000
    .section    .rodata

.bss declares that the following statements will describe a part of the bss section.

.align 32 declares that this address should be aligned to 32 bytes. This is done to structure the RAM properly and prevent some misalignment issues.

.type   v, @object
.size   v, 2000

These declare the size and type of v object. The size is declared as 2000.

v:
    .zero   2000

this is the actual allocation of space. .zero 2000 allocates 2000 bytes of zeroed memory which is pointed by the v label.

By these you can do something like:

.bss
abc:
    .zero 30000

to allocate 30000 bytes in the most basic way.