Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
http://www.tutorialspoint.com/assembly_prog ramming /assembly_system_calls.htm Copyright © tutorialspoint.com
ASSEMBLY - SYSTEM CALLS
Systemcalls are APIs for the interface betweenuser space and kernelspace. We have already used the system
calls sys_write and sys_exit for writing into the screenand exiting fromthe program, respectively.
Linux System Calls
Youcanmake use of Linux systemcalls inyour assembly programs. Youneed to take the following steps for
using Linux systemcalls inyour program:
Put the systemcallnumber inthe EAX register.
Store the arguments to the systemcallinthe registers EBX, ECX, etc.
Callthe relevant interrupt (80h).
The result is usually returned inthe EAX register.
There are six registers that store the arguments of the systemcallused. These are the EBX, ECX, EDX, ESI,
EDI, and EBP. These registers take the consecutive arguments, starting withthe EBX register. If there are
more thansix arguments, thenthe memory locationof the first argument is stored inthe EBX register.
The following code snippet shows the use of the systemcallsys_exit:
mov eax,1 ; system call number (sys_exit)
int 0x80 ; call kernel
The following code snippet shows the use of the systemcallsys_write:
mov edx,4 ; 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
Allthe syscalls are listed in/usr/include/asm/unistd.h, together withtheir numbers (the value to put inEAX
before youcallint 80h).
The following table shows some of the systemcalls used inthis tutorial:
%eax Name %ebx %ecx %edx %esx %edi
1 sys_exit int - - - -
2 sys_fork struct pt_regs - - - -
3 sys_read unsigned int char * size_t - -
4 sys_write unsigned int const char * size_t - -
5 sys_open const char * int int - -
6 sys_close unsigned int - - - -
Example
The following example reads a number fromthe keyboard and displays it onthe screen:
section .data ;Data segment
userMsg db 'Please enter a number: ' ;Ask the user to enter a number
lenUserMsg equ $-userMsg ;The length of the message
dispMsg db 'You have entered: '
lenDispMsg equ $-dispMsg
section .bss ;Uninitialized data
num resb 5
section .text ;Code Segment
global _start
_start:
;User prompt
mov eax, 4
mov ebx, 1
mov ecx, userMsg
mov edx, lenUserMsg
int 80h
;Read and store the user input
mov eax, 3
mov ebx, 2
mov ecx, num
mov edx, 5 ;5 bytes (numeric, 1 for sign) of that information
int 80h
;Output the message 'The entered number is: '
mov eax, 4
mov ebx, 1
mov ecx, dispMsg
mov edx, lenDispMsg
int 80h
;Output the number entered
mov eax, 4
mov ebx, 1
mov ecx, num
mov edx, 5
int 80h
; Exit code
mov eax, 1
mov ebx, 0
int 80h
Whenthe above code is compiled and executed, it produces the following result:
Please enter a number:
1234
You have entered:1234

More Related Content

What's hot

Chapter 01
Chapter 01Chapter 01
Chapter 01
Google
 
Part 04 Creating a System Call in Linux
Part 04 Creating a System Call in LinuxPart 04 Creating a System Call in Linux
Part 04 Creating a System Call in Linux
Tushar B Kute
 
System calls
System callsSystem calls
System calls
Bernard Senam
 
System Calls
System CallsSystem Calls
System Calls
Anil Kumar Pugalia
 
Summarized of UNIX Time Sharing System
Summarized of UNIX Time Sharing SystemSummarized of UNIX Time Sharing System
Summarized of UNIX Time Sharing System
Shuya Osaki
 
System Calls
System CallsSystem Calls
System Calls
Anil Kumar Pugalia
 
Studying a decade of Linux system calls
Studying a decade of Linux system callsStudying a decade of Linux system calls
Studying a decade of Linux system calls
corpaulbezemer
 
System Init
System InitSystem Init
System Init
cntlinux
 
System call
System callSystem call
System call
RakshiyaRamya
 
LINUX System Call Quick Reference
LINUX System Call Quick ReferenceLINUX System Call Quick Reference
LINUX System Call Quick Reference
wensheng wei
 
Os note
Os noteOs note
Chapter 3 Using Unix Commands
Chapter 3 Using Unix CommandsChapter 3 Using Unix Commands
Chapter 3 Using Unix Commands
MeenalJabde
 
