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:
[code].model small
.stack 100h
.data
.code
main proc
end main
[/code]
The usage of each segment is described below:
[thrive_headline_focus title=”.Model” orientation=”left”].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)
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.
[thrive_headline_focus title=”.Data” orientation=”left”]In Data segment, all the variables are declared or initialized. For example:
[code].DATA
WORDl DW2
WORD2 DW7
MSG DB ‘THIS IS A MESSAGE’
[/code] [thrive_headline_focus title=”.Code” orientation=”left”]The Code segment, contain program instructions. In the above example, we have a main procedure in the .code section.
[thrive_headline_focus title=”Main Proc” orientation=”left”]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:
[code]main endpend main[/code]
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.