码迷,mamicode.com
首页 > 系统相关 > 详细

AT&T ASSEMBLY FOR LINUX AND MAC (SYS_FORK)

时间:2015-05-07 08:41:11      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

Fork() in C: (sys_fork.c)

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(void)
{
    fork();
    printf("Hello Landpack\n");
    return 0;
}

技术分享

Fork() in AT&T for Linux:(sys_fork.s)

.section .rodata
msg:    .ascii "Hello Landpack\n"
    len = .-msg

.section .bass

.section .text
.globl _start
_start:
    movl    $2,%eax     # sys_fork number (2)
    int     $0x80

# As we know,if we fork() in C
# we will run the double process
# They almost have the same code and data

    movl    $4,%eax     # sys_write number (4)
    movl    $1,%ebx     # STDOUT_FILENO == (1)
    movl    $msg,%ecx   # The head address of msg
    movl    $len,%edx   # The offset of addr
    int     $0x80

    movl    $1,%eax
    movl    $0,%ebx
    int     $0x80

 技术分享

AT&T ASSEMBLY FOR LINUX AND MAC (SYS_FORK)

标签:

原文地址:http://www.cnblogs.com/landpack/p/4483242.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!