AT&T ASSEMBLY FOR LINUX AND MAC (SYS_FORK)

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

 技术分享

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。