简体   繁体   中英

ASM In c++ project …How this little asm code will be in c++

Hellow I found an asm code... which was integrated in c++ project

template <class T>
T returned; 

BYTE *tem = buffer;
__asm
{
    mov eax, tem
    call eax
    mov  returned, eax
}

So As I don´t know asm It is hard To understood what this code means... Can anyone convert this ASM code in c++ entirely and post here:) Ttanks...

It looks like it is executing code placed in a buffer and returning the contents of the EAX register. You might try this:

typedef T (*pfn)();

returned = ((pfn) buffer)();

The assembly code is essentially treating tem as a function pointer and calling it. It is then putting the return into returned.

mov eax, tem;

The contents of tem is transferrer into the processor internal register eax

call eax

The contents of eax is used to make a function call. The code starting at the address which eax holds will be executed. After the function call returns the return value will be in the register eax

mov returned, eax

The return value in eax is transferred into a variable returned

This is what basically the code does. You shold have a look at the call instuction to know how exactly it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM