Skip to content

Instantly share code, notes, and snippets.

@long-long-float
Created January 7, 2014 17:56
Show Gist options
  • Save long-long-float/8303549 to your computer and use it in GitHub Desktop.
Save long-long-float/8303549 to your computer and use it in GitHub Desktop.
"return" function
#include <stdio.h>
#include <cassert>
void _return(){
__asm{
pop ebp //フレームポインタ回収
pop ebp //_returnから脱出
pop ebp //呼び出し元のフレームポインタ回収
ret
}
}
void _return(int val){
__asm{
mov eax, dword ptr [ebp + 8] //返り値セット
pop ebp
pop ebp
add esp, 4 //呼び出し側の仕事
pop ebp
ret
}
}
void func1(){
_return();
assert(false);
return;
}
int func2(){
_return(10);
assert(false);
return -1;
}
int main(){
func1();
printf("%d\n", func2()); //=> 10
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment