* src/mcs51/gen.c (genCodePointerGet): inc dptr instead of loading acc
[fw/sdcc] / src / mcs51 / gen.c
index e8b5afaba5abf93112addd9f882e2f8953a2e29e..baaf26643a2f95900d80fe6bddb94813586b2bef 100644 (file)
@@ -954,13 +954,21 @@ aopOp (operand * op, iCode * ic, bool result)
 
       if (sym->usl.spillLoc)
         {
+          asmop *oldAsmOp = NULL;
+
           if (getSize(sym->type) != getSize(sym->usl.spillLoc->type))
             {
               /* force a new aop if sizes differ */
+              oldAsmOp = sym->usl.spillLoc->aop;
               sym->usl.spillLoc->aop = NULL;
             }
           sym->aop = op->aop = aop =
                      aopForSym (ic, sym->usl.spillLoc, result);
+          if (getSize(sym->type) != getSize(sym->usl.spillLoc->type))
+            {
+              /* Don't reuse the new aop, go with the last one */
+              sym->usl.spillLoc->aop = oldAsmOp;
+            }
           aop->size = getSize (sym->type);
           return;
         }
@@ -9860,21 +9868,12 @@ genCodePointerGet (operand * left,
 
       while (size--)
         {
-          if (pi)
-            {
-              emitcode ("clr", "a");
-              emitcode ("movc", "a,@a+dptr");
-              if (!ifx)
-              aopPut (result, "a", offset++, isOperandVolatile (result, FALSE));
-              emitcode ("inc", "dptr");
-            }
-          else
-            {
-              emitcode ("mov", "a,#0x%02x", offset);
-              emitcode ("movc", "a,@a+dptr");
-              if (!ifx)
-              aopPut (result, "a", offset++, isOperandVolatile (result, FALSE));
-            }
+          emitcode ("clr", "a");
+          emitcode ("movc", "a,@a+dptr");
+          if (!ifx)
+            aopPut (result, "a", offset++, isOperandVolatile (result, FALSE));
+          if (size || pi)
+            emitcode ("inc", "dptr");
         }
     }