使用C++在Netbeans中进行内联汇编

Zac*_*Zac 1 c++ netbeans inline-assembly

我试图通过youtube上发布的一系列非常好的教程来学习汇编:

http://www.youtube.com/watch?v=guru397zg2g&list=PL0C5C980A28FEE68D&feature=plcp&context=C4ca8d4cFDvjVQa1PpcFM2reYRFji1sQFkiYY545AxtksGRUnLWSY=

我熟悉netbeans中的C++和Java编程,我正在使用MinGW编译器集.我在netbeans编译器属性中设置了我的C++和汇编编译器.

我的C++代码正在编译,但是使用_asm {}来尝试内联汇编代码并不能正确编译.

我收到的错误是:

main.cpp: In function 'int getValueFromASM()':

main.cpp:18:5: error: '_asm' was not declared in this scope

main.cpp:18:10: error: expected ';' before '{' token

make[2]: *** [build/Debug/MinGW_1-Windows/main.o] Error 1

make[1]: *** [.build-conf] Error 2

make: *** [.build-impl] Error 2
Run Code Online (Sandbox Code Playgroud)

代码是:

#include <cstdlib>
#include <iostream>

using namespace std;



int getValueFromASM()
{
    _asm {
        mov eax, 39
    }
}

int main(int argc, char** argv) {

    cout << "Hello World from C++ !\n";

    cout << "ASM said " << getValueFromASM() << endl;

    cout << "Back in the program before close.\n";

    return 0;

}
Run Code Online (Sandbox Code Playgroud)

有人能指出我如何让​​内联装配工作在netbeans中.

Kyl*_*utz 5

您收到编译错误,因为您使用了错误的语法.

尝试将您的getValueFromASM方法更改为:

int getValueFromASM()
{
    asm("mov $39, %eax");
}
Run Code Online (Sandbox Code Playgroud)

可以在此处找到有关GCC内联汇编的良好指南:http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html