Register Preservation in Inline ASM Blocks
Walter Bright
newshound2 at digitalmars.com
Fri Nov 19 17:22:53 PST 2010
dsimcha wrote:
> What is the rule on who is responsible for saving registers when inserting an
> inline ASM block into the middle of a function? For example:
>
> void fun() {
> auto ptr = somePointer();
> asm {
> mov EAX, ptr;
> lock;
> inc [EAX];
> }
> }
>
> Is this acceptable (will the compiler do what it needs to do to deal with my
> usage of EAX), or do I need to do something more like:
>
> asm {
> push EAX;
> lock;
> inc [EAX];
> pop EAX;
> }
>
> , leaving EAX exactly as I found it?
Unless you use 'naked' asm, the compiler will figure it out for you.
More information about the Digitalmars-d
mailing list