Introduce examples dir
[lcapit-junk-code.git] / examples / C / getpid-asm.c
blob5158a3975fa902e35b5dd21fff79af4be2cb69c2
1 /*
2 * Calls getpid() by hand (linux-only probably)
4 * 1- Store the system call number in %eax
5 * 2- Executes int 0x80
6 * 3- Store the return code in 'ret'
7 *
8 * Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>
9 */
11 #include <stdio.h>
12 #include <unistd.h>
14 int main(void)
17 int ret, num;
19 num = 20; /* gerpid()'s number */
21 asm("movl %1, %%eax\n\t"
22 "int $0x80\n\t"
23 "movl %%eax, %0"
24 : "=r" (ret)
25 : "r" (num)
26 : "%eax");
28 printf("PID: %d\n", ret);
29 return 0;