Inline Assembly 井民全
Accessing C or C++ Data in __asm Blocks An __asm block can refer to any symbols Including variable name Ex: __asm mov eax, var Store the value of var in EAX
Accessing C or C++ Data in __asm Blocks Structure struct first_type { char *weasel; int same_name; }; struct second_type { int wonton; long same_name; }; struct first_type hal; struct second_type oat; void main(){ __asm{ mov ebx,offset hal mov eax,[ebx] weasel mov ebx,hal.same_name } // 狡滑的人 See AccessStructure.docAccessStructure.doc
Accessing C or C++ Data in __asm Blocks class See 03AccessClassDataMember.doc03AccessClassDataMember.doc
Calling C Function An __asm block can call C functions, including C library routines printf("%s %s\n","Hello","world"); See: Example1.cppExample1.cpp
Calling the User Defined Function int max(int a, int b) void main() { int a=1,b=2; int result; __asm{ push b push a call max pop ebx } int max(int a, int b) { return (a>b)?a:b; } But, how to get the return value ?
How to get the return value? int test(); void main() { __asm{ call test } int test() { int a=0x12; return a; } What ’ s happen in assembly Language?
Calling User Defined Function Observing the assembly The disassembly window
int max(int a, int b) void main() { int a=1,b=2; int result; __asm{ push b push a call max pop ebx mov result, eax } printf( “ result =%d ”,result); } int max(int a, int b) { return (a>b)?a:b; } Call_UserDefinedFunction.cpp
Calling C++ Function __asm block can only call global C++ functions that are not overloaded Cann ’ t call c++ member function