asm code and an inout function argument

Denis Koroskin 2korden at gmail.com
Fri May 15 03:48:59 PDT 2009


On Fri, 15 May 2009 14:41:35 +0400, Vladimir A. Reznichenko <kalessil at gmail.com> wrote:

> Denis Koroskin Wrote:
>
>> On Fri, 15 May 2009 14:24:16 +0400, Vladimir A. Reznichenko  
>> <kalessil at gmail.com> wrote:
>>
>> > I have a function:
>> >
>> > void test (inout uint a)
>> > {
>> > 	asm
>> > 	{
>> > 		mov a, 0x25;
>> > 	}
>> > }
>> >
>> > The trouble is that the function's call doesn't change the a variable.
>> > Any ideas?
>> >
>>
>> I believe your code is incorrect. This is how it should be done:
>>
>> import std.stdio;
>>
>> void test (out uint a)
>> {
>>     asm
>>     {
>>         mov EDX, a;
>>         mov [EDX], 0x25;
>>     }
>> }
>>
>> void main()
>> {
>>     uint a = 0;
>>     test(a);
>>
>>     writefln("0x%x", a);
>> }
>>
>> Perhaps, errors like yours could be flagged at compile time? If so, an  
>> enhancement request would be nice.
>
>
> Thank you, Denis.

You are wellcome.

But I stand corrected - your original code was correct, it just didn't do what you expected (I replaced inout with pointer for clarity):

void test (uint* a)
{
    writefln("0x%x", a); // prints 0x12FE88, may differ
    asm {
        mov a, 0x25;
    }
    writefln("0x%x", a); // prints 0x25, i.e. you were modifying 'a', not '*a'
}

The following would be correct, but it is disallowed and silently ignored:
void test (uint* a)
{
    asm {
        mov [a], 0x25; // no warning is issued, works as if there were no brackets around a, is that correct behavior?
    }
}



More information about the Digitalmars-d mailing list