Linux 64位汇编调用C语言库函数,以编写了一个调用printf函数,显示字符串“Hello World”的程序为例。
.section .data fmt: .asciz "Hello %s\n" arg: .asciz "World" .section .text .global _start _start: # call printf movq $fmt, %rdi movq $arg, %rsi call printf # call exit movq $0, %rdi call exit
编译运行:
[ycxie@localhost Workspace]$ as -o demo_libc.o demo_libc.s [ycxie@localhost Workspace]$ ld -lc -I /usr/lib64/ld-linux-x86-64.so.2 -o demo_libc demo_libc.o [ycxie@localhost Workspace]$ ./demo_libc Hello World