Ubuntu C内嵌汇编
刚开始使用C内嵌汇编,今天看了个小程序,代码如下:
1 #include <stdio.h>
2
3 void reboot()
4 {
5
6 asm
7 {
8 mov ax, 0ffffh
9 push ax
10 xor ax, ax
11 push ax
12 retf
13 }
14 }
15
16 void main()
17 {
18 printf("please press key to reboot.....\n");
19 getch();
20 reboot();
21 }
本程序的功能:
BIOS的起始地址是0FFFF:0000,将程序的执行跳转到这个地址就可以实现重启,但是编译出现如下问题:
gcc -o reboot reboot.c
reboot.c: In function ‘reboot’:
reboot.c:7: error: expected ‘(’ before ‘{’ token
reboot.c:8: error: ‘mov’ undeclared (first use in this function)
reboot.c:8: error: (Each undeclared identifier is reported only once
reboot.c:8: error: for each function it appears in.)
reboot.c:8: error: expected ‘;’ before ‘ax’
reboot.c:8:17: error: invalid suffix "ffffh" on integer constant
这大概是什么原因,头文件么?
[解决办法]
1. gcc的内联汇编与vc,写法不同。不是asm{ }。而是__asm()。这个你需要查一下gcc的手册。
2. gcc的内联汇编使用的是at&t汇编语法,而不是intel汇编语法。
[解决办法]
gcc 手册:
http://gcc.gnu.org/onlinedocs/