System call
System callSystem call
System call
Sumant Diwakar
 
Monit
MonitMonit

What's hot (14)

Chapter 01
Chapter 01Chapter 01
Chapter 01
 
Part 04 Creating a System Call in Linux
Part 04 Creating a System Call in LinuxPart 04 Creating a System Call in Linux
Part 04 Creating a System Call in Linux
 
System calls
System callsSystem calls
System calls
 
System Calls
System CallsSystem Calls
System Calls
 
Summarized of UNIX Time Sharing System
Summarized of UNIX Time Sharing SystemSummarized of UNIX Time Sharing System
Summarized of UNIX Time Sharing System
 
System Calls
System CallsSystem Calls
System Calls
 
Studying a decade of Linux system calls
Studying a decade of Linux system callsStudying a decade of Linux system calls
Studying a decade of Linux system calls
 
System Init
System InitSystem Init
System Init
 
System call
System callSystem call
System call
 
LINUX System Call Quick Reference
LINUX System Call Quick ReferenceLINUX System Call Quick Reference
LINUX System Call Quick Reference
 
Os note
Os noteOs note
Os note
 
Chapter 3 Using Unix Commands
Chapter 3 Using Unix CommandsChapter 3 Using Unix Commands
Chapter 3 Using Unix Commands
 
System call
System callSystem call
System call
 
Monit
MonitMonit
Monit
 

Similar to N_Asm Assembly system calls (sol)

Introduction to Assembly Language Programming
Introduction to Assembly Language ProgrammingIntroduction to Assembly Language Programming
Introduction to Assembly Language Programming
Rahul P
 
LINUX Device Drivers
LINUX Device DriversLINUX Device Drivers
LINUX Device Drivers
Partha Bhattacharya
 
Buffer overflow – Smashing The Stack
Buffer overflow – Smashing The StackBuffer overflow – Smashing The Stack
Buffer overflow – Smashing The Stack
Tomer Zait
 
Shellcoding in linux
Shellcoding in linuxShellcoding in linux
Shellcoding in linux
Ajin Abraham
 
N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)N_Asm Assembly macros (sol)
N_Asm Assembly macros (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
 
X86 assembly nasm syntax
X86 assembly nasm syntaxX86 assembly nasm syntax
X86 assembly nasm syntax
Francesco DiFusco
 
ASSEMBLY LANGUAGE.pptx
ASSEMBLY LANGUAGE.pptxASSEMBLY LANGUAGE.pptx
ASSEMBLY LANGUAGE.pptx
EdFeranil
 
Trap Handling in Linux
Trap Handling in LinuxTrap Handling in Linux
Trap Handling in Linux
YongraeJo
 
Buffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the StackBuffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the Stack
ironSource
 
Shellcode Disassembling - Reverse Engineering
Shellcode Disassembling - Reverse EngineeringShellcode Disassembling - Reverse Engineering
Shellcode Disassembling - Reverse Engineering
Sumutiu Marius
 
Linux Shellcode disassembling
Linux Shellcode disassemblingLinux Shellcode disassembling
Linux Shellcode disassembling
Harsh Daftary
 
X86 assembly & GDB
X86 assembly & GDBX86 assembly & GDB
X86 assembly & GDB
Jian-Yu Li
 
ppt aman solanki.pptx
ppt aman solanki.pptxppt aman solanki.pptx
ppt aman solanki.pptx
HUNNTERRAJPUT
 
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Vincenzo Iozzo
 
Dive into exploit development
Dive into exploit developmentDive into exploit development
Dive into exploit development
Payampardaz
 
Linux Kernel Tour
Linux Kernel TourLinux Kernel Tour
Linux Kernel Tour
samrat das
 
202202 SUGUKI UNIX X Command Tips and Tricks
202202 SUGUKI UNIX X Command Tips and Tricks202202 SUGUKI UNIX X Command Tips and Tricks
202202 SUGUKI UNIX X Command Tips and Tricks
dhorvath
 
N_Asm Assembly basic syntax (sol)
N_Asm Assembly basic syntax (sol)N_Asm Assembly basic syntax (sol)
N_Asm Assembly basic syntax (sol)
Selomon birhane
 
Al2ed chapter17
Al2ed chapter17Al2ed chapter17
Al2ed chapter17
Abdullelah Al-Fahad
 

Similar to N_Asm Assembly system calls (sol) (20)

Introduction to Assembly Language Programming
Introduction to Assembly Language ProgrammingIntroduction to Assembly Language Programming
Introduction to Assembly Language Programming
 
LINUX Device Drivers
LINUX Device DriversLINUX Device Drivers
LINUX Device Drivers
 
Buffer overflow – Smashing The Stack
Buffer overflow – Smashing The StackBuffer overflow – Smashing The Stack
Buffer overflow – Smashing The Stack
 
Shellcoding in linux
Shellcoding in linuxShellcoding in linux
Shellcoding in linux
 
N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)
 
