2010-10-01 111 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」指定,在這種情況下表示一般操作數。