2011-11-25 48 views
3

我想使用AT & T語法使用內聯彙編分配數組。我想要實現類似以下的內容。請注意,rsp這裏是%rsp寄存器。使用AT&T語法訪問使用內聯彙編的數組

long saved_sp[N]; 
long new_sp[N]; 

void some_function(unsigned int tid, ...) 
{ 
// These two lines should be in assembly 
saved_sp[tid] = rsp; 
rsp = new_sp[tid]; 
...... 
} 

回答

3

我敢肯定,我不需要提醒你...

__asm__ __volatile__ (

    "movq %%rsp, (%0, %2, 8)\n\t" 
    "movq (%1, %2, 8), %%rsp\n\t" 

    : : "r" (saved_sp), "r" (new_sp), "r" ((long) tid)); 

也許「存儲器」應被添加爲撞,但它似乎有點多餘。無論你走到哪裏,都要記住幀指針「%rbp」將會失效。

+0

噢,好吧,我有你想要做的:)! – MetallicPriest