digitalmars.D.learn - [Inline assembler] Sequential `asm` blocks and return via EAX
- Denis Shelomovskij (23/23) Mar 08 2012 1. Is there any guaranties that no code will be added between sequential...
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (7/30) Mar 08 2012 Probably not.
- Denis Shelomovskij (20/51) Mar 09 2012 All given answers looks like:
- James Miller (8/31) Mar 08 2012 For 1. I'd say that it would probably work, but you can't necessarily
- Daniel Murphy (5/18) Mar 08 2012 I'm pretty sure dmd splits up all asm block into bunches of asm statemen...
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (5/25) Mar 08 2012 I don't think it should be a formal language requirement either. It
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? } --- Is it documented? 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
Mar 08 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.htmlAs long as you follow whatever ABI your function uses (cdecl, stdcall, the D ABI, whatever), I don't see anything wrong with this. -- - Alex
Mar 08 2012
08.03.2012 14:00, Alex Rønne Petersen пишет:On 08-03-2012 10:42, Denis Shelomovskij wrote: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.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.htmlAs long as you follow whatever ABI your function uses (cdecl, stdcall, the D ABI, whatever), I don't see anything wrong with this.
Mar 09 2012
On 8 March 2012 22:42, Denis Shelomovskij <verylonglogin.reg gmail.com> wro= te:1. Is there any guaranties that no code will be added between sequential inline assembler blocks, e.g.: --- void f() { =C2=A0 =C2=A0static if(x) =C2=A0 =C2=A0 =C2=A0 =C2=A0asm { mov EBX, 3; } =C2=A0 =C2=A0else =C2=A0 =C2=A0 =C2=A0 =C2=A0asm { mov EBX, 7; } =C2=A0 =C2=A0asm { mov EAX, EBX; } // Is EBX value defined here? } --- Is it documented? 2. Such question about return via EAX (is the following use legal/documented): --- int g() { =C2=A0 =C2=A0asm { mov EAX, 4; } } --- Such use of `asm` to return a value is used here and there in http://dlang.org/iasm.htmlFor 1. I'd say that it would probably work, but you can't necessarily rely on that, you may have to live with a bit of code duplication. For 2. It seems that it should be fine, I can't check it right now, but I would be surprised if it didn't compile and run. -- James Miller
Mar 08 2012
"Denis Shelomovskij" <verylonglogin.reg gmail.com> wrote in message news:jj9uv1$8o$1 digitalmars.com...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? } --- Is it documented?I'm pretty sure dmd splits up all asm block into bunches of asm statements internally, so you should be able to rely on this. (dmd only) I don't think it's documented anywhere.
Mar 08 2012
On 08-03-2012 14:48, Daniel Murphy wrote:"Denis Shelomovskij"<verylonglogin.reg gmail.com> wrote in message news:jj9uv1$8o$1 digitalmars.com...I don't think it should be a formal language requirement either. It would be a rather harsh limitation on inline assembly implementations. -- - Alex1. 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? } --- Is it documented?I'm pretty sure dmd splits up all asm block into bunches of asm statements internally, so you should be able to rely on this. (dmd only) I don't think it's documented anywhere.
Mar 08 2012