Basic Structure
Last updated
Last updated
best cross-platform IDE for assembly is SASM which supports multiple assemblers and is available for linux, windows and mac. you can find it here:
if you are on linux, install it with your package manager:
the process of assembling, linking and loading an assembly program is like this:
The following are the main parts of an assembly program:
section .data
section .bss
section .text
you can tell that this structure is related to the program execution stack in memory. so data section is for initialized variables, bss section is for uninitialized variables and text section is the program instructions.
section .data - In section .data , initialized data is declared and defined, in the following format:
section .data can also contain constants, which are values that cannot be changed in the program. They are declared in the following format:
section .bss - The acronym bss stands for Block Started by Symbol , and its history goes back to the fifties, when it was part of assembly language developed for the IBM 704. In this section go the uninitialized variables. Space for uninitialized variables is declared in this section, in the following format:
section .text - this is the actual instructions of the program where the functions (including main ) are declared and defined. it should always start with an entry point which is defined right after the section .text definition like this:
in NASM, you can use the keywords 'segment' and 'section' interchangeably. so section .text can be segment .text
here is a basic example of an assembly code with the 3 sections we talked about:
you can compile and run this program with:
for the rest of this section we are going to use these commands to compile and run our x86 programs, remember that the syntax is different for x64.
in all assemblers the single-line comment sign is a semicolon.