0

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.

  • Which instructions do you not understand in particular? – fuz Oct 17 '22 at 08:10
  • Near duplicate of [Confusion about the many ways of saving variables in assembly, aka .skip .equ and .quad](https://stackoverflow.com/q/73672672) / [Writing large arrays to memory x86 assembly - segfaults using stack space](https://stackoverflow.com/q/68440668) / [resd instruction in AT&T syntax](https://stackoverflow.com/q/60840759) / [assembly: uses storage in the .bss section rather than the #stack to store the file descriptors (exercise question)](https://stackoverflow.com/q/55930771) – Peter Cordes Oct 17 '22 at 11:07

1 Answers1

1
.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.

  • 1
    *`.bss` declares the **beginning** of bss section.* No, it just switches to the current position in that section. You can switch sections as many times as you want, reserving BSS bytes or emitting bytes in other sections, and it doesn't rewind to the beginning of BSS every time you do. `.bss` ; `.zero 100` will be *after* whatever was last, not overlapping. – Peter Cordes Oct 17 '22 at 10:56