简体   繁体   English

从 ASM(64 位汇编)C++ 中获取价值

[英]Get Value From ASM (Assembly 64-bit) C++

I am having problems with Assembly & C++, I was just playing around and learning how to use Assembly in C++ but I couldn't seem to be able to get a function in asm to return the value I wanted it to.我在使用汇编和 C++ 时遇到问题,我只是在玩耍并学习如何在 C++ 中使用汇编,但我似乎无法在 asm 中获得一个函数来返回我想要的值。 My C++ code:我的 C++ 代码:

#include <iostream>

using namespace std;

extern "C" int GetValueFromASM();

int main()
{
    cout << GetValueFromASM();
    cin.ignore();
    return 0;
}

And my asm code in another file:我在另一个文件中的 asm 代码:

.code
GetValueFromASM proc
    move eax, 489
    ret
GetValueFromASM endp

end

The errors I recieve are我收到的错误是

Error2 error LNK1120: 1 unresolved externals    
Error1 error LNK2019: unresolved external symbol GetValueFromASM referenced in function main

I am using Visual Studio 2013 & and masm for the assembly & I selected x64 in the Configuration Manager, just some extra info there.我正在使用 Visual Studio 2013 & 和 masm 进行程序集 & 我在配置管理器中选择了 x64,那里只是一些额外的信息。

I would be very thankful for any help as I am new to asm.我会非常感谢任何帮助,因为我是 asm 的新手。

One way单程

You have to change this:你必须改变这个:

extern "C" int GetValueFromASM();

to his:给他的:

extern "C" int __stdcall GetValueFromASM();

Another way其他方式

Or in asm-file define this或者在 asm 文件中定义这个

.model flat, c

instead of this而不是这个

.model flat, stdcall

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM