clean up genDjnz for far data case; include same fix for mcs51 port.
[fw/sdcc] / src / ds390 / gen.c
index 184f88381300b91bbfd6d456baeb46248e2889fe..880b2e7452d59ddc928d8c39776cb369571a1db7 100644 (file)
@@ -9242,9 +9242,21 @@ genDjnz (iCode * ic, iCode * ifx)
        * the accumulator, we must explicitly write
        * it back after the decrement.
        */
-      emitcode ("dec", "%s",
-                 aopGet(AOP(IC_RESULT(ic)), 0, FALSE, FALSE, FALSE));
-      aopPut(AOP(IC_RESULT(ic)), "acc", 0);
+      char *rByte = aopGet(AOP(IC_RESULT(ic)), 0, FALSE, FALSE, TRUE);
+      
+      if (strcmp(rByte, "a"))
+      {
+           /* Something is hopelessly wrong */
+           fprintf(stderr, "*** warning: internal error at %s:%d\n",
+                  __FILE__, __LINE__);
+           /* We can just give up; the generated code will be inefficient,
+            * but what the hey.
+            */
+           freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+           return 0;
+      }
+      emitcode ("dec", "%s", rByte);
+      aopPut(AOP(IC_RESULT(ic)), rByte, 0);
       emitcode ("jnz", "%05d$", lbl->key + 100);
   }
   else if (IS_AOP_PREG (IC_RESULT (ic)))