Exit program in Assembly code
Do not miss this exclusive book on Binary Tree Problems. Get it now for free.
In this article at OpenGenus, we have explored how to exit a program written in Assembly.
Table of contents:
- Introduction to exit
- Exit in Assembly code
Introduction to exit
Following is a simple C code using exit:
#include <stdio.h>
#include <stdlib.h>
int main() {
printf("Exiting the program\n");
exit(0);
}
How does the exit() call convert in Assembly code?
Exit in Assembly code
To exit an assembly code, use the following:
mov eax, 1
xor ebx, ebx
int 0x80
This is for x86 assembly architecture. The steps are:
- The value of register eax is set to 1 which corresponds to system call for exit
- Register ebx is set to 0 which is the exit status. 0 denotes normal exit.
- The last statement int 0x80 raises an interrupt 0x80 to trigger the exit system call.
If you want to dive further in this domain of counting set bits, go through the paper titled "Faster Population Counts Using AVX2 Instructions" by Wojciech Mula, Nathan Kurz and Daniel Lemire.
With this article at OpenGenus, you must have the complete idea of how to implement exit in Assembly code.
Sign up for FREE 3 months of Amazon Music. YOU MUST NOT MISS.