Created
March 26, 2014 11:37
-
-
Save OzTamir/9781353 to your computer and use it in GitHub Desktop.
Fork Process in x86 NASM. Each process will print a different message and then exit.
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
section .text | |
global _start | |
_start: | |
mov eax, 2 ; SYS_FORK Op Code | |
int 0x80 | |
cmp eax, 0 ;If the return value is 0, we are in the child process | |
jz child | |
parent: | |
mov edx, len ;Move msg length to edx | |
mov ecx, msg ;Move msg to ecx | |
call print ;Print | |
call exit ;Exit | |
child: | |
mov edx,cLen ;Same... | |
mov ecx,cMsg | |
call print | |
call exit | |
print: | |
mov ebx,1 ;first argument: file handle (stdout) | |
mov eax,4 ;system call number (SYS_WRITE) | |
int 0x80 | |
ret | |
exit: | |
mov ebx,0 ; Exit code | |
mov eax,1 ; SYS_EXIT | |
int 0x80 | |
section .data | |
msg db "I AM YOUR FATHER",0xa ;String to be printed by father process | |
len equ $ - msg ; And it's length | |
cMsg db "Im the good child",0xa ;String to be printed by child process | |
cLen equ $ - cMsg ;And it's length... |
SYS_FORK isn't an opcode, it's a system call. Other than that, really useful, thanks.
Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great tutorial. Small point, but it should be jmp exit as exit doesn't return.