digitalmars.D - Register Preservation in Inline ASM Blocks
- dsimcha <dsimcha yahoo.com> Nov 19 2010
- Walter Bright <newshound2 digitalmars.com> Nov 19 2010
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?
Nov 19 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.
Nov 19 2010








Walter Bright <newshound2 digitalmars.com>