2011-06-03 106 views
2

我有另一種錯誤嘗試使用-fasm塊參數(這使英特爾風格彙編語法)與蘋果GCC 4.2.1編譯這在工作MSVC聯彙編代碼:塊組件的操作數沒有識別標籤 'LASM $ TYPE' 使用,但不限定GCC內聯彙編錯誤:塊組件操作不承認

typedef struct _MyStruct 
{ 
    int data; 
    //... 
}MyStruct; 

void testAsm() 
{ 
    MyStruct *pMyStruct = new MyStruct(); // Please not that I create an instance of MyStruct here only for the sake of simplicity 

    _asm 
    { 
     mov edi, pMyStruct 
     add edi, TYPE MyStruct // error: block assembly operand not recognized. label 'LASM$TYPE' used but not defined 
     //... 
    }; 

    delete pMyStruct; 
} 


我該如何解決這個問題?

+0

你究竟想要做什麼?我從來沒有在Visual C++中看到這樣的語法... – Goz 2011-06-03 09:58:45

+0

其實,這是我第一次看到它,我無法找到文檔,它會覆蓋它... – Ryan 2011-06-03 10:11:34

+0

我也遇到過這個問題 - 在另一個內聯彙編代碼中,使用了offset關鍵字:「mov eax,offset fptr」,其中fptr是一個函數「void fptr(void * pData)」...這次GCC報告錯誤「Block assembly operand not承認「:( – Ryan 2011-06-03 10:16:11

回答

1

TYPEMSVC-specificasm關鍵字。這裏只是表示sizeof。我試圖在網上找到一些gcc asm-block文檔,但是十分鐘後我放棄了。嘗試

add edi,sizeof(MyStruct) 

和變體。我沒有蘋果,所以我無法爲你嘗試。

更新回答在評論的問題:試試這個:

add edi,__offsetof(MyStruct,MyMember) 

如果它不能正常工作,請參閱"Using the GNU Compiler Collection"的文檔。

+0

謝謝,這似乎是工作!我還可以請你告訴我如何處理偏移關鍵字? – Ryan 2011-06-03 11:34:17

+0

@Ryan:見更新。 – TonyK 2011-06-03 11:52:43

+0

男子,我不能相信我錯過了... ...非常感謝,託尼! – Ryan 2011-06-03 12:11:13