2.2. Sections

Assembled code is broken into logical sections that are used in different ways. The bits that represent instructions must be executable but should generally not be writable. The bits that represent data should be readable and writable but may not make sense to execute.

Some common sections:

Directives are used to specify what section various parts of an assembly program belong to:

.section       .data
myGlobal:      .word   0xC

.section       .rodata
MY_CONSTANT:   .word   0x64

.section       .bss
uninitializedGlobal:   .space  4

.text
.global _start
_start:
@Do nothing...
MOV   r1, #0

end:  b end       @stop program
Try sample

That code gets build into what is shown below. Some things to note:

../_images/sections.png

Note

Most of the time, this tutorial will stick to using just using .data for all data and .text for the code. We will generally not use .rodata or .bss.

You have attempted of activities on this page
Next Section - 2.3. Data & Alignment