Search anything:

Exit program in Assembly code

Learn Algorithms and become a National Programmer
Indian Technical Authorship Contest starts on 1st July 2023. Stay tuned.

In this article at OpenGenus, we have explored how to exit a program written in Assembly.

Table of contents:

  1. Introduction to exit
  2. 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");

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.

Devansh Biswal

3rd year B. Tech student at Veer Surendra Sai University of Technology, Burla. Working hard day and night to get placed at Google.

Read More

Vote for Author of this article:

Improved & Reviewed by:

OpenGenus Tech Review Team OpenGenus Tech Review Team