N_Asm Assembly numbers (sol)
N_Asm Assembly numbers (sol)N_Asm Assembly numbers (sol)
N_Asm Assembly numbers (sol)
 
X86 assembly nasm syntax
X86 assembly nasm syntaxX86 assembly nasm syntax
X86 assembly nasm syntax
 
ASSEMBLY LANGUAGE.pptx
ASSEMBLY LANGUAGE.pptxASSEMBLY LANGUAGE.pptx
ASSEMBLY LANGUAGE.pptx
 
Trap Handling in Linux
Trap Handling in LinuxTrap Handling in Linux
Trap Handling in Linux
 
Buffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the StackBuffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the Stack
 
Shellcode Disassembling - Reverse Engineering
Shellcode Disassembling - Reverse EngineeringShellcode Disassembling - Reverse Engineering
Shellcode Disassembling - Reverse Engineering
 
Linux Shellcode disassembling
Linux Shellcode disassemblingLinux Shellcode disassembling
Linux Shellcode disassembling
 
X86 assembly & GDB
X86 assembly & GDBX86 assembly & GDB
X86 assembly & GDB
 
ppt aman solanki.pptx
ppt aman solanki.pptxppt aman solanki.pptx
ppt aman solanki.pptx
 
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
 
Dive into exploit development
Dive into exploit developmentDive into exploit development
Dive into exploit development
 
Linux Kernel Tour
Linux Kernel TourLinux Kernel Tour
Linux Kernel Tour
 
202202 SUGUKI UNIX X Command Tips and Tricks
202202 SUGUKI UNIX X Command Tips and Tricks202202 SUGUKI UNIX X Command Tips and Tricks
202202 SUGUKI UNIX X Command Tips and Tricks
 
N_Asm Assembly basic syntax (sol)
N_Asm Assembly basic syntax (sol)N_Asm Assembly basic syntax (sol)
N_Asm Assembly basic syntax (sol)
 
Al2ed chapter17
Al2ed chapter17Al2ed chapter17
Al2ed chapter17
 

More from 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 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
 
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 (9)

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 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)
 
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

The two flavors of Python 3.13 - PyHEP 2024
The two flavors of Python 3.13 - PyHEP 2024The two flavors of Python 3.13 - PyHEP 2024
The two flavors of Python 3.13 - PyHEP 2024
Henry Schreiner
 
Googling for Software Development: What Developers Search For and What They F...
Googling for Software Development: What Developers Search For and What They F...Googling for Software Development: What Developers Search For and What They F...
Googling for Software Development: What Developers Search For and What They F...
Andre Hora
 
CrushFTP 10.4.0.29 PC Software - WhizNews
CrushFTP 10.4.0.29 PC Software - WhizNewsCrushFTP 10.4.0.29 PC Software - WhizNews
CrushFTP 10.4.0.29 PC Software - WhizNews
Eman Nisar
 
My Bully Is My Lover Apk CH1 EP4 (Gallery Unlock, MOD)
My Bully Is My Lover Apk CH1 EP4 (Gallery Unlock, MOD)My Bully Is My Lover Apk CH1 EP4 (Gallery Unlock, MOD)
My Bully Is My Lover Apk CH1 EP4 (Gallery Unlock, MOD)
Apk2me
 
Augmented Reality (AR) in Ionic Apps Transforming User Experiences.pdf
Augmented Reality (AR) in Ionic Apps Transforming User Experiences.pdfAugmented Reality (AR) in Ionic Apps Transforming User Experiences.pdf
Augmented Reality (AR) in Ionic Apps Transforming User Experiences.pdf
Grey Space Computing
 
