2010-10-01 189 views
1

我想将变量“userstack”的值移到ESP寄存器中,然后绝对跳转到变量“location”中包含的内存地址。 这是我的本钱:基本GCC内联汇编问题

// These are the two variables that contains memory addresses 
uint32_t location = current_running->LOCATION; 
uint32_t userstack = current_running->user_stack; 

// And then something like this 
__asm__ volatile ("movl userstack, %esp"); 
__asm__ volatile ("ljmp $0x0000, location"); 

然而,当我尝试编译我得到的错误: “错误:后缀或操作数LJMP无效”和“未定义的参考`userstack'”。

任何帮助将非常感激。

回答

1

看一看manual

我想你需要的东西是这样的:

asm volatile ("movl %0, %esp" : "g" (userstack)); 
asm volatile ("ljmp $0x0000, %0" : "g" (location)); 

基本上GCC需要知道什么,在哪里userstack和位置是(寄存器,内存操作数,浮点,限制寄存器的子集等)和这由“g”指定,在这种情况下表示一般操作数。