avoid using mrs
[cyclone68000.git] / OpArith.cpp
index ca279da..e956831 100644 (file)
@@ -45,19 +45,17 @@ int OpArith(int op)
 \r
   ot(";@ Do arithmetic:\n");\r
 \r
-  if (type==0) ot("  orr r1,r10,r0%s\n",shiftstr);\r
-  if (type==1) ot("  and r1,r10,r0%s\n",shiftstr);\r
+  if (type==0) ot("  orrs r1,r10,r0%s\n",shiftstr);\r
+  if (type==1) ot("  ands r1,r10,r0%s\n",shiftstr);\r
   if (type==2||type==6)\r
                ot("  rsbs r1,r10,r0%s ;@ Defines NZCV\n",shiftstr);\r
   if (type==3) ot("  adds r1,r10,r0%s ;@ Defines NZCV\n",shiftstr);\r
-  if (type==5) ot("  eor r1,r10,r0%s\n",shiftstr);\r
+  if (type==5) ot("  eors r1,r10,r0%s\n",shiftstr);\r
 \r
-  if (type<2 || type==5) ot("  adds r1,r1,#0 ;@ Defines NZ, clears CV\n"); // 0,1,5\r
-\r
-  if (type< 2) OpGetFlags(0,0); // Ori/And\r
+  if (type< 2) OpGetFlagsNZ(1); // Ori/And\r
   if (type==2) OpGetFlags(1,1); // Sub: Subtract/X-bit\r
   if (type==3) OpGetFlags(0,1); // Add: X-bit\r
-  if (type==5) OpGetFlags(0,0); // Eor\r
+  if (type==5) OpGetFlagsNZ(1); // Eor\r
   if (type==6) OpGetFlags(1,0); // Cmp: Subtract\r
   ot("\n");\r
 \r
@@ -182,9 +180,9 @@ int OpArithReg(int op)
   EaCalcReadNoSE(dir?-1:11,1,rea,size,0x0e00);\r
 \r
   ot(";@ Do arithmetic:\n");\r
-  if (type==0) strop = "orr";\r
+  if (type==0) strop = "orrs";\r
   if (type==1) strop = (char *) (dir ? "subs" : "rsbs");\r
-  if (type==4) strop = "and";\r
+  if (type==4) strop = "ands";\r
   if (type==5) strop = "adds";\r
 \r
   if (size==0) asl=",asl #24";\r
@@ -193,9 +191,8 @@ int OpArithReg(int op)
   if (size<2) ot("  mov r0,r0%s\n",asl);\r
   ot("  %s r1,r0,r1%s\n",strop,asl);\r
 \r
-  if ((type&1)==0) ot("  adds r1,r1,#0 ;@ Defines NZ, clears CV\n");\r
-\r
-  OpGetFlags(type==1,type&1); // 1==subtract\r
+  if (type&1) OpGetFlags(type==1,type&1); // add/subtract\r
+  else        OpGetFlagsNZ(1);\r
   ot("\n");\r
 \r
   ot(";@ Save result:\n");\r
@@ -327,9 +324,8 @@ int OpMul(int op)
       ot("\n");\r
     }\r
 \r
-    ot("  mov r1,r3,lsl #16 ;@ Clip to 16-bits\n");\r
-    ot("  adds r1,r1,#0 ;@ Defines NZ, clears CV\n");\r
-    OpGetFlags(0,0);\r
+    ot("  movs r1,r3,lsl #16 ;@ Clip to 16-bits\n");\r
+    OpGetFlagsNZ(1);\r
 \r
     ot("  mov r1,r1,lsr #16\n");\r
     ot("  orr r1,r1,r2,lsl #16 ;@ Insert remainder\n");\r
@@ -343,9 +339,8 @@ int OpMul(int op)
     ot("  mov r2,r2,%s #16\n",sign?"asr":"lsr");\r
     ot("\n");\r
 \r
-    ot("  mul r1,r2,r0\n");\r
-    ot("  adds r1,r1,#0 ;@ Defines NZ, clears CV\n");\r
-    OpGetFlags(0,0);\r
+    ot("  muls r1,r2,r0\n");\r
+    OpGetFlagsNZ(1);\r
   }\r
   ot("\n");\r
 \r
@@ -716,14 +711,16 @@ int OpCmpEor(int op)
   if (size<2) asl=(char *)(size?",asl #16":",asl #24");\r
 \r
   ot(";@ Do arithmetic:\n");\r
-  if (eor==0) ot("  rsbs r1,r0,r1%s\n",asl);\r
   if (eor)\r
   {\r
-    ot("  eor r1,r0,r1%s\n",asl);\r
-    ot("  adds r1,r1,#0 ;@ Defines NZ, clears CV\n");\r
+    ot("  eors r1,r0,r1%s\n",asl);\r
+    OpGetFlagsNZ(1);\r
+  }\r
+  else\r
+  {\r
+    ot("  rsbs r1,r0,r1%s\n",asl);\r
+    OpGetFlags(1,0); // Cmp like subtract\r
   }\r
-\r
-  OpGetFlags(eor==0,0); // Cmp like subtract\r
   ot("\n");\r
 \r
   if (eor) EaWrite(11, 1,ea,size,0x003f,1);\r
@@ -800,18 +797,18 @@ int OpChk(int op)
   EaCalcReadNoSE(-1,1,rea,size,0x0e00);\r
 \r
   if (size<2) ot("  mov r0,r0,asl #%d\n",size?16:24);\r
-  if (size<2) ot("  mov r1,r1,asl #%d\n\n",size?16:24);\r
+\r
+  if (size<2) ot("  movs r1,r1,asl #%d\n\n",size?16:24);\r
+  else        ot("  adds r1,r1,#0 ;@ Define flags\n");\r
 \r
   ot(";@ get flags, including undocumented ones\n");\r
   ot("  and r3,r10,#0x80000000\n");\r
-  ot("  adds r1,r1,#0 ;@ Defines NZ, clears CV\n");\r
-  OpGetFlags(0,0);\r
+  OpGetFlagsNZ(1);\r
 \r
   ot(";@ is reg negative?\n");\r
   ot("  bmi chktrap%.4x\n",op);\r
 \r
   ot(";@ Do arithmetic:\n");\r
-  ot("  bic r10,r10,#0x80000000 ;@ N\n");\r
   ot("  cmp r1,r0\n");\r
   ot("  bgt chktrap%.4x\n",op);\r
 \r