diff --git a/.gitattributes b/.gitattributes
index 45c91254eb..be4580e7d0 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -6182,6 +6182,7 @@ tests/tbs/tb0519.pp svneol=native#text/plain
 tests/tbs/tb0520.pp svneol=native#text/plain
 tests/tbs/tb0521.pp svneol=native#text/plain
 tests/tbs/tb0522.pp svneol=native#text/plain
+tests/tbs/tb0523.pp svneol=native#text/plain
 tests/tbs/ub0060.pp svneol=native#text/plain
 tests/tbs/ub0069.pp svneol=native#text/plain
 tests/tbs/ub0119.pp svneol=native#text/plain
diff --git a/compiler/i386/i386tab.inc b/compiler/i386/i386tab.inc
index 4befdee5cd..c56cac36c8 100644
--- a/compiler/i386/i386tab.inc
+++ b/compiler/i386/i386tab.inc
@@ -6345,7 +6345,7 @@
   (
     opcode  : A_TEST;
     ops     : 2;
-    optypes : (ot_reg8,ot_memory,ot_none);
+    optypes : (ot_regmem or ot_bits8,ot_reg8,ot_none);
     code    : #193#211#1#132#72;
     flags   : if_8086 or if_sm
   ),
diff --git a/compiler/x86/x86ins.dat b/compiler/x86/x86ins.dat
index 18016eedac..8f1a088f4a 100644
--- a/compiler/x86/x86ins.dat
+++ b/compiler/x86/x86ins.dat
@@ -2020,7 +2020,7 @@ void                  \2\x0F\x07                      P6,PRIV,AMD
 regmem,reg16|32|64    \300\320\1\x85\101              8086,SM
 reg16|32|64,mem       \301\320\1\x85\110              8086,SM
 reg8,reg8             \300\323\1\x84\101              8086
-reg8,mem              \301\323\1\x84\110              8086,SM
+rm8,reg8              \301\323\1\x84\110              8086,SM
 reg_eax,imm           \325\1\xA9\41                   386,SM
 reg_ax,imm            \324\1\xA9\31                   8086,SM
 reg_al,imm            \1\xA8\21                       8086,SM
diff --git a/compiler/x86_64/x8664tab.inc b/compiler/x86_64/x8664tab.inc
index d603e34e1b..aa0077fdb6 100644
--- a/compiler/x86_64/x8664tab.inc
+++ b/compiler/x86_64/x8664tab.inc
@@ -6289,7 +6289,7 @@
   (
     opcode  : A_TEST;
     ops     : 2;
-    optypes : (ot_reg8,ot_memory,ot_none);
+    optypes : (ot_regmem or ot_bits8,ot_reg8,ot_none);
     code    : #193#211#1#132#72;
     flags   : if_8086 or if_sm
   ),
diff --git a/tests/tbs/tb0523.pp b/tests/tbs/tb0523.pp
new file mode 100644
index 0000000000..4b1545a7ce
--- /dev/null
+++ b/tests/tbs/tb0523.pp
@@ -0,0 +1,19 @@
+{ %target=i386 }
+{$asmmode intel}
+
+var
+  a : array[0..1] of byte;
+  myresult : boolean;
+begin
+  a[0]:=$ff;
+  a[1]:=$1;
+  asm
+    mov esi,offset a
+    mov dl,1
+    test byte ptr [esi+1], dl
+    setnz myresult
+  end;
+  if not(myresult) then
+    halt(1);
+  writeln('ok');
+end.