Alluxio Webinar | What’s new in Alluxio Enterprise AI 3.2: Leverage GPU Anywh...
Alluxio Webinar | What’s new in Alluxio Enterprise AI 3.2: Leverage GPU Anywh...Alluxio Webinar | What’s new in Alluxio Enterprise AI 3.2: Leverage GPU Anywh...
Alluxio Webinar | What’s new in Alluxio Enterprise AI 3.2: Leverage GPU Anywh...
Alluxio, Inc.
 
JavaScript API Deprecation in the Wild: A First Assessment (SANER 2020)
JavaScript API Deprecation in the Wild: A First Assessment (SANER 2020)JavaScript API Deprecation in the Wild: A First Assessment (SANER 2020)
JavaScript API Deprecation in the Wild: A First Assessment (SANER 2020)
Andre Hora
 
Python Objects and Data Structure Basics
Python Objects and Data Structure BasicsPython Objects and Data Structure Basics
Python Objects and Data Structure Basics
roldangomezjuan0
 
Automating Enterprise Workflows with Node.pdf
Automating Enterprise Workflows with Node.pdfAutomating Enterprise Workflows with Node.pdf
Automating Enterprise Workflows with Node.pdf
Jane Brewer
 
Full stack odoo development solutions provided by Fortune 500 trusted supplier
Full stack odoo development solutions provided by Fortune 500 trusted supplierFull stack odoo development solutions provided by Fortune 500 trusted supplier
Full stack odoo development solutions provided by Fortune 500 trusted supplier
Odoo Red
 
Cloud Databases and Big Data - Mechlin.pptx
Cloud Databases and Big Data - Mechlin.pptxCloud Databases and Big Data - Mechlin.pptx
Cloud Databases and Big Data - Mechlin.pptx
Mitchell Marsh
 
Limited Time Offer! Pay One Time to Access to Sociosight for Only $95
Limited Time Offer! Pay One Time to Access to Sociosight for Only $95Limited Time Offer! Pay One Time to Access to Sociosight for Only $95
Limited Time Offer! Pay One Time to Access to Sociosight for Only $95
Sri Damayanti
 
Customer Relationship Management Systems.pptx
Customer Relationship Management Systems.pptxCustomer Relationship Management Systems.pptx
Customer Relationship Management Systems.pptx
Amara Nielson
 
How to Choose the Right Partner for Outsource Website Development
How to Choose the Right Partner for Outsource Website DevelopmentHow to Choose the Right Partner for Outsource Website Development
How to Choose the Right Partner for Outsource Website Development
Rollout IT
 
A House In The Rift 0.7.10 b1 (Gallery Unlock, MOD)
A House In The Rift 0.7.10 b1 (Gallery Unlock, MOD)A House In The Rift 0.7.10 b1 (Gallery Unlock, MOD)
A House In The Rift 0.7.10 b1 (Gallery Unlock, MOD)
Apk2me
 
How and Why Developers Migrate Python Tests (SANER 2022)
How and Why Developers Migrate Python Tests (SANER 2022)How and Why Developers Migrate Python Tests (SANER 2022)
How and Why Developers Migrate Python Tests (SANER 2022)
Andre Hora
 
Understanding Automated Testing Tools for Web Applications.pdf
Understanding Automated Testing Tools for Web Applications.pdfUnderstanding Automated Testing Tools for Web Applications.pdf
Understanding Automated Testing Tools for Web Applications.pdf
kalichargn70th171
 
Cal Girls Fort Chandragupt Jaipur 8445551418 Khusi Top Class Girls Call Jaipu...
Cal Girls Fort Chandragupt Jaipur 8445551418 Khusi Top Class Girls Call Jaipu...Cal Girls Fort Chandragupt Jaipur 8445551418 Khusi Top Class Girls Call Jaipu...
Cal Girls Fort Chandragupt Jaipur 8445551418 Khusi Top Class Girls Call Jaipu...
Trisha Kumari
 
Viswanath_Cover letter_Scrum Master_10+yrs
Viswanath_Cover letter_Scrum Master_10+yrsViswanath_Cover letter_Scrum Master_10+yrs
Viswanath_Cover letter_Scrum Master_10+yrs
cviswanathsai
 
Experience Enhanced Testing with the Best Test Automation Tools for Salesforc...
Experience Enhanced Testing with the Best Test Automation Tools for Salesforc...Experience Enhanced Testing with the Best Test Automation Tools for Salesforc...
Experience Enhanced Testing with the Best Test Automation Tools for Salesforc...
kalichargn70th171
 

