汇编和C实现 Hello, world! 之比较

下列分别是三种实现的代码。

#hello_32.s
.data                    
msg : .string "Hello, world!\n" 
len = .-msg
.text
.global _start
_start:
movl $len, %edx
movl $msg, %ecx
movl $1, %ebx
movl $4, %eax
int  $0x80

movl $0,%ebx
movl $1,%eax
int  $0x80
#hello_64.s
.data                    
msg : .string "Hello, world!\n" 
len = .-msg
.text
.code64
.globl _start
_start:
movq $len, %rdx
leaq msg, %rsi
movq $1, %rdi
movq $1, %rax
syscall

movq $60, %rax 
xorq %rdi, %rdi
syscall
#include <stdio.h>

int main(int argc, char **argv)
{
    printf("Hello, world!\n");
    return 0;
}

编译后的文件大小如下:

-rwxr-xr-x. 1 xxx users 1603 Nov 10 10:38 hello_32
-rwxr-xr-x. 1 xxx users 1603 Nov 10 10:37 hello_64
-rwxr-xr-x. 1 xxx users 8505 Nov 10 10:59 hello_c

你可能感兴趣的:(汇编,C语言)