Saturday, April 2, 2016

C/C++ Function returns value through register A

Did you know? C/C++ functions return values through register A:

(Try on visual studio)

int Temp()
{
_asm
{
mov eax, 10
}
}

main()
{
int x = Temp();
cout<<x; //10
}

With the understanding that a micro-controller register is used for returning values, think what happens when you return primitive datatypes, pointers, references etc., from functions and how the function behaves!!