[Inline assembler] Sequential `asm` blocks and return via EAX

Alex Rønne Petersen xtzgzorex at gmail.com
Thu Mar 8 02:00:31 PST 2012


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.

-- 
- Alex


More information about the Digitalmars-d-learn mailing list