Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


What is basic syntax in Assembly?

Rukhshan Haroon

Any program written in assembly language is made up of three sections:

  • Data Section
  • BSS Section
  • Text Section

In this shot, we shall discuss the syntax and role of each of these three sections one by one.

Data Section

The 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

The 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

The 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:

   global _start

The declaration of global_start indicates to the kernel where program execution begins.

Assembly Language Instructions

The syntax of an assembly language instruction comprises of two major components:

  • Instruction Name
  • Instruction Parameters

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

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 db directive.

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!




Rukhshan Haroon
Copyright ©2022 Educative, Inc. All rights reserved

View all Courses

Keep Exploring