Created
June 3, 2012 09:13
-
-
Save abcsharp/2862697 to your computer and use it in GitHub Desktop.
インラインアセンブラを使って書いた何か(VC++2010)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
void swap(int& _a,int& _b) | |
{ | |
__asm{ | |
mov eax,dword ptr[_a] | |
mov ecx,[eax] | |
mov ebx,dword ptr[_b] | |
mov edx,[ebx] | |
mov [eax],edx | |
mov [ebx],ecx | |
} | |
return; | |
} | |
int main(void) | |
{ | |
int a=1,b=2; | |
std::cout<<"a="<<a<<",b="<<b<<std::endl; | |
std::cout<<"swap"<<std::endl; | |
__asm{ | |
lea eax,[b] | |
push eax | |
lea eax,[a] | |
push eax | |
call swap | |
add esp,8 | |
} | |
std::cout<<"a="<<a<<",b="<<b<<std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment