I compile 64 bit program in Visual Studio 2015, it has two files:
2.asm
.code ;-------------------------------------------- Addup PROC, Arg1:DWORD, Arg2:DWORD, Arg3:DWORD mov eax, Arg1 add eax, Arg2 add eax, Arg3 ret Addup ENDP ;---------------------------------------------- END 1.cpp
#include <iostream> extern "C" int __stdcall Addup(int, int, int); int main() { std::cout << Addup(1, 1, 1); system("pause"); } The problem is that instead of the correct value of 3, the program displays some sort of garbage:
How to fix it? Thanks in advance.
Decision:
Here: msdn.microsoft.com/ru-ru/library/dd335933.aspx answer:
In the x64 agreement, the first four integer arguments (from left to right) are passed in 64-bit registers designed specifically for this purpose: RCX: 1st integer argument RDX: 2nd integer argument R8: 3rd integer argument R9: 4- th integer argument The remaining integer arguments are passed through the stack.
2.asm
.code ;-------------------------------------------- Addup PROC mov rax, rcx add rax, rdx add rax, r8 ret Addup ENDP ;---------------------------------------------- END 