Tomaka17 wrote:
quok wrote:First, you cannot specify as clobbers registers that are used as inputs. If you take "edi" and "ecx" out from the clobber list, your error will go away.
Yes it goes away but still doesn't work
How is GCC supposed to know that "rep stosb" modified edi and ecx?
If I was GCC I would store a pointer to a structure into "edi", call memset and then use edi again to retreive some data from the structure
GCC doesn't know anything at all about asm, that's the whole point of specifying clobbers -- to tell GCC what changed. By default, anything specified as an input is also clobbered, so you only have to tell GCC about the things that you change specifically. If your asm template included "xor %%eax, %%eax" then you would have to specify eax as a clobber; gcc doesn't know anything at all about that asm statement. The constraints used (a, b, c, D, etc) tell GCC what register (technically register class) is being used.
For the example that you quoted, if GCC has something in edi already and then hits inline asm that says it will be putting something in edi, GCC throws a 'push edi' in front of the inline asm and will 'pop edi' afterward.
quok wrote:Second, you have no outputs, and you're not using volatile. Either of those will cause GCC to behave differently when using the optimizer. You should specify the asm as volatile, and specify _d as an output as well as an input (or just use the + modifier in front of it where it is).
Yeah I just noticed that
I was doing some tests with outputs as well, so I didn't notice that GCC was simply stripping the memset call
If you do not specify an output, when optimizing the code GCC may delete the asm entirely (this behavior may apply even if volatile is specified). If you do not specify an asm as volatile, then GCC may move the statement around (make it execute outside of a loop for instance). If you need the asm to execute exactly where it is, it MUST be declared volatile.
quok wrote:You may also want to use "cc" instead of "flags" as they're basically the same thing, but "cc" is more standard than "flags". (That may have changed in GCC 4.4.0 though; I haven't used it yet and unfortunately inline asm semantics change quite a bit from GCC version to GCC version.)
I was not sure about this because "cc" means "condition control" or something like that (like what is modified by "cmp" or "test")
But the "direction flag" is not really in this category
Instructions like cmp, test, jmp, etc all modify bits in EFLAGS like the carry flag, zero flag, sign flag, etc. CLD clears the direction flag. These bits (flags) are the same things as "condition codes". The different jmp instructions are generally referred to as jmpcc, because their behavior depends on the specific condition codes set in EFLAGS. CF, ZF, SF, and DF are all in EFLAGS, so it's rather safe to assume (and correct, as well), that DF fits in this category. Regardless though, if "flags" works then go ahead and use that.