www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12730] New: lea instruction accepts subtraction of scaling

https://issues.dlang.org/show_bug.cgi?id=12730

          Issue ID: 12730
           Summary: lea instruction accepts subtraction of scaling
                    register but actually adds
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Keywords: iasm, wrong-code
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: dsimcha yahoo.com

I ran into this while erroneously thinking that the lea instruction can be used
for three-operand subtraction of a register from another, as well as addition
and for subtraction of an immediate.  DMD accepts this code, but actually
performs addition.

import std.stdio;

void main() {
    uint a = 1;
    uint b = 2;
    uint c;
    asm {
        mov EAX, a;
        mov EBX, b;
        lea ECX, [EBX - EAX];
        mov c, ECX;
    }

    writeln(c);  // Prints 3 on both 32-bit and 64-bit
}

--
May 10 2014