2020-2021-1 20209321《Linux内核原理与分析》第五周作业

1.通过对库函数的调用来实现对文件的改名

2.在C语言代码中调用汇编来实现对文件的改名

3.通过对库函数的调用来获取系统时间

代码如下:

#include<stdio.h>
#include<time.h>

int main(){
	time_t tt;
	struct tm *t;
	tt = time(NULL);
	t = localtime(&tt);
	printf("time:%d:%d:%d:%d:%d:%d:\n",t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
	return 0;
}

4.在C语言代码中调用汇编来触发系统调用

#include<stdio.h>
#include<time.h>
int main(){
	time_t tt;
	struct tm *t;
	asm volatile(
		"movl $0,%%ebx\n\t"
		"movl $0xd,%%eax\n\t"
		"int $0x80\n\t"
		"movl %%eax,%0\n\t"
		:"=m"(tt)
		:
		:"eax","ebx"
	);
	t=localtime(&tt);
	printf("time:%d:%d:%d:%d:%d:%d:\n",t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
	return 0;
}
posted @ 2020-11-08 21:10  20209321  阅读(79)  评论(1编辑  收藏  举报