标签:
# libc.s .section .data output: .asciz "The result is %d. \n" # printf 函数需要空字符结尾的字符串 .section .bss .lcomm result, 4 .section .text .globl _start _start: nop movl $0, result movl %esp, %ebp pushl 8(%ebp) # 把第一个命令行参数指针压入堆栈 call atoi # 把参数字符串转换为整型 movl %eax, result # atoi函数返回值返回到eax寄存器中 pushl 12(%ebp) # 把第二个命令行参数指针压入堆栈 call atoi addl %eax, result pushl result # 把参数传递给函数printf,必须把他们压入堆栈。 pushl $output # 参数放入顺序和printf获取的顺序相反。 call printf pushl $0 call exit
$ make as -gstabs -o libc.o libc.s ld -o arg libc.o libc.o:libc.s:18: undefined reference to `atoi' libc.o:libc.s:22: undefined reference to `atoi' libc.o:libc.s:27: undefined reference to `printf' libc.o:libc.s:30: undefined reference to `exit' make: *** [arg] 错误 1
$ ./libc 1 45 The result is 46. $ ./libc 100 23 The result is 123. $
linux平台学x86汇编(十六):在汇编语言中调用C库函数
标签:
原文地址:http://blog.csdn.net/shallnet/article/details/45625299