Linux系统调用与内联汇编编程详解
1. 追踪C函数
C库函数通过底层系统调用实现其功能。可以使用 strace 程序来观察C函数的操作。例如, cfunctest.s 程序复制了 nanotest.s 程序的功能,但使用了C函数调用:
# cfunctest.s - An example of using C functions */
.section .data
output:
.asciz “This is a test\n”
.section .text
.globl _start
_start:
movl $10, %ecx
loop1:
pushl %ecx
pushl $output
call printf
addl $4, %esp
pushl $5
call sleep
addl $4, %esp
popl %ecx
loop loop1
pushl $0
call exit
与 nanotest.s 程序类似, ECX 寄存器用作循环计数器。在调用 printf 和 sleep 函数之前,必须将其压入堆栈,因为在函数调用中其值会被破坏。
要创建可执行程序,必须将 cfunctest.s 程序与Linux系统上的C库以及动态加载器链接:
$ as -o c
超级会员免费看
订阅专栏 解锁全文
412

被折叠的 条评论
为什么被折叠?



