`
thecloud
  • 浏览: 879793 次
文章分类
社区版块
存档分类
最新评论

Linux0.11内核--汇编代码实现C函数

 
阅读更多

Linux0.11内核中有很多函数都是在C语言里面声明,然后通过汇编来实现。例如/kernel/blk_drv/hd.c中函数中声明

extern void hd_interrupt (void);
但是其他C代码中没有实现,找了好久,终于知道它在汇编代码中实现了。
下面自己写了个简单的实例来证实
test.c代码
shixain.s代码

假如没有shixian.s代码,编译test.c会报错
test.c: In function ‘main’:
test.c:8: warning: format ‘%x’ expects type ‘unsigned int’, but argument 2 has type ‘void (*)(void)’
test.c:9: warning: format ‘%x’ expects type ‘unsigned int’, but argument 2 has type ‘void (*)(void)’
test.c:10: warning: format ‘%x’ expects type ‘unsigned int’, but argument 2 has type ‘void (*)(void)’
/tmp/ccqsI4JA.o: In function `main':
test.c:(.text+0x15): undefined reference to `test1'
test.c:(.text+0x29): undefined reference to `test2'
test.c:(.text+0x3d): undefined reference to `test3'
collect2: ld returned 1 exit status
但是加入汇编实现代码
命令:
as -gstabs -o shixian.o shixian.s
gcc -c -o test.o test.c
gcc -o result test.o shixian.o
编译生成可执行文件result
运行./result
结果:
0x8048440
0x8048443
0x8048446
注:在mingW下GCC和早期Linux版本下GCC,将汇编中的函数标号前加上_(一个下划线),而在如今的linux GCC下已不再加上_
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics