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

A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
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
 
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
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
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
 
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
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
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
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
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
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
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
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
lorraineandreiamcidl
 

Recently uploaded (20)

A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
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
 
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
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
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
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
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
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
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
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
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
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
 

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