From 8db222397eebaececbb1adff41404a65fb474e45 Mon Sep 17 00:00:00 2001 From: dwrz Date: Thu, 16 Mar 2023 00:54:00 +0000 Subject: [PATCH] Add exit --- exit/exit.s | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 exit/exit.s diff --git a/exit/exit.s b/exit/exit.s new file mode 100644 index 0000000..e89cddf --- /dev/null +++ b/exit/exit.s @@ -0,0 +1,37 @@ +#PURPOSE: Simple program that exits and returns a +# status code back to the Linux kernel +# + +#INPUT: none +# + +#OUTPUT: returns a status code This can be viewed +# by typing +# +# echo $? +# +# after running the program +# + +#VARIABLES: +# %rax holds the system call number +# %rbx holds the return status +# +.section .data + +.section .text +.globl _start + +_start: +mov $1, %rax # this is the linux kernel command + # number (system call) for exiting + # $ means immediate mode addressing, + # without $ it defaults to direct + # mode, looking up a number in + # address 1 + +mov $0, %rbx # this is the status number we will + # return to the OS + +int $0x80 # this wakes up the kernel to run the + # exit command