SlideShare a Scribd company logo
http://www.tutorialspoint.com/assembly_prog ramming /assembly_basic_syntax.htm Copyright © tutorialspoint.com
ASSEMBLY - BASIC SYNTAX
Anassembly programcanbe divided into three sections:
The data section
The bss section
The text section
The data Section
The data sectionis used for declaring initialized data or constants. This data does not change at runtime. Youcan
declare various constant values, file names or buffer size, etc., inthis section.
The syntax for declaring data sectionis:
section .data
The bss Section
The bss sectionis used for declaring variables. The syntax for declaring bss sectionis:
section .bss
The text section
The text sectionis used for keeping the actualcode. This sectionmust beginwiththe declarationglobal
_start, whichtells the kernelwhere the programexecutionbegins.
The syntax for declaring text sectionis:
section .text
global _start
_start:
Comments
Assembly language comment begins witha semicolon(;). It may containany printable character including blank. It
canappear ona line by itself, like:
; This program displays a message on screen
or, onthe same line along withaninstruction, like:
add eax ,ebx ; adds ebx to eax
Assembly Language Statements
Assembly language programs consist of three types of statements:
Executable instructions or instructions
Assembler directives or pseudo-ops
Macros
The executable instructions or simply instructions tellthe processor what to do. Eachinstruction
consists of anoperation code (opcode). Eachexecutable instructiongenerates one machine language
instruction.
The assembler directives or pseudo-ops tellthe assembler about the various aspects of the assembly
process. These are non-executable and do not generate machine language instructions.
Macros are basically a text substitutionmechanism.
Syntax of Assembly Language Statements
Assembly language statements are entered one statement per line. Eachstatement follows the following format:
[label] mnemonic [operands] [;comment]
The fields inthe square brackets are optional. A basic instructionhas two parts, the first one is the name of the
instruction(or the mnemonic), whichis to be executed, and the second are the operands or the parameters of the
command.
Following are some examples of typicalassembly language statements:
INC COUNT ; Increment the memory variable COUNT
MOV TOTAL, 48 ; Transfer the value 48 in the
; memory variable TOTAL
ADD AH, BH ; Add the content of the
; BH register into the AH register
AND MASK1, 128 ; Perform AND operation on the
; variable MASK1 and 128
ADD MARKS, 10 ; Add 10 to the variable MARKS
MOV AL, 10 ; Transfer the value 10 to the AL register
The Hello World Program in Assembly
The following assembly language code displays the string 'Hello World' onthe screen:
section .text
global _start ;must be declared for linker (ld)
_start: ;tells linker entry point
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
msg db 'Hello, world!', 0xa ;our dear string
len equ $ - msg ;length of our dear string
Whenthe above code is compiled and executed, it produces the following result:
Hello, world!
Compiling and Linking an Assembly Program in NASM
Make sure youhave set the pathof nasmand ld binaries inyour PATH environment variable. Now, take the
following steps for compiling and linking the above program:
Type the above code using a text editor and save it as hello.asm.
Make sure that youare inthe same directory as where yousaved hello.asm.
To assemble the program, type nasm -f elf hello.asm
If there is any error, youwillbe prompted about that at this stage. Otherwise, anobject file of your
programnamed hello.o willbe created.
To link the object file and create anexecutable file named hello, type ld -m elf_i386 -s -o hello
hello.o
Execute the programby typing ./hello
If youhave done everything correctly, it willdisplay Hello, world! onthe screen.

More Related Content

What's hot

Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
nTier Custom Solutions
 
QBASIC
QBASICQBASIC
QBASIC
nivi88
 
Programming Fundamentals and Programming Languages Concepts Translators
Programming Fundamentals and Programming Languages Concepts TranslatorsProgramming Fundamentals and Programming Languages Concepts Translators
Programming Fundamentals and Programming Languages Concepts Translators
imtiazalijoono
 
Chapter 3(1)
Chapter 3(1)Chapter 3(1)
Chapter 3(1)
TejaswiB4
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
Akshay Ithape
 
Writing command macro in stratus cobol
Writing command macro in stratus cobolWriting command macro in stratus cobol
Writing command macro in stratus cobol
Srinimf-Slides
 
C Language
C LanguageC Language
C Language
Aakash Singh
 
An Overview of Programming C
An Overview of Programming CAn Overview of Programming C
An Overview of Programming C
Nishargo Nigar
 
Chapter 2(1)
Chapter 2(1)Chapter 2(1)
Chapter 2(1)
TejaswiB4
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
marvellous2
 
C introduction
C introductionC introduction
C introduction
Kamran
 
Single Pass Assembler
Single Pass AssemblerSingle Pass Assembler
Single Pass Assembler
Satyamevjayte Haxor
 
Unit 2 introduction to c programming
Unit 2   introduction to c programmingUnit 2   introduction to c programming
Unit 2 introduction to c programming
Mithun DSouza
 
Plsql overview
Plsql overviewPlsql overview
Plsql overview
Gagan Deep
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming Language
Prof Ansari
 
INTRODUCCIÓN A LA PROGRAMACIÓN
INTRODUCCIÓN A LA PROGRAMACIÓNINTRODUCCIÓN A LA PROGRAMACIÓN
INTRODUCCIÓN A LA PROGRAMACIÓN
BenjaminAnilema
 
First pass of assembler
First pass of assemblerFirst pass of assembler
First pass of assembler
Hemant Chetwani
 

What's hot (17)

Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
QBASIC
QBASICQBASIC
QBASIC
 
Programming Fundamentals and Programming Languages Concepts Translators
Programming Fundamentals and Programming Languages Concepts TranslatorsProgramming Fundamentals and Programming Languages Concepts Translators
Programming Fundamentals and Programming Languages Concepts Translators
 
Chapter 3(1)
Chapter 3(1)Chapter 3(1)
Chapter 3(1)
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Writing command macro in stratus cobol
Writing command macro in stratus cobolWriting command macro in stratus cobol
Writing command macro in stratus cobol
 
C Language
C LanguageC Language
C Language
 
An Overview of Programming C
An Overview of Programming CAn Overview of Programming C
An Overview of Programming C
 
Chapter 2(1)
Chapter 2(1)Chapter 2(1)
Chapter 2(1)
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
C introduction
C introductionC introduction
C introduction
 
Single Pass Assembler
Single Pass AssemblerSingle Pass Assembler
Single Pass Assembler
 
Unit 2 introduction to c programming
Unit 2   introduction to c programmingUnit 2   introduction to c programming
Unit 2 introduction to c programming
 
Plsql overview
Plsql overviewPlsql overview
Plsql overview
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming Language
 
INTRODUCCIÓN A LA PROGRAMACIÓN
INTRODUCCIÓN A LA PROGRAMACIÓNINTRODUCCIÓN A LA PROGRAMACIÓN
INTRODUCCIÓN A LA PROGRAMACIÓN
 
First pass of assembler
First pass of assemblerFirst pass of assembler
First pass of assembler
 

Similar to N_Asm Assembly basic syntax (sol)

Introduction to Assembly Language Programming
Introduction to Assembly Language ProgrammingIntroduction to Assembly Language Programming
Introduction to Assembly Language Programming
Rahul P
 
ASSEMBLY LANGUAGE.pptx
ASSEMBLY LANGUAGE.pptxASSEMBLY LANGUAGE.pptx
ASSEMBLY LANGUAGE.pptx
EdFeranil
 
Lec 04 intro assembly
Lec 04 intro assemblyLec 04 intro assembly
Lec 04 intro assembly
Abdul Khan
 
Mp lab manual
Mp lab manualMp lab manual
Mp lab manual
Pradeep Kumar
 
Assembly level language
Assembly level languageAssembly level language
Assembly level language
PDFSHARE
 
