EBX,EXC,EDX,ESI,EDI,EBP
系统调用 time系统调用time_asm.c
#include#include int main(){ time_t tt; struct tm *t; asm volatile( "mov $0,%%ebxnt" "mov $0xd,%%eaxnt" "int 0x80nt" "mov %%eax,%0nt" :"=m"(tt) ); t = localtime(&tt); printf("time:%d:%d:%d:%d:%d:%d:n",t->tm_year+1900,t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec); return 0; }
这个代码有个地方好像是错的
t->tm_mda===>t->tm_mday
rename.c
#includeint main(){ int ret;//承接系统返回值 char *oldname="hello.c"; char *newname="newhello.c"; ret = rename(oldname,newname); if(ret == 0) printf("Rename ok"); else printf("Rename failed"); return 0; }
rename_asm.c
#includeint main(){ int ret; char *oldname="hello.c"; char *newname="newhello.c"; asm volatile( "movl %2,%%ecxnt" //newname是第二个值,所以赋给ecx "movl %1,%%ebxnt" //oldname 是第一个值,所以赋给ebx "movl $0x26,%%eaxnt" //rename的系统调用号是38 :"=a"(ret) :"b"(oldname),"c"(newname) ); if(ret ==0 ) printf("Rename ok!"); else printf("Rename failed"); return 0; }
syscall.c
#include遇到问题#include int main(){ int ret; char *oldname="hello.c"; char *newname="newhello.c"; ret = syscall(SYS_reanme,oldname,newname); if(ret ==0 ) printf("Rename ok!"); else printf("Rename failed"); return 0;
估计是因为 实验楼的环境是64位,所以会出错
加上这个,应该就行gcc rename_asm.c -o rename_asm -m32
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)