Skip to content

Instantly share code, notes, and snippets.

@abcsharp
Created June 3, 2012 09:13
Show Gist options
  • Save abcsharp/2862697 to your computer and use it in GitHub Desktop.
Save abcsharp/2862697 to your computer and use it in GitHub Desktop.
インラインアセンブラを使って書いた何か(VC++2010)
#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