Chapter 2 programming concepts - I
Chapter 2  programming concepts - IChapter 2  programming concepts - I
Chapter 2 programming concepts - I
SHREEHARI WADAWADAGI
 
1 Describe different types of Assemblers.Assembly language.docx
 1 Describe different types of Assemblers.Assembly language.docx 1 Describe different types of Assemblers.Assembly language.docx
1 Describe different types of Assemblers.Assembly language.docx
aryan532920
 
Alp 05
Alp 05Alp 05
Alp 05
Jaimon Jacob
 
Basics1
Basics1Basics1
Basics1
phanleson
 
1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf
SemsemSameer1
 
Assembly language
Assembly languageAssembly language
Assembly language
gaurav jain
 
1. introduction to computer
1. introduction to computer1. introduction to computer
1. introduction to computer
Shankar Gangaju
 
7986-lect 7.pdf
7986-lect 7.pdf7986-lect 7.pdf
7986-lect 7.pdf
RiazAhmad521284
 
intro to assembly language.pptx
intro to assembly language.pptxintro to assembly language.pptx
intro to assembly language.pptx
EdFeranil
 
Unit-2.pptx
Unit-2.pptxUnit-2.pptx
Unit-2.pptx
sidhantkulkarni1
 
Assembly language programming(unit 4)
Assembly language programming(unit 4)Assembly language programming(unit 4)
Assembly language programming(unit 4)
Ashim Saha
 
unit 2.pptx
unit 2.pptxunit 2.pptx
unit 2.pptx
rrbornarecm
 
REXX_ Lab_1 ITT 340 NOTE If you are still a little shaky about.docx
REXX_ Lab_1  ITT 340 NOTE If you are still a little shaky about.docxREXX_ Lab_1  ITT 340 NOTE If you are still a little shaky about.docx
REXX_ Lab_1 ITT 340 NOTE If you are still a little shaky about.docx
joellemurphey
 
cs262_intro_slides.pptx
cs262_intro_slides.pptxcs262_intro_slides.pptx
cs262_intro_slides.pptx
AnaLoreto13
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
Rana Ehtisham Ul Haq
 

Similar to N_Asm Assembly basic syntax (sol) (20)

Introduction to Assembly Language Programming
Introduction to Assembly Language ProgrammingIntroduction to Assembly Language Programming
Introduction to Assembly Language Programming
 
ASSEMBLY LANGUAGE.pptx
ASSEMBLY LANGUAGE.pptxASSEMBLY LANGUAGE.pptx
ASSEMBLY LANGUAGE.pptx
 
Lec 04 intro assembly
Lec 04 intro assemblyLec 04 intro assembly
Lec 04 intro assembly
 
Mp lab manual
Mp lab manualMp lab manual
Mp lab manual
 
Assembly level language
Assembly level languageAssembly level language
Assembly level language
 
Chapter 2 programming concepts - I
Chapter 2  programming concepts - IChapter 2  programming concepts - I
Chapter 2 programming concepts - I
 
1 Describe different types of Assemblers.Assembly language.docx
 1 Describe different types of Assemblers.Assembly language.docx 1 Describe different types of Assemblers.Assembly language.docx
1 Describe different types of Assemblers.Assembly language.docx
 
Alp 05
Alp 05Alp 05
Alp 05
 
Basics1
Basics1Basics1
Basics1
 
1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf
 
Assembly language
Assembly languageAssembly language
Assembly language
 
1. introduction to computer
1. introduction to computer1. introduction to computer
1. introduction to computer
 
7986-lect 7.pdf
7986-lect 7.pdf7986-lect 7.pdf
7986-lect 7.pdf
 
intro to assembly language.pptx
intro to assembly language.pptxintro to assembly language.pptx
intro to assembly language.pptx
 
Unit-2.pptx
Unit-2.pptxUnit-2.pptx
Unit-2.pptx
 
Assembly language programming(unit 4)
Assembly language programming(unit 4)Assembly language programming(unit 4)
Assembly language programming(unit 4)
 
unit 2.pptx
unit 2.pptxunit 2.pptx
unit 2.pptx
 
REXX_ Lab_1 ITT 340 NOTE If you are still a little shaky about.docx
REXX_ Lab_1  ITT 340 NOTE If you are still a little shaky about.docxREXX_ Lab_1  ITT 340 NOTE If you are still a little shaky about.docx
REXX_ Lab_1 ITT 340 NOTE If you are still a little shaky about.docx
 
cs262_intro_slides.pptx
cs262_intro_slides.pptxcs262_intro_slides.pptx
cs262_intro_slides.pptx
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
 

More from Selomon birhane

N_Asm Assembly system calls (sol)
N_Asm Assembly system calls (sol)N_Asm Assembly system calls (sol)
N_Asm Assembly system calls (sol)
Selomon birhane
 
N_Asm Assembly addressing modes (sol)
N_Asm Assembly addressing modes (sol)N_Asm Assembly addressing modes (sol)
N_Asm Assembly addressing modes (sol)
Selomon birhane
 
N_Asm Assembly arrays (sol)
N_Asm Assembly arrays (sol)N_Asm Assembly arrays (sol)
N_Asm Assembly arrays (sol)
Selomon birhane
 
N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)
Selomon birhane
 
N_Asm Assembly recursion (sol)
N_Asm Assembly recursion (sol)N_Asm Assembly recursion (sol)
N_Asm Assembly recursion (sol)
Selomon birhane
 
N_Asm Assembly strings (sol)
N_Asm Assembly strings (sol)N_Asm Assembly strings (sol)
N_Asm Assembly strings (sol)
Selomon birhane
 
N_Asm Assembly numbers (sol)
N_Asm Assembly numbers (sol)N_Asm Assembly numbers (sol)
N_Asm Assembly numbers (sol)
Selomon birhane
 
N_Asm Assembly registers (sol)
N_Asm Assembly registers (sol)N_Asm Assembly registers (sol)
N_Asm Assembly registers (sol)
Selomon birhane
 
N_Asm Assembly variables (sol)
N_Asm Assembly variables (sol)N_Asm Assembly variables (sol)
N_Asm Assembly variables (sol)
Selomon birhane
 
N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)
Selomon birhane
 
Control system(smarajit ghosh) By sol
Control system(smarajit ghosh) By solControl system(smarajit ghosh) By sol
Control system(smarajit ghosh) By sol
Selomon birhane
 
Two ports
Two ports Two ports
Two ports
Selomon birhane
 

More from Selomon birhane (12)

N_Asm Assembly system calls (sol)
N_Asm Assembly system calls (sol)N_Asm Assembly system calls (sol)
N_Asm Assembly system calls (sol)
 
N_Asm Assembly addressing modes (sol)
N_Asm Assembly addressing modes (sol)N_Asm Assembly addressing modes (sol)
N_Asm Assembly addressing modes (sol)
 
N_Asm Assembly arrays (sol)
N_Asm Assembly arrays (sol)N_Asm Assembly arrays (sol)
N_Asm Assembly arrays (sol)
 
N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)
 
N_Asm Assembly recursion (sol)
N_Asm Assembly recursion (sol)N_Asm Assembly recursion (sol)
N_Asm Assembly recursion (sol)
 
N_Asm Assembly strings (sol)
N_Asm Assembly strings (sol)N_Asm Assembly strings (sol)
N_Asm Assembly strings (sol)
 
N_Asm Assembly numbers (sol)
N_Asm Assembly numbers (sol)N_Asm Assembly numbers (sol)
N_Asm Assembly numbers (sol)
 
N_Asm Assembly registers (sol)
N_Asm Assembly registers (sol)N_Asm Assembly registers (sol)
N_Asm Assembly registers (sol)
 
N_Asm Assembly variables (sol)
N_Asm Assembly variables (sol)N_Asm Assembly variables (sol)
N_Asm Assembly variables (sol)
 
