Browse Source

+ support LEA with 16-bit operand size

git-svn-id: trunk@25808 -
nickysn 11 years ago
parent
commit
4aa010eedc

+ 1 - 0
.gitattributes

@@ -11430,6 +11430,7 @@ tests/test/tisoread.pp svneol=native#text/pascal
 tests/test/tisorec1.pp svneol=native#text/pascal
 tests/test/tisorec2.pp svneol=native#text/pascal
 tests/test/tisorec3.pp svneol=native#text/pascal
+tests/test/tlea1.pp svneol=native#text/plain
 tests/test/tlib1a.pp svneol=native#text/plain
 tests/test/tlib1b.pp svneol=native#text/plain
 tests/test/tlib2a.pp svneol=native#text/plain

+ 2 - 2
compiler/i386/i386tab.inc

@@ -2649,14 +2649,14 @@
   (
     opcode  : A_LEA;
     ops     : 2;
-    optypes : (ot_reg32 or ot_bits64,ot_memory,ot_none,ot_none);
+    optypes : (ot_reg16 or ot_bits32 or ot_bits64,ot_memory,ot_none,ot_none);
     code    : #208#1#141#72;
     flags   : if_8086
   ),
   (
     opcode  : A_LEA;
     ops     : 2;
-    optypes : (ot_reg32 or ot_bits64,ot_immediate,ot_none,ot_none);
+    optypes : (ot_reg16 or ot_bits32 or ot_bits64,ot_immediate,ot_none,ot_none);
     code    : #208#1#141#72;
     flags   : if_8086 or if_sd
   ),

+ 2 - 2
compiler/i8086/i8086tab.inc

@@ -2649,14 +2649,14 @@
   (
     opcode  : A_LEA;
     ops     : 2;
-    optypes : (ot_reg32 or ot_bits64,ot_memory,ot_none,ot_none);
+    optypes : (ot_reg16 or ot_bits32 or ot_bits64,ot_memory,ot_none,ot_none);
     code    : #208#1#141#72;
     flags   : if_8086
   ),
   (
     opcode  : A_LEA;
     ops     : 2;
-    optypes : (ot_reg32 or ot_bits64,ot_immediate,ot_none,ot_none);
+    optypes : (ot_reg16 or ot_bits32 or ot_bits64,ot_immediate,ot_none,ot_none);
     code    : #208#1#141#72;
     flags   : if_8086 or if_sd
   ),

+ 2 - 2
compiler/x86/x86ins.dat

@@ -924,8 +924,8 @@ reg16|32,mem          \320\1\xC5\110                  8086,NOX86_64
 
 [LEA,leaX]
 (Ch_Wop2, Ch_Rop1, Ch_None)
-reg32|64,mem          \320\1\x8D\110                  8086
-reg32|64,imm          \320\1\x8D\110                  8086,SD
+reg16|32|64,mem          \320\1\x8D\110                  8086
+reg16|32|64,imm          \320\1\x8D\110                  8086,SD
 
 [LEAVE]
 (Ch_RWESP, Ch_WEBP, Ch_None)

+ 2 - 2
compiler/x86_64/x8664tab.inc

@@ -2544,14 +2544,14 @@
   (
     opcode  : A_LEA;
     ops     : 2;
-    optypes : (ot_reg32 or ot_bits64,ot_memory,ot_none,ot_none);
+    optypes : (ot_reg16 or ot_bits32 or ot_bits64,ot_memory,ot_none,ot_none);
     code    : #208#1#141#72;
     flags   : if_8086
   ),
   (
     opcode  : A_LEA;
     ops     : 2;
-    optypes : (ot_reg32 or ot_bits64,ot_immediate,ot_none,ot_none);
+    optypes : (ot_reg16 or ot_bits32 or ot_bits64,ot_immediate,ot_none,ot_none);
     code    : #208#1#141#72;
     flags   : if_8086 or if_sd
   ),

+ 87 - 0
tests/test/tlea1.pp

@@ -0,0 +1,87 @@
+{ %cpu=i386 }
+
+program tlea1;
+
+{$ASMMODE intel}
+
+procedure Fail;
+begin
+  Writeln('Error!');
+  Halt(1);
+end;
+
+procedure TestO32A32;
+var
+  res: DWord;
+begin
+  Writeln('Testing LEA with 32-bit operand size and 32-bit address size...');
+  asm
+    mov ecx, 0deadbeefh
+    mov edi, 0abcdefedh
+    mov ebx, 055667788h
+    lea ebx, [ecx + edi * 8 + 12345678h]
+    mov res, ebx
+  end ['EBX', 'ECX', 'EDI'];
+  if res <> $4F5194CF then
+    Fail;
+end;
+
+procedure TestO16A32;
+var
+  res: DWord;
+begin
+  Writeln('Testing LEA with 16-bit operand size and 32-bit address size...');
+  asm
+    mov ecx, 0deadbeefh
+    mov edi, 0abcdefedh
+    mov ebx, 055667788h
+    lea bx, [ecx + edi * 8 + 12345678h]
+    mov res, ebx
+  end ['EBX', 'ECX', 'EDI'];
+  if res <> $556694CF then
+    Fail;
+end;
+
+{$ifdef 16BITADDRSUPPORT}
+procedure TestO32A16;
+var
+  res: DWord;
+begin
+  Writeln('Testing LEA with 32-bit operand size and 16-bit address size...');
+  asm
+    mov ebx, 0deadbeefh
+    mov edi, 0abcdefedh
+    mov ecx, 055667788h
+    lea ecx, [bx + di + 1234h]
+    mov res, ecx
+  end ['EBX', 'ECX', 'EDI'];
+  if res <> $C110 then
+    Fail;
+end;
+
+procedure TestO16A16;
+var
+  res: DWord;
+begin
+  Writeln('Testing LEA with 16-bit operand size and 16-bit address size...');
+  asm
+    mov ebx, 0deadbeefh
+    mov edi, 0abcdefedh
+    mov ecx, 055667788h
+    lea cx, [bx + di + 1234h]
+    mov res, ecx
+  end ['EBX', 'ECX', 'EDI'];
+  if res <> $5566C110 then
+    Fail;
+end;
+{$endif 16BITADDRSUPPORT}
+
+begin
+  TestO32A32;
+  TestO16A32;
+{$ifdef 16BITADDRSUPPORT}
+  TestO32A16;
+  TestO16A16;
+{$endif 16BITADDRSUPPORT}
+  Writeln('Success!');
+end.