This Repository is a collection of different ethical hacking tools and malware's for penetration testing and research purpose written in python, ruby, rust, c++, go and c.
JavaScript algorithmsartificial-intelligencebugbountycryptographycyber-threat-intelligencecybersecurity-projectsethical-hackinghacking-toolsmalwarenessusnetwork-monitoringnetwork-securitynmapportscannerpythonpythonprojectsthreat-intelligencevirus-scanning
Create How does Assembly language interact with the operating system.md
Abdul Wahab Junaidb76322fe5c05
diff --git a/Assembly language/Basics of Assembly language/How does Assembly language interact with the operating system.md b/Assembly language/Basics of Assembly language/How does Assembly language interact with the operating system.mdnew file mode 100644index 0000000..231b26a--- /dev/null+++ b/Assembly language/Basics of Assembly language/How does Assembly language interact with the operating system.md@@ -0,0 +1,51 @@+Assembly language interacts with the operating system (OS) through a set of predefined functions, known as system calls or interrupts. System calls provide a way for programs written in assembly or other languages to request services from the operating system, such as file I/O, process creation, memory allocation, and other operations that require privileged access. The interaction between assembly language and the operating system generally involves the following steps:++1. **Software Interrupt (Trap):**+ - When a program needs to request a service from the operating system, it triggers a software interrupt or trap. This is often accomplished through an assembly language instruction specifically designed for invoking interrupts (e.g., `int` instruction in x86 architecture).++ ```assembly+ ; Example of triggering a software interrupt for system call+ MOV AH, 4EH ; Service number for "Create File" in DOS+ INT 21H ; Trigger software interrupt 21H to invoke the operating system+ ```++2. **Interrupt Vector Table (IVT):**+ - The interrupt vector table is a data structure that associates interrupt or system call numbers with the corresponding addresses of their handlers or service routines.+ - The operating system sets up the IVT during initialization.++3. **Context Switch to Kernel Mode:**+ - Invoking a system call requires transitioning from user mode to kernel mode, where the operating system has privileged access to system resources.+ - The interrupt mechanism facilitates this transition, allowing the OS to execute the requested service on behalf of the user program.++4. **Execution of System Call Handler:**+ - The operating system's kernel contains a set of system call handlers, each associated with a specific service.+ - When an interrupt is triggered, the CPU jumps to the corresponding handler's address, initiating the execution of the system call.++5. **Parameters and Results:**+ - System calls often involve passing parameters from the user program to the operating system and returning results back to the program.+ - Parameters may be passed in registers, memory locations, or a combination of both, depending on the architecture and system call.++ ```assembly+ ; Example of passing parameters to a system call+ MOV AH, 09H ; Service number for "Print String" in DOS+ LEA DX, Message ; Load effective address of the message into DX+ INT 21H ; Trigger software interrupt 21H to invoke the operating system+ ```++6. **Return from Kernel Mode:**+ - After executing the system call, the operating system returns control to the user program.+ - The return may involve copying results back to user space and restoring the user program's context.++7. **Error Handling:**+ - System calls may encounter errors, such as invalid parameters or insufficient permissions.+ - The system call handler returns an error code, which the user program can check to handle exceptional conditions.++ ```assembly+ ; Example of checking for errors after a system call+ JC ErrorHandler ; Jump to error handler if carry flag is set (indicating an error)+ ```++8. **Common System Calls:**+ - Common system calls include those for file I/O (`open`, `read`, `write`, `close`), process management (`fork`, `exec`, `exit`), memory management (`brk`, `mmap`), and other essential OS services.++The specifics of system calls, including the registers used for passing parameters and receiving results, vary across different architectures and operating systems. The interaction described here is a generalized model that applies to many systems, but details may differ. It's essential to consult the documentation of the specific operating system and architecture for accurate information on system calls and their usage.