08.03.2012 14:00, Alex Rønne Petersen пишет:
On 08-03-2012 10:42, Denis Shelomovskij wrote:
1. Is there any guaranties that no code will be added between sequential
inline assembler blocks, e.g.:
---
void f()
{
static if(x)
asm { mov EBX, 3; }
else
asm { mov EBX, 7; }
asm { mov EAX, EBX; } // Is EBX value defined here?
}
I don't think you can rely on this.
---
Is it documented?
Probably not.
2. Such question about return via EAX (is the following use
legal/documented):
---
int g()
{
asm { mov EAX, 4; }
}
---
Such use of `asm` to return a value is used here and there in
http://dlang.org/iasm.html
As long as you follow whatever ABI your function uses (cdecl, stdcall,
the D ABI, whatever), I don't see anything wrong with this.
All given answers looks like:
---
int g()
{
asm { mov EAX, 4; }
}
---
will work and
---
int g()
{
asm { mov EAX, 4; }
asm { }
}
---
will not. I'm pretty sure returning value is like relying on saving
registers between sequential inline assembler blocks and even worse
because "end of function" is and action and there are no actions between
sequential inline assembler blocks.