Recently uploaded (20)

The two flavors of Python 3.13 - PyHEP 2024
The two flavors of Python 3.13 - PyHEP 2024The two flavors of Python 3.13 - PyHEP 2024
The two flavors of Python 3.13 - PyHEP 2024
 
Googling for Software Development: What Developers Search For and What They F...
Googling for Software Development: What Developers Search For and What They F...Googling for Software Development: What Developers Search For and What They F...
Googling for Software Development: What Developers Search For and What They F...
 
CrushFTP 10.4.0.29 PC Software - WhizNews
CrushFTP 10.4.0.29 PC Software - WhizNewsCrushFTP 10.4.0.29 PC Software - WhizNews
CrushFTP 10.4.0.29 PC Software - WhizNews
 
My Bully Is My Lover Apk CH1 EP4 (Gallery Unlock, MOD)
My Bully Is My Lover Apk CH1 EP4 (Gallery Unlock, MOD)My Bully Is My Lover Apk CH1 EP4 (Gallery Unlock, MOD)
My Bully Is My Lover Apk CH1 EP4 (Gallery Unlock, MOD)
 
Augmented Reality (AR) in Ionic Apps Transforming User Experiences.pdf
Augmented Reality (AR) in Ionic Apps Transforming User Experiences.pdfAugmented Reality (AR) in Ionic Apps Transforming User Experiences.pdf
Augmented Reality (AR) in Ionic Apps Transforming User Experiences.pdf
 
Alluxio Webinar | What’s new in Alluxio Enterprise AI 3.2: Leverage GPU Anywh...
Alluxio Webinar | What’s new in Alluxio Enterprise AI 3.2: Leverage GPU Anywh...Alluxio Webinar | What’s new in Alluxio Enterprise AI 3.2: Leverage GPU Anywh...
Alluxio Webinar | What’s new in Alluxio Enterprise AI 3.2: Leverage GPU Anywh...
 
JavaScript API Deprecation in the Wild: A First Assessment (SANER 2020)
JavaScript API Deprecation in the Wild: A First Assessment (SANER 2020)JavaScript API Deprecation in the Wild: A First Assessment (SANER 2020)
JavaScript API Deprecation in the Wild: A First Assessment (SANER 2020)
 
Python Objects and Data Structure Basics
Python Objects and Data Structure BasicsPython Objects and Data Structure Basics
Python Objects and Data Structure Basics
 
Automating Enterprise Workflows with Node.pdf
Automating Enterprise Workflows with Node.pdfAutomating Enterprise Workflows with Node.pdf
Automating Enterprise Workflows with Node.pdf
 
Full stack odoo development solutions provided by Fortune 500 trusted supplier
Full stack odoo development solutions provided by Fortune 500 trusted supplierFull stack odoo development solutions provided by Fortune 500 trusted supplier
Full stack odoo development solutions provided by Fortune 500 trusted supplier
 
Cloud Databases and Big Data - Mechlin.pptx
Cloud Databases and Big Data - Mechlin.pptxCloud Databases and Big Data - Mechlin.pptx
Cloud Databases and Big Data - Mechlin.pptx
 
Limited Time Offer! Pay One Time to Access to Sociosight for Only $95
Limited Time Offer! Pay One Time to Access to Sociosight for Only $95Limited Time Offer! Pay One Time to Access to Sociosight for Only $95
Limited Time Offer! Pay One Time to Access to Sociosight for Only $95
 
Customer Relationship Management Systems.pptx
Customer Relationship Management Systems.pptxCustomer Relationship Management Systems.pptx
Customer Relationship Management Systems.pptx
 
How to Choose the Right Partner for Outsource Website Development
How to Choose the Right Partner for Outsource Website DevelopmentHow to Choose the Right Partner for Outsource Website Development
How to Choose the Right Partner for Outsource Website Development
 
A House In The Rift 0.7.10 b1 (Gallery Unlock, MOD)
A House In The Rift 0.7.10 b1 (Gallery Unlock, MOD)A House In The Rift 0.7.10 b1 (Gallery Unlock, MOD)
A House In The Rift 0.7.10 b1 (Gallery Unlock, MOD)
 
How and Why Developers Migrate Python Tests (SANER 2022)
How and Why Developers Migrate Python Tests (SANER 2022)How and Why Developers Migrate Python Tests (SANER 2022)
How and Why Developers Migrate Python Tests (SANER 2022)
 
Understanding Automated Testing Tools for Web Applications.pdf
Understanding Automated Testing Tools for Web Applications.pdfUnderstanding Automated Testing Tools for Web Applications.pdf
Understanding Automated Testing Tools for Web Applications.pdf
 
Cal Girls Fort Chandragupt Jaipur 8445551418 Khusi Top Class Girls Call Jaipu...
Cal Girls Fort Chandragupt Jaipur 8445551418 Khusi Top Class Girls Call Jaipu...Cal Girls Fort Chandragupt Jaipur 8445551418 Khusi Top Class Girls Call Jaipu...
Cal Girls Fort Chandragupt Jaipur 8445551418 Khusi Top Class Girls Call Jaipu...
 
Viswanath_Cover letter_Scrum Master_10+yrs
Viswanath_Cover letter_Scrum Master_10+yrsViswanath_Cover letter_Scrum Master_10+yrs
Viswanath_Cover letter_Scrum Master_10+yrs
 
Experience Enhanced Testing with the Best Test Automation Tools for Salesforc...
Experience Enhanced Testing with the Best Test Automation Tools for Salesforc...Experience Enhanced Testing with the Best Test Automation Tools for Salesforc...
Experience Enhanced Testing with the Best Test Automation Tools for Salesforc...
 

N_Asm Assembly system calls (sol)

  • 1. http://www.tutorialspoint.com/assembly_prog ramming /assembly_system_calls.htm Copyright © tutorialspoint.com ASSEMBLY - SYSTEM CALLS Systemcalls are APIs for the interface betweenuser space and kernelspace. We have already used the system calls sys_write and sys_exit for writing into the screenand exiting fromthe program, respectively. Linux System Calls Youcanmake use of Linux systemcalls inyour assembly programs. Youneed to take the following steps for using Linux systemcalls inyour program: Put the systemcallnumber inthe EAX register. Store the arguments to the systemcallinthe registers EBX, ECX, etc. Callthe relevant interrupt (80h). The result is usually returned inthe EAX register. There are six registers that store the arguments of the systemcallused. These are the EBX, ECX, EDX, ESI, EDI, and EBP. These registers take the consecutive arguments, starting withthe EBX register. If there are more thansix arguments, thenthe memory locationof the first argument is stored inthe EBX register. The following code snippet shows the use of the systemcallsys_exit: mov eax,1 ; system call number (sys_exit) int 0x80 ; call kernel The following code snippet shows the use of the systemcallsys_write: mov edx,4 ; 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 Allthe syscalls are listed in/usr/include/asm/unistd.h, together withtheir numbers (the value to put inEAX before youcallint 80h). The following table shows some of the systemcalls used inthis tutorial: %eax Name %ebx %ecx %edx %esx %edi 1 sys_exit int - - - - 2 sys_fork struct pt_regs - - - - 3 sys_read unsigned int char * size_t - - 4 sys_write unsigned int const char * size_t - - 5 sys_open const char * int int - - 6 sys_close unsigned int - - - - Example The following example reads a number fromthe keyboard and displays it onthe screen: section .data ;Data segment
  • 2. userMsg db 'Please enter a number: ' ;Ask the user to enter a number lenUserMsg equ $-userMsg ;The length of the message dispMsg db 'You have entered: ' lenDispMsg equ $-dispMsg section .bss ;Uninitialized data num resb 5 section .text ;Code Segment global _start _start: ;User prompt mov eax, 4 mov ebx, 1 mov ecx, userMsg mov edx, lenUserMsg int 80h ;Read and store the user input mov eax, 3 mov ebx, 2 mov ecx, num mov edx, 5 ;5 bytes (numeric, 1 for sign) of that information int 80h ;Output the message 'The entered number is: ' mov eax, 4 mov ebx, 1 mov ecx, dispMsg mov edx, lenDispMsg int 80h ;Output the number entered mov eax, 4 mov ebx, 1 mov ecx, num mov edx, 5 int 80h ; Exit code mov eax, 1 mov ebx, 0 int 80h Whenthe above code is compiled and executed, it produces the following result: Please enter a number: 1234 You have entered:1234