Any program written in assembly language is made up of three sections:
In this shot, we shall discuss the syntax and role of each of these three sections one by one.
data section aims to store constants or other information that is supposed to be initialized at the program’s start. Any variables declared in the data section are not permitted to change at run-time. Constants such as file names and buffer sizes are typically stored in the data section.
The syntax for initializing the data section is as follows:
BSS section is where all variables are stored. Typically, global and static variables are stored in the
BSS section and are either uninitialized in source code or initialized to zero.
The syntax to initialize the
BSS section is as follows:
text section is where the source code is stored. Information present in the
text section may include assembly language instructions and assembler directives, which we will look into below.
The syntax for initializing the
text segment is as follows:
section.text global _start _start:
The declaration of
global_startindicates to the kernel where program execution begins.
The syntax of an assembly language instruction comprises of two major components:
In the assembly language instruction below, mov is the instruction name and value and 8 are the instruction parameters, also known as operands. The instruction moves 8 into the variable named var; in other words, the value of var changes to 8!
mov value, 8
Assembly directives are used to administer the assembly process. For instance, the directive
db stands for defined bytes and may allocate space for data initialization. Other uses of assembly directives include but are not limited to specifying libraries to extract macros from, assembling control blocks, and analyzing debugging data.
The following code snippet shows how we may allocate space in an assembly language program to store a string to a variable named message using the
section .data message db 'Welcome to Educative!', 0xa
Comments in assembly language can be marked by putting
; before their beginning.
The snippet below demonstrates how to add comments to assembly code:
mov value,8 ;I'm a comment!
View all Courses