-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: 0x4248 <60709927+0x4248@users.noreply.github.com>
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
return | ||
====== | ||
|
||
Returning 0 from main using basic assembly | ||
|
||
Source code structure | ||
--------------------- | ||
|
||
In the program we only run three instructions | ||
|
||
|
||
We first move the value 60 to the rax register, this will tell linux that we | ||
want to exit the program. | ||
|
||
mov rax, 60 | ||
|
||
We then move the value 0 to the rdi register, this is the argument that we pass | ||
into the exit syscall. The RDI register stores the code that's being used to exit. | ||
|
||
mov rdi, 0 | ||
|
||
We then run the syscall instruction to exit the program. | ||
|
||
syscall | ||
|
||
The program will return 0 to the shell. We can confirm this by running the | ||
program and then using echo $? to see the return value. | ||
|
||
|
||
./return | ||
echo $? |