Bug 12730 – lea instruction accepts subtraction of scaling register but actually adds
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2014-05-11T04:17:12Z
Last change time
2020-08-10T22:19:55Z
Keywords
iasm, pull, wrong-code
Assigned to
No Owner
Creator
David Simcha
Comments
Comment #0 by dsimcha — 2014-05-11T04:17:12Z
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
}
Comment #1 by dlang-bot — 2020-08-10T08:56:22Z
@WalterBright created dlang/dmd pull request #11543 "fix Issue 12730 - lea instruction accepts subtraction of scaling regi…" fixing this issue:
- fix Issue 12730 - lea instruction accepts subtraction of scaling register but actually adds
https://github.com/dlang/dmd/pull/11543
Comment #2 by dlang-bot — 2020-08-10T22:19:55Z
dlang/dmd pull request #11543 "fix Issue 12730 - lea instruction accepts subtraction of scaling regi…" was merged into master:
- a17b5f44a19e2dff7e55cbfd4e78c34930158997 by Walter Bright:
fix Issue 12730 - lea instruction accepts subtraction of scaling register but actually adds
https://github.com/dlang/dmd/pull/11543