x86 Assembly Language Syntax

x86 Assembly Language Syntax is a little bit different from MIPS and ARM instruction set. It basically consists of four segments. A basic x86 assembly program syntax is given below:

.model small
.stack 100h
.data
.code
main proc
end main
 

The usage of each segment is described below:

.Model define the size of data and code a program can have. In the above example, we have use .model small which means we will be having one segment of code and one segment of data. some other model directives are:

 

  • Medium        # more than one code and one data segment
  • Compact       # one code and more than one data segment
  • Large             # more than one code and data segment (Array not greater than 64k bytes)
  • Huge              # more than one code and data segment (Array can be greater than 64k bytes)

.Stack

In Stack segment, we set aside a block of memory to store stack. Its size is considered in kb. In the above example, we have given the size of 100h which means 1kb.

.Data

In Data segment, all the variables are declared or initialized. For example:

.DATA
WORDl              DW2
WORD2             DW7
MSG                   DB 'THIS IS A MESSAGE'

.Code

The Code segment, contain program instructions. In the above example, we have a main procedure in the .code section.

Main Proc

Proc stands for “procedure” so main proc means main procedure. Here we will write our further instruction and the we will end our main proc with following statements:

main endp
end main

 

Hope the above tutorial helped you understand the basic syntax of x86 instruction set. If you have any problem let us know in the comment box.

Nauman Rehmat
 

Nauman Rehmat is the owner of Assembly Language Tuts.He is interested in Programming and SEO. He is also pursuing a degree in Computer Software Engineering from Comsats.