greek_zjb 发表于 2006-3-14 08:03:01

求助c语言的内嵌汇编编译时的问题

:(
linux0.11源代码中内存管理处有一个关于分配一页空闲物理内存的函数get_free_page
源代码如下:(自己提炼了一下)

#define MEM_SIZE 15
#define LOW_MEM 0x100000
#define PAGING_MEM (MEM_SIZE*1024*1024)
#define PAGING_PAGES (PAGING_MEM>>12)

static unsigned char mem_map = {0};

unsigned long get_free_page()
{
register unsigned long __res asm("eax");

__asm__ ("std; repne; scasb\n\t"
"jne 1f\n\t"
"movb $1, 1(%%edi)\n\t"
//计算实际的物理地址
"sall $12, %%ecx\n\t"
"addl %2, %%ecx\n\t"
"movl %%ecx, %%edx\n\t" //物理地址存放在edx中
//清空所分配的内存
"movl $1024, %%ecx\n\t"
"leal 4092(%%edx), %%edi\n\t"
"rep; stosl\n\t"
"movl %%edx, %%eax\n"
"1:"
:"=a"(__res)
:""(0), "i"(LOW_MEM), "c"(PAGING_PAGES),
"D"(mem_map + PAGING_PAGES - 1)
:"di", "cx", "dx" );
return __res;
}
这段代码放在test.c文件中。
编译:
gcc -o test test.c
编译的结果如下:
test.c: In function `get_free_page':
test.c:13: warning: asm operand 1 probably doesn't match constraints
test.c:13: can't find a register in class `CREG' while reloading `asm'
不知道“can't find a register in class `CREG' while reloading `asm'”是什么错误
以及怎样才能使这段代码通过编译呢?
请大家指教!!
谢谢!!

VirusCamp 发表于 2006-3-14 10:12:18

linux0.11源代码不能用现在的 gcc 编译 ,下载 linux0.11源码的地方不同时提供了一个可以编译的gcc了.

greek_zjb 发表于 2006-3-14 22:07:22

哦,我找找。谢谢。
但是要是我想写可以用现在gcc编译的内嵌汇编那该怎么办呢?
页: [1]
查看完整版本: 求助c语言的内嵌汇编编译时的问题