[Issue 701] New: Inline asm using incorrect offsets when used in inner function

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Dec 20 18:11:49 PST 2006


http://d.puremagic.com/issues/show_bug.cgi?id=701

           Summary: Inline asm using incorrect offsets when used in inner
                    function
           Product: D
           Version: 0.177
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: sean at f4.ca


I expect the following code:

    void main()
    {
        int i = 0;

        void fn()
        {
            asm
            {
                naked;
                lea EAX, i;
                mov [EAX], 42;
                ret;
            }
        }
        fn();
        printf( "i = %d\n", i );
    }

to print "42" but instead it prints "0".  This is because the assembler uses
the offset of 'i' that would be used within main() rather than adjusting for
the inner function.  Changing the code to this:

    void main()
    {
        int i = 0;

        void fn()
        {
            asm
            {
                naked;
                lea EAX, i;
                add EAX, 4;
                mov [EAX], 42;
                ret;
            }
        }
        fn();
        printf( "i = %d\n", i );
    }

Prints "42" as desired, but a manual adjustment of offsets should not be
necessary.  This is particulrly problematic in situations where "naked" is not
used, so the amount to adjust the offset by is not fixed.


-- 



More information about the Digitalmars-d-bugs mailing list