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
");
    return 0;
}

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

.section .rodata
msg:    .ascii "Hello Landpack
"
    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

 

Can we drop this masquerade
原文地址:https://www.cnblogs.com/landpack/p/4483242.html