N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)
 
Control system(smarajit ghosh) By sol
Control system(smarajit ghosh) By solControl system(smarajit ghosh) By sol
Control system(smarajit ghosh) By sol
 
Two ports
Two ports Two ports
Two ports
 

Recently uploaded

How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Envertis Software Solutions
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Undress Baby
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 

Recently uploaded (20)

How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 

N_Asm Assembly basic syntax (sol)

  • 1. http://www.tutorialspoint.com/assembly_prog ramming /assembly_basic_syntax.htm Copyright © tutorialspoint.com ASSEMBLY - BASIC SYNTAX Anassembly programcanbe divided into three sections: The data section The bss section The text section The data Section The data sectionis used for declaring initialized data or constants. This data does not change at runtime. Youcan declare various constant values, file names or buffer size, etc., inthis section. The syntax for declaring data sectionis: section .data The bss Section The bss sectionis used for declaring variables. The syntax for declaring bss sectionis: section .bss The text section The text sectionis used for keeping the actualcode. This sectionmust beginwiththe declarationglobal _start, whichtells the kernelwhere the programexecutionbegins. The syntax for declaring text sectionis: section .text global _start _start: Comments Assembly language comment begins witha semicolon(;). It may containany printable character including blank. It canappear ona line by itself, like: ; This program displays a message on screen or, onthe same line along withaninstruction, like: add eax ,ebx ; adds ebx to eax Assembly Language Statements Assembly language programs consist of three types of statements: Executable instructions or instructions Assembler directives or pseudo-ops Macros The executable instructions or simply instructions tellthe processor what to do. Eachinstruction consists of anoperation code (opcode). Eachexecutable instructiongenerates one machine language instruction.
  • 2. The assembler directives or pseudo-ops tellthe assembler about the various aspects of the assembly process. These are non-executable and do not generate machine language instructions. Macros are basically a text substitutionmechanism. Syntax of Assembly Language Statements Assembly language statements are entered one statement per line. Eachstatement follows the following format: [label] mnemonic [operands] [;comment] The fields inthe square brackets are optional. A basic instructionhas two parts, the first one is the name of the instruction(or the mnemonic), whichis to be executed, and the second are the operands or the parameters of the command. Following are some examples of typicalassembly language statements: INC COUNT ; Increment the memory variable COUNT MOV TOTAL, 48 ; Transfer the value 48 in the ; memory variable TOTAL ADD AH, BH ; Add the content of the ; BH register into the AH register AND MASK1, 128 ; Perform AND operation on the ; variable MASK1 and 128 ADD MARKS, 10 ; Add 10 to the variable MARKS MOV AL, 10 ; Transfer the value 10 to the AL register The Hello World Program in Assembly The following assembly language code displays the string 'Hello World' onthe screen: section .text global _start ;must be declared for linker (ld) _start: ;tells linker entry point mov edx,len ;message length mov ecx,msg ;message to write mov ebx,1 ;file descriptor (stdout) mov eax,4 ;system call number (sys_write) int 0x80 ;call kernel mov eax,1 ;system call number (sys_exit) int 0x80 ;call kernel section .data msg db 'Hello, world!', 0xa ;our dear string len equ $ - msg ;length of our dear string Whenthe above code is compiled and executed, it produces the following result: Hello, world! Compiling and Linking an Assembly Program in NASM Make sure youhave set the pathof nasmand ld binaries inyour PATH environment variable. Now, take the following steps for compiling and linking the above program: Type the above code using a text editor and save it as hello.asm. Make sure that youare inthe same directory as where yousaved hello.asm. To assemble the program, type nasm -f elf hello.asm If there is any error, youwillbe prompted about that at this stage. Otherwise, anobject file of your programnamed hello.o willbe created.
  • 3. To link the object file and create anexecutable file named hello, type ld -m elf_i386 -s -o hello hello.o Execute the programby typing ./hello If youhave done everything correctly, it willdisplay Hello, world! onthe screen.