int main(){
int uid;
__asm__ __volatile__(
"mov $24,%%eax\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
:"=m"(uid)
);
printf("asm_result=%d\napi_result=%d\n",uid, getuid());
return 0;
}
反汇编:
main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $32, %esp
mov $24,%eax
int $0x80
mov %eax,28(%esp)
call getuid
movl 28(%esp), %edx
movl %eax, 8(%esp)
movl %edx, 4(%esp)
movl $.LC0, (%esp)
call printf
movl $0, %eax
leave
ret
总结:
汇编部分通过int 指令int $0x80指令触发一个软中断产生128(0x80)中断向量,并传递参数(存在%eax),根据这个中断向量找到对应的中断服务程序(中断向量128对应的中断服务程序就是系统调用处理程序),系统调用处理程序中根据参数找到对应的系统调用服务例程并调用。