Could someone please explain how DWordSwapAsm works without a return statement? I've ran the program with breakpoints and i gets changed even though there's no return value in that function.. how does this work?

NOTE: I don't want help with the assembly code, just the function itself.

template <typename T>
inline T DWordSwapAsm( T dw )
{
   __asm
   {
      mov eax, dw
      bswap eax
   }
}

int _tmain(int argc, _TCHAR* argv[])
{
	int i = 10;
	i = DWordSwapAsm( i );

	return 0;
}

Recommended Answers

All 2 Replies

It's because eax is used as the return value register.

If you look at the assembly for a normal function, you'll see a move TO eax when the function returns, and a move FROM eax in the caller, to assign the destination variable.

Ah, that makes sense now. Thanks for your reply.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.