September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,32 +1,71 @@
|
|||
extern fork
|
||||
extern printf
|
||||
; x86_64 linux nasm
|
||||
|
||||
%include "/home/james/Desktop/ASM_LIB/Print.asm"
|
||||
%include "/home/james/Desktop/ASM_LIB/Sleep.asm"
|
||||
|
||||
section .data
|
||||
|
||||
parent: db "Parent: "
|
||||
child: db "Child: "
|
||||
newLine: db 10
|
||||
|
||||
section .text
|
||||
global _start
|
||||
|
||||
_start:
|
||||
call fork
|
||||
cmp eax, 0
|
||||
je _child
|
||||
jg _parent
|
||||
jmp _exit
|
||||
|
||||
_parent:
|
||||
push p_msg
|
||||
call printf
|
||||
jmp _exit
|
||||
_child:
|
||||
push c_msg
|
||||
call printf
|
||||
jmp _exit
|
||||
|
||||
_exit:
|
||||
push 0x1
|
||||
mov eax, 1
|
||||
push eax
|
||||
int 0x80
|
||||
ret
|
||||
|
||||
section .data
|
||||
c_msg db "Printed from Child process",13,10,0
|
||||
p_msg db "Printed from Parent process",13,10,0
|
||||
|
||||
global _start
|
||||
|
||||
_start:
|
||||
mov rax, 57 ; fork syscall
|
||||
syscall
|
||||
cmp rax, 0 ; if the return value is 0, we're in the child process
|
||||
je printChild
|
||||
|
||||
printParent: ; else it's the child's PID, we're in the parent
|
||||
|
||||
mov rax, 1
|
||||
mov rdi, 1
|
||||
mov rsi, parent
|
||||
mov rdx, 8
|
||||
syscall
|
||||
|
||||
mov rax, 39 ; sys_getpid
|
||||
syscall
|
||||
mov rdi, rax
|
||||
call Print_Unsigned
|
||||
|
||||
mov rax, 1
|
||||
mov rdi, 1
|
||||
mov rsi, newLine
|
||||
mov rdx, 1
|
||||
syscall
|
||||
|
||||
mov rdi, 1 ; sleep so the child process can print befor the parent exits
|
||||
call Sleep ; you might not see the child output if you don't do this
|
||||
|
||||
jmp exit
|
||||
|
||||
printChild:
|
||||
|
||||
mov rdi, 1
|
||||
call Sleep ; sleep and wait for parent to print to screen first
|
||||
|
||||
mov rax, 1
|
||||
mov rdi, 1
|
||||
mov rsi, child
|
||||
mov rdx, 7
|
||||
syscall
|
||||
|
||||
mov rax, 39 ; sys_getpid
|
||||
syscall
|
||||
mov rdi, rax
|
||||
call Print_Unsigned
|
||||
|
||||
mov rax, 1
|
||||
mov rdi, 1
|
||||
mov rsi, newLine
|
||||
mov rdx, 1
|
||||
syscall
|
||||
|
||||
exit:
|
||||
mov rax, 60
|
||||
mov rdi, 0
|
||||
syscall
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue