问题
I'm relatively new to x64 assembly and im using it in conjunction with VS2010. I'm struggling to get a handle on the return values from a proc and I can't really find quality documentation for beginners.
.data
MyByte db 10
.code
GetValueFromASM proc
mov rax, 28
mov rbx , 19
lea rax, MyByte
mov rax, 10
mov eax, 11
mov ecx, 100
ret
GetValueFromASM endp
end
The Ret instruction is printing out the value of eax in my c++ front end, is there some sort of default return register or can you specify it?
#include <iostream>
using namespace std;
extern "C" int GetValueFromASM();
int main()
{
cout << "sup, asm said " <<GetValueFromASM()<<endl;
cin.get();
return 0;
}
furthermore the instruction mov [reg], MyByte yields an error, how else do you put a variable into a register?
回答1:
ret doesn't change registers, it's not like the C return statement which takes an operand. It's the caller who expects the return value in register eax, according to the calling convention. Read about it on msdn.
mov [reg], MyByte would be a memory-to-memory move which is not supported and would not do what you wanted anyway. You probably want mov reg, MyByte without brackets so the value gets put into the register.
来源:https://stackoverflow.com/questions/22595010/x64-assembly-ret-register-and-variables