Windows 64-bit assembly in C++

I saw an tutorial that teaches asm in C++. I saw in the video this code:
1
2
3
4
5
6
7
8
9
#include <iostream>
int GetASM()
{
    asm("mov %eax,1000");
}
int main()
{
    std::cout << GetASM();
}


But, when compiling and runing, my program instantly crashes. What am I doing wrong?
the meaning of the asm keyword http://en.cppreference.com/w/cpp/language/asm is different in every compiler - see links at the bottom of that page for some common ones,
closed account (13bSLyTq)
its equivalent to return 1000 in terms of C++
I know, but the program instantly crashes.
What compiler are you using? What compiler is the tutorial using? Are they the same?
@LB Nope. I use GNU GCC (MinGW), and the tutorial uses MSVC++, but I saw that using the GCC asm() and string literals results in the same. At least, should. Do you think that my asm code is correct?
No, Microsoft's inline assembly is completely different from GNU's inline assembly.
Can you help me? I'm just a assembly begginer. Do you haz teh codez? :P
Last edited on
In AT&T syntax it would be: asm("mov $1000, %eax");
Try it and tell us if it doesn't explode your computer.
Haha, funny (ironic).
Topic archived. No new replies allowed.