disable packRegsForOneuse until I can make it safe
[fw/sdcc] / src / ds390 / gen.c
index f24f651f402a77e6d4bccab061b1a4401206db7d..bc8cd0a2b48ce8bdc6f86bfe8642271aab06538a 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
-#include "SDCCglobl.h"
+
+#include <common.h>
+#include "ralloc.h"
+#include "gen.h"
 
 #ifdef HAVE_SYS_ISA_DEFS_H
 #include <sys/isa_defs.h>
 #endif
 #endif
 
-#include "common.h"
-#include "SDCCpeeph.h"
-#include "ralloc.h"
-#include "gen.h"
-
 char *aopLiteral (value *val, int offset);
+#if 0
+//REMOVE ME!!!
 extern int allocInfo;
+#endif
 
 /* this is the down and dirty file with all kinds of 
    kludgy & hacky stuff. This is what it is all about
@@ -82,10 +83,8 @@ static struct {
     set *sendSet;
 } _G;
 
-extern int ds390_ptrRegReq ;
-extern int ds390_nRegs;
-extern FILE *codeOutFile;
 static void saverbank (int, iCode *,bool);
+
 #define RESULTONSTACK(x) \
                          (IC_RESULT(x) && IC_RESULT(x)->aop && \
                          IC_RESULT(x)->aop->type == AOP_STK )
@@ -98,7 +97,8 @@ static void saverbank (int, iCode *,bool);
                  } \
                  free(_mova_tmp); \
                 }
-#define CLRC    emitcode("clr","c");
+#define CLRC    emitcode("clr","c")
+#define SETC    emitcode("setb","c")
 
 static lineNode *lineHead = NULL;
 static lineNode *lineCurr = NULL;
@@ -225,7 +225,7 @@ endOfWorld :
     /* other wise this is true end of the world */
     werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
            "getFreePtr should never reach here");
-    exit(0);
+    exit(1);
 }
 
 /*-----------------------------------------------------------------*/
@@ -240,20 +240,112 @@ static asmop *newAsmop (short type)
     return aop;
 }
 
+/* Turn this off if the world goes to hell. */
+#define LAZY_DPS_OPT
+
+static int _currentDPS;          /* Current processor DPS. */
+static int _desiredDPS;          /* DPS value compiler thinks we should be using. */
+static int _lazyDPS = 0;  /* if non-zero, we are doing lazy evaluation of DPS changes. */
+
+/*-----------------------------------------------------------------*/
+/* genSetDPTR: generate code to select which DPTR is in use (zero  */
+/* selects standard DPTR (DPL/DPH/DPX), non-zero selects DS390            */
+/* alternate DPTR (DPL1/DPH1/DPX1).                               */
+/*-----------------------------------------------------------------*/
 static void genSetDPTR(int n)
 {
+
+#ifdef LAZY_DPS_OPT
+    /* If we are doing lazy evaluation, simply note the desired
+     * change, but don't emit any code yet.
+     */
+    if (_lazyDPS)
+    {
+        _desiredDPS = n;
+        return;
+    }
+#endif
+
     if (!n)
     {
-        emitcode(";", "Select standard DPTR");
         emitcode("mov", "dps, #0x00");
     }
     else
     {
-        emitcode(";", "Select alternate DPTR");
         emitcode("mov", "dps, #0x01");
     }
 }
 
+/*-----------------------------------------------------------------*/
+/* _startLazyDPSEvaluation: call to start doing lazy DPS evaluation*/
+/*                                                                */
+/* Any code that operates on DPTR (NB: not on the individual      */
+/* components, like DPH) *must* call _flushLazyDPS() before using  */
+/* DPTR within a lazy DPS evaluation block.                       */
+/*                                                                */
+/* Note that aopPut and aopGet already contain the proper calls to */
+/* _flushLazyDPS, so it is safe to use these calls within a lazy   */
+/* DPS evaluation block.                                          */
+/*                                                                */
+/* Also, _flushLazyDPS must be called before any flow control     */
+/* operations that could potentially branch out of the block.     */
+/*                                                                */
+/* Lazy DPS evaluation is simply an optimization (though an       */
+/* important one), so if in doubt, leave it out.                  */
+/*-----------------------------------------------------------------*/
+static void _startLazyDPSEvaluation(void)
+{
+   _currentDPS = 0;
+   _desiredDPS = 0;
+   _lazyDPS = 1;
+}
+
+/*-----------------------------------------------------------------*/
+/* _flushLazyDPS: emit code to force the actual DPS setting to the */
+/* desired one. Call before using DPTR within a lazy DPS evaluation*/
+/* block.                                                         */
+/*-----------------------------------------------------------------*/
+static void _flushLazyDPS(void)
+{
+    if (!_lazyDPS)
+    {
+        /* nothing to do. */
+        return;
+    }
+    
+    if (_desiredDPS != _currentDPS)
+    {
+       if (_desiredDPS)
+       {
+           emitcode("inc", "dps");
+       }
+       else
+       {
+           emitcode("dec", "dps");
+       }
+       _currentDPS = _desiredDPS;
+    }
+}
+
+/*-----------------------------------------------------------------*/
+/* _endLazyDPSEvaluation: end lazy DPS evaluation block.          */
+/*                                                                */
+/* Forces us back to the safe state (standard DPTR selected).     */
+/*-----------------------------------------------------------------*/
+static void _endLazyDPSEvaluation(void)
+{
+   if (_currentDPS)
+   {
+       genSetDPTR(0);
+       _flushLazyDPS();
+   }
+   _lazyDPS = 0;
+   _currentDPS = 0;
+   _desiredDPS = 0;
+}
+
+
+
 /*-----------------------------------------------------------------*/
 /* pointerCode - returns the code for a pointer type               */
 /*-----------------------------------------------------------------*/
@@ -329,11 +421,11 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result, bool useDP2)
         
        if (useDP2)
        {        
-        genSetDPTR(1);
+        /* genSetDPTR(1); */
         emitcode ("mov","dpx1,#0x40");
         emitcode ("mov","dph1,#0x00");
         emitcode ("mov","dpl1, a");
-        genSetDPTR(0);
+        /* genSetDPTR(0); */
         }
         else
         {
@@ -380,7 +472,8 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result, bool useDP2)
     if (useDP2)
     {        
         genSetDPTR(1);
-    emitcode ("mov","dptr,#%s", sym->rname);
+        _flushLazyDPS();
+       emitcode ("mov","dptr,#%s", sym->rname);
         genSetDPTR(0);
     }    
     else
@@ -619,6 +712,15 @@ static void aopOp (operand *op, iCode *ic, bool result, bool useDP2)
 
         if (sym->ruonly ) {
             int i;
+            
+            if (useDP2)
+            {
+                /* a AOP_STR uses DPTR, but DPTR is already in use; 
+                 * we're just hosed.
+                 */
+                fprintf(stderr, "*** Internal error: AOP_STR with DPTR in use!\n");
+            }
+            
             aop = op->aop = sym->aop = newAsmop(AOP_STR);
             aop->size = getSize(sym->type);
             for ( i = 0 ; i < fReturnSize_390 ; i++ )
@@ -742,10 +844,19 @@ dealloc:
     }
 }
 
-/*-----------------------------------------------------------------*/
-/* aopGet - for fetching value of the aop                          */
-/*-----------------------------------------------------------------*/
-static char *aopGet (asmop *aop, int offset, bool bit16, bool dname)
+/*------------------------------------------------------------------*/
+/* aopGet - for fetching value of the aop                           */
+/*                                                                 */
+/* Set canClobberACC if you are aure it is OK to clobber the value  */
+/* in the accumulator. Set it FALSE otherwise; FALSE is always safe,*/
+/* just less efficient.                                                    */
+/*------------------------------------------------------------------*/
+
+static char *aopGet (asmop *aop, 
+                    int offset, 
+                    bool bit16,
+                    bool dname,
+                    bool canClobberACC)
 {
     char *s = buffer ;
     char *rs;
@@ -785,11 +896,19 @@ static char *aopGet (asmop *aop, int offset, bool bit16, bool dname)
     case AOP_DPTR:
     case AOP_DPTR2:
     
-    if (aop->type == AOP_DPTR2)
-    {
-        genSetDPTR(1);
-        emitcode("xch", "a, ap");
-    }
+       if (aop->type == AOP_DPTR2)
+       {
+            genSetDPTR(1);
+        
+#ifndef KEVIN_BROKE_IT        
+            if (!canClobberACC)
+#endif        
+            {
+               emitcode("xch", "a, ap");
+            }
+       }
+    
+       _flushLazyDPS();
     
        while (offset > aop->coff) {
            emitcode ("inc","dptr");
@@ -806,19 +925,24 @@ static char *aopGet (asmop *aop, int offset, bool bit16, bool dname)
            emitcode("clr","a");
            emitcode("movc","a,@a+dptr");
         }
-    else {
+       else {
            emitcode("movx","a,@dptr");
-    }
+       }
            
-    if (aop->type == AOP_DPTR2)
-    {
-        emitcode("xch", "a, ap");
-        genSetDPTR(0);
-        return "ap";
-    }
+       if (aop->type == AOP_DPTR2)
+       {
+           genSetDPTR(0);
+
+#ifndef KEVIN_BROKE_IT        
+            if (!canClobberACC)
+#endif        
+            {
+               emitcode("xch", "a, ap");
+               return "ap";
+            }
+       }
            
-    return (dname ? "acc" : "a");
-       
+       return (dname ? "acc" : "a");
        
     case AOP_IMMD:
        if (bit16) 
@@ -878,7 +1002,7 @@ static char *aopGet (asmop *aop, int offset, bool bit16, bool dname)
 
     werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
            "aopget got unsupported aop->type");
-    exit(0);
+    exit(1);
 }
 /*-----------------------------------------------------------------*/
 /* aopPut - puts a string for a aop                                */
@@ -891,7 +1015,7 @@ static void aopPut (asmop *aop, char *s, int offset)
     if (aop->size && offset > ( aop->size - 1)) {
         werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
                "aopPut got offset > aop->size");
-        exit(0);
+        exit(1);
     }
 
     /* will assign value to value */
@@ -932,15 +1056,16 @@ static void aopPut (asmop *aop, char *s, int offset)
     case AOP_DPTR:
     case AOP_DPTR2:
     
-    if (aop->type == AOP_DPTR2)
-    {
-        genSetDPTR(1);
-    }
+       if (aop->type == AOP_DPTR2)
+       {
+            genSetDPTR(1);
+       }
+       _flushLazyDPS();
     
        if (aop->code) {
            werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
                   "aopPut writting to code space");
-           exit(0);
+           exit(1);
        }
        
        while (offset > aop->coff) {
@@ -960,10 +1085,10 @@ static void aopPut (asmop *aop, char *s, int offset)
        
        emitcode ("movx","@dptr,a");
        
-    if (aop->type == AOP_DPTR2)
-    {
-        genSetDPTR(0);
-    }
+       if (aop->type == AOP_DPTR2)
+       {
+            genSetDPTR(0);
+       }
        break;
        
     case AOP_R0:
@@ -1059,38 +1184,12 @@ static void aopPut (asmop *aop, char *s, int offset)
     default :
        werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
               "aopPut got unsupported aop->type");
-       exit(0);    
+       exit(1);    
     }    
 
 }
 
 
-#if 0
-/*-----------------------------------------------------------------*/
-/* pointToEnd :- points to the last byte of the operand            */
-/*-----------------------------------------------------------------*/
-static void pointToEnd (asmop *aop)
-{
-    int count ;
-    if (!aop)
-        return ;
-
-    aop->coff = count = (aop->size - 1);
-    switch (aop->type) {
-        case AOP_R0 :
-        case AOP_R1 :
-            while (count--)
-                emitcode("inc","%s",aop->aopu.aop_ptr->name);
-            break;
-        case AOP_DPTR :
-            while (count--)
-                emitcode("inc","dptr");
-            break;
-    }
-
-}
-#endif
-
 /*-----------------------------------------------------------------*/
 /* reAdjustPreg - points a register back to where it should        */
 /*-----------------------------------------------------------------*/
@@ -1113,6 +1212,7 @@ static void reAdjustPreg (asmop *aop)
             if (aop->type == AOP_DPTR2)
            {
                 genSetDPTR(1);
+                _flushLazyDPS();
            } 
             while (size--)
             {
@@ -1143,6 +1243,33 @@ static void reAdjustPreg (asmop *aop)
                       (x->aopu.aop_reg[0] == ds390_regWithIdx(R0_IDX) || \
                       x->aopu.aop_reg[0] == ds390_regWithIdx(R1_IDX) )))
 
+/* Workaround for DS80C390 bug: div ab may return bogus results
+ * if A is accessed in instruction immediately before the div.
+ *
+ * Will be fixed in B4 rev of processor, Dallas claims.
+ */
+#define LOAD_AB_FOR_DIV(LEFT, RIGHT, L)                        \
+    if (!AOP_NEEDSACC(RIGHT))                                  \
+    {                                                          \
+       /* We can load A first, then B, since                   \
+        * B (the RIGHT operand) won't clobber A,               \
+        * thus avoiding touching A right before the div.       \
+        */                                                     \
+       D(emitcode(";", "DS80C390 div bug: rearranged ops.");); \
+       L = aopGet(AOP(LEFT),0,FALSE,FALSE,TRUE);               \
+       MOVA(L);                                                \
+       emitcode("mov","b,%s",aopGet(AOP(RIGHT),0,FALSE,FALSE,FALSE));\
+    }                                                          \
+    else                                                       \
+    {                                                          \
+       /* Just stuff in a nop after loading A. */              \
+       emitcode("mov","b,%s",aopGet(AOP(RIGHT),0,FALSE,FALSE,FALSE));\
+       L = aopGet(AOP(LEFT),0,FALSE,FALSE,TRUE);               \
+       MOVA(L);                                                \
+       emitcode("nop", "; workaround for DS80C390 div bug.");  \
+    }
+
 /*-----------------------------------------------------------------*/
 /* genNotFloat - generates not for float operations              */
 /*-----------------------------------------------------------------*/
@@ -1160,14 +1287,16 @@ static void genNotFloat (operand *op, operand *res)
     size = AOP_SIZE(op) - 1;
     offset = 1;
 
-    l = aopGet(op->aop,offset++,FALSE,FALSE);
+    _startLazyDPSEvaluation();
+    l = aopGet(op->aop,offset++,FALSE,FALSE,TRUE);
     MOVA(l);    
 
     while(size--) {
         emitcode("orl","a,%s",
                  aopGet(op->aop,
-                        offset++,FALSE,FALSE));
+                        offset++,FALSE,FALSE,FALSE));
     }
+    _endLazyDPSEvaluation();
     tlbl = newiTempLabel(NULL);
 
     tlbl = newiTempLabel(NULL);
@@ -1260,26 +1389,39 @@ static void toBoolean(operand *oper)
     int size = AOP_SIZE(oper) - 1;
     int offset = 1;
 
+    /* The generic part of a generic pointer should
+     * not participate in it's truth value.
+     *
+     * i.e. 0x10000000 is zero.
+     */
+    if (opIsGptr(oper))
+    {
+       D(emitcode(";", "toBoolean: generic ptr special case."););
+               size--;
+    }
+
+    _startLazyDPSEvaluation();
     if (AOP_NEEDSACC(oper))
     {
         emitcode("push", "b");
-        emitcode("mov", "b, %s", aopGet(AOP(oper),0,FALSE,FALSE));
+        emitcode("mov", "b, %s", aopGet(AOP(oper),0,FALSE,FALSE,FALSE));
     }
     else
     {
-    MOVA(aopGet(AOP(oper),0,FALSE,FALSE));
+       MOVA(aopGet(AOP(oper),0,FALSE,FALSE,TRUE));
     }
     while (size--) 
     {
        if (AOP_NEEDSACC(oper))
        {
-           emitcode("orl","b,%s",aopGet(AOP(oper),offset++,FALSE,FALSE));
+           emitcode("orl","b,%s",aopGet(AOP(oper),offset++,FALSE,FALSE,FALSE));
        }
        else
        {
-        emitcode("orl","a,%s",aopGet(AOP(oper),offset++,FALSE,FALSE));
-}
+            emitcode("orl","a,%s",aopGet(AOP(oper),offset++,FALSE,FALSE,FALSE));
+       }
     }
+    _endLazyDPSEvaluation();
     
     if (AOP_NEEDSACC(oper))
     {
@@ -1358,12 +1500,14 @@ static void genCpl (iCode *ic)
     } 
 
     size = AOP_SIZE(IC_RESULT(ic));
+    _startLazyDPSEvaluation();
     while (size--) {
-        char *l = aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE);
+        char *l = aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE,TRUE);
         MOVA(l);       
         emitcode("cpl","a");
         aopPut(AOP(IC_RESULT(ic)),"a",offset++);
     }
+    _endLazyDPSEvaluation();
 
 
 release:
@@ -1381,11 +1525,11 @@ static void genUminusFloat(operand *op,operand *result)
     char *l;
     /* for this we just need to flip the 
     first it then copy the rest in place */
-    size = AOP_SIZE(op) - 1;
-    l = aopGet(AOP(op),3,FALSE,FALSE);
-
     D(emitcode(";", "genUminusFloat"););
-
+    
+    _startLazyDPSEvaluation();
+    size = AOP_SIZE(op) - 1;
+    l = aopGet(AOP(op),3,FALSE,FALSE,TRUE);
     MOVA(l);    
 
     emitcode("cpl","acc.7");
@@ -1393,10 +1537,11 @@ static void genUminusFloat(operand *op,operand *result)
 
     while(size--) {
         aopPut(AOP(result),
-               aopGet(AOP(op),offset,FALSE,FALSE),
+               aopGet(AOP(op),offset,FALSE,FALSE,FALSE),
                offset);
         offset++;
-    }          
+    }
+    _endLazyDPSEvaluation();
 }
 
 /*-----------------------------------------------------------------*/
@@ -1437,18 +1582,23 @@ static void genUminus (iCode *ic)
     /* otherwise subtract from zero */
     size = AOP_SIZE(IC_LEFT(ic));
     offset = 0 ;
-    CLRC ;
+    _startLazyDPSEvaluation();
     while(size--) {
-        char *l = aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE);
+        char *l = aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE,TRUE);
         if (!strcmp(l,"a")) {
-            emitcode("cpl","a");
-            emitcode("inc","a");
+         if (offset==0)
+           SETC;
+         emitcode("cpl","a");
+         emitcode("addc", "a,#0");
         } else {
-            emitcode("clr","a");
-            emitcode("subb","a,%s",l);
+         if (offset==0)
+           CLRC;
+         emitcode("clr","a");
+         emitcode("subb","a,%s",l);
         }       
         aopPut(AOP(IC_RESULT(ic)),"a",offset++);
     }
+    _endLazyDPSEvaluation();
 
     /* if any remaining bytes in the result */
     /* we just need to propagate the sign   */
@@ -1571,8 +1721,9 @@ static void unsaveRegisters (iCode *ic)
 static void pushSide(operand * oper, int size)
 {
        int offset = 0;
+       _startLazyDPSEvaluation();
        while (size--) {
-               char *l = aopGet(AOP(oper),offset++,FALSE,TRUE);
+               char *l = aopGet(AOP(oper),offset++,FALSE,TRUE,FALSE);
                if (AOP_TYPE(oper) != AOP_REG &&
                    AOP_TYPE(oper) != AOP_DIR &&
                    strcmp(l,"a") ) {
@@ -1581,6 +1732,7 @@ static void pushSide(operand * oper, int size)
                } else
                        emitcode("push","%s",l);
        }
+       _endLazyDPSEvaluation();
 }
 
 /*-----------------------------------------------------------------*/
@@ -1590,10 +1742,13 @@ static void assignResultValue(operand * oper)
 {
        int offset = 0;
        int size = AOP_SIZE(oper);
+       
+       _startLazyDPSEvaluation();
        while (size--) {
                aopPut(AOP(oper),fReturn[offset],offset);
                offset++;
        }
+       _endLazyDPSEvaluation();
 }
 
 
@@ -1615,15 +1770,17 @@ static void genXpush (iCode *ic)
     emitcode("mov","%s,_spx",r->name);
 
     size = AOP_SIZE(IC_LEFT(ic));
+    _startLazyDPSEvaluation();
     while(size--) {
 
        char *l = aopGet(AOP(IC_LEFT(ic)),
-                        offset++,FALSE,FALSE); 
+                        offset++,FALSE,FALSE,TRUE);    
        MOVA(l);            
        emitcode("movx","@%s,a",r->name);       
        emitcode("inc","%s",r->name);
 
     }
+    _endLazyDPSEvaluation();
 
        
     emitcode("mov","_spx,%s",r->name);
@@ -1654,14 +1811,16 @@ static void genIpush (iCode *ic)
         aopOp(IC_LEFT(ic),ic,FALSE, FALSE);
         size = AOP_SIZE(IC_LEFT(ic));
         /* push it on the stack */
+        _startLazyDPSEvaluation();
         while(size--) {
-            l = aopGet(AOP(IC_LEFT(ic)),offset++,FALSE,TRUE);
+            l = aopGet(AOP(IC_LEFT(ic)),offset++,FALSE,TRUE,TRUE);
             if (*l == '#') {
                 MOVA(l);
                 l = "acc";
             }
             emitcode("push","%s",l);
         }
+        _endLazyDPSEvaluation();
         return ;        
     }
 
@@ -1680,12 +1839,12 @@ static void genIpush (iCode *ic)
     /* then do the push */
     aopOp(IC_LEFT(ic),ic,FALSE, FALSE);
 
-
-       // pushSide(IC_LEFT(ic), AOP_SIZE(IC_LEFT(ic)));
+    // pushSide(IC_LEFT(ic), AOP_SIZE(IC_LEFT(ic)));
     size = AOP_SIZE(IC_LEFT(ic));
 
+    _startLazyDPSEvaluation();
     while (size--) {
-        l = aopGet(AOP(IC_LEFT(ic)),offset++,FALSE,TRUE);
+        l = aopGet(AOP(IC_LEFT(ic)),offset++,FALSE,TRUE,FALSE);
         if (AOP_TYPE(IC_LEFT(ic)) != AOP_REG && 
             AOP_TYPE(IC_LEFT(ic)) != AOP_DIR &&
             strcmp(l,"a") ) {
@@ -1693,7 +1852,8 @@ static void genIpush (iCode *ic)
             emitcode("push","acc");
         } else
             emitcode("push","%s",l);
-    }       
+    }
+    _endLazyDPSEvaluation();
 
     freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
 }
@@ -1715,9 +1875,13 @@ static void genIpop (iCode *ic)
     aopOp(IC_LEFT(ic),ic,FALSE, FALSE);
     size = AOP_SIZE(IC_LEFT(ic));
     offset = (size-1);
-    while (size--) 
+    _startLazyDPSEvaluation();
+    while (size--)
+    {
         emitcode("pop","%s",aopGet(AOP(IC_LEFT(ic)),offset--,
-                                   FALSE,TRUE));
+                                   FALSE,TRUE,TRUE));
+    }
+    _endLazyDPSEvaluation();
 
     freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
 }
@@ -1840,19 +2004,24 @@ static void genCall (iCode *ic)
        iCode *sic ;
 
        for (sic = setFirstItem(_G.sendSet) ; sic ; 
-            sic = setNextItem(_G.sendSet)) {
+            sic = setNextItem(_G.sendSet)) 
+       {
            int size, offset = 0;
-        aopOp(IC_LEFT(sic),sic,FALSE, TRUE);
+        
+            aopOp(IC_LEFT(sic),sic,FALSE, TRUE);
            size = AOP_SIZE(IC_LEFT(sic));
+           
+           _startLazyDPSEvaluation();
            while (size--) {
                char *l = aopGet(AOP(IC_LEFT(sic)),offset,
-                               FALSE, FALSE);
+                               FALSE, FALSE, TRUE);
                if (strcmp(l,fReturn[offset]))
                    emitcode("mov","%s,%s",
                             fReturn[offset],
                             l);
                offset++;
            }
+           _endLazyDPSEvaluation();
            freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
        }
        _G.sendSet = NULL;
@@ -1868,16 +2037,57 @@ static void genCall (iCode *ic)
           OP_SYMBOL(IC_RESULT(ic))->spildir )) ||
         IS_TRUE_SYMOP(IC_RESULT(ic)) ) {
 
+#ifdef LAZY_DPS_OPT
+       /* Not really related to LAZY_DPS_OPT, but don't want
+        * another testing flag right now...
+        */
+#define FAR_RETURN_OPT
+#ifdef FAR_RETURN_OPT   
+       if (isOperandInFarSpace(IC_RESULT(ic))
+        && getSize(operandType(IC_RESULT(ic))) <= 2)
+       {
+           int size =  getSize(operandType(IC_RESULT(ic)));
+           
+            /* Special case for 1 or 2 byte return in far space. */
+           emitcode(";", "Kevin function call abuse #1");
+
+           MOVA(fReturn[0]);
+           if (size > 1)
+           {
+               emitcode("mov", "b,%s", fReturn[1]);
+           }
+    
+           aopOp(IC_RESULT(ic),ic,FALSE, FALSE);
+           aopPut(AOP(IC_RESULT(ic)),"a",0);
+           
+           if (size > 1)
+           {
+               aopPut(AOP(IC_RESULT(ic)),"b",1);
+           }
+           freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);           
+       }
+       else
+#endif 
+       {
+            _G.accInUse++;
+            aopOp(IC_RESULT(ic),ic,FALSE, TRUE);
+            _G.accInUse--;
+                                     
+            assignResultValue(IC_RESULT(ic));
+                                                  
+            freeAsmop(IC_RESULT(ic),NULL, ic,TRUE);
+        }
+#else
        if (!isOperandInFarSpace(IC_RESULT(ic)))
        {
-        _G.accInUse++;
+            _G.accInUse++;
             aopOp(IC_RESULT(ic),ic,FALSE, FALSE);
-        _G.accInUse--;
+            _G.accInUse--;
 
-       assignResultValue(IC_RESULT(ic));
+           assignResultValue(IC_RESULT(ic));
                
-        freeAsmop(IC_RESULT(ic),NULL, ic,TRUE);
-    }
+            freeAsmop(IC_RESULT(ic),NULL, ic,TRUE);
+       }
         else
         {
             /* Result is in far space, and requires DPTR to access
@@ -1910,7 +2120,8 @@ static void genCall (iCode *ic)
                aopPut(AOP(IC_RESULT(ic)),"a",++offset);
            }
            freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
-        }
+       }
+#endif 
     }
 
     /* adjust the stack for parameters if 
@@ -1987,22 +2198,29 @@ static void genPcall (iCode *ic)
        iCode *sic ;
 
        for (sic = setFirstItem(_G.sendSet) ; sic ; 
-            sic = setNextItem(_G.sendSet)) {
-           int size, offset = 0;
-           aopOp(IC_LEFT(sic),sic,FALSE, FALSE);
-           size = AOP_SIZE(IC_LEFT(sic));
-           while (size--) {
-               char *l = aopGet(AOP(IC_LEFT(sic)),offset,
-                               FALSE,FALSE);
-               if (strcmp(l,fReturn[offset]))
-                   emitcode("mov","%s,%s",
-                            fReturn[offset],
-                            l);
-               offset++;
+            sic = setNextItem(_G.sendSet)) 
+            {
+               int size, offset = 0;
+           
+               aopOp(IC_LEFT(sic),sic,FALSE, FALSE);
+               size = AOP_SIZE(IC_LEFT(sic));
+               _startLazyDPSEvaluation();
+               while (size--) 
+               {
+                       char *l = aopGet(AOP(IC_LEFT(sic)),offset,
+                                        FALSE,FALSE,TRUE);
+                       if (strcmp(l,fReturn[offset]))
+                       {
+                               emitcode("mov","%s,%s",
+                                        fReturn[offset],
+                                        l);
+                       }
+                       offset++;
+               }
+               _endLazyDPSEvaluation();
+               freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
            }
-           freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
-       }
-       _G.sendSet = NULL;
+           _G.sendSet = NULL;
     }
 
     emitcode("ret","");
@@ -2429,21 +2647,22 @@ static void genRet (iCode *ic)
     aopOp(IC_LEFT(ic),ic,FALSE, TRUE);
     size = AOP_SIZE(IC_LEFT(ic));
     
+    _startLazyDPSEvaluation();
     while (size--) {
            char *l ;
            if (AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR) {
-                   /* #NOCHANGE */
                    l = aopGet(AOP(IC_LEFT(ic)),offset++,
-                          FALSE,TRUE);
+                          FALSE,TRUE,FALSE);
                    emitcode("push","%s",l);
                    pushed++;
            } else {
                    l = aopGet(AOP(IC_LEFT(ic)),offset,
-                              FALSE,FALSE);
+                              FALSE,FALSE,FALSE);
                    if (strcmp(fReturn[offset],l))
                            emitcode("mov","%s,%s",fReturn[offset++],l);
            }
-    }    
+    }
+    _endLazyDPSEvaluation();    
 
     if (pushed) {
        while(pushed) {
@@ -2545,14 +2764,14 @@ static bool genPlusIncr (iCode *ic)
         int labelRange;
 
        /* If the next instruction is a goto and the goto target
-        * is < 10 instructions previous to this, we can generate
+        * is <= 5 instructions previous to this, we can generate
         * jumps straight to that target.
         */
         if (ic->next && ic->next->op == GOTO
             && (labelRange = findLabelBackwards(ic, IC_LABEL(ic->next)->key)) != 0
-            && labelRange <= 10 )
+            && labelRange <= 5 )
         {
-           emitcode(";", "tail increment optimized");
+           emitcode(";", "tail increment optimized (range %d)", labelRange);
            tlbl = IC_LABEL(ic->next);
            emitTlbl = 0;
         }
@@ -2561,47 +2780,47 @@ static bool genPlusIncr (iCode *ic)
             tlbl = newiTempLabel(NULL);
             emitTlbl = 1;
         }
-       emitcode("inc","%s",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
+       emitcode("inc","%s",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE,FALSE));
        if(AOP_TYPE(IC_RESULT(ic)) == AOP_REG ||
           IS_AOP_PREG(IC_RESULT(ic)))
            emitcode("cjne","%s,#0x00,%05d$"
-                    ,aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE)
+                    ,aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE,FALSE)
                     ,tlbl->key+100);
        else {
            emitcode("clr","a");
            emitcode("cjne","a,%s,%05d$"
-                    ,aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE)
+                    ,aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE,FALSE)
                     ,tlbl->key+100);
        }
     
-       emitcode("inc","%s",aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE));
+       emitcode("inc","%s",aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE,FALSE));
        if (size > 2)
        {
            if(AOP_TYPE(IC_RESULT(ic)) == AOP_REG ||
               IS_AOP_PREG(IC_RESULT(ic)))
                emitcode("cjne","%s,#0x00,%05d$"
-                        ,aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE)
+                        ,aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE,FALSE)
                         ,tlbl->key+100);
            else
                emitcode("cjne","a,%s,%05d$"
-                        ,aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE)
+                        ,aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE,FALSE)
                         ,tlbl->key+100);
            
-           emitcode("inc","%s",aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE));
+           emitcode("inc","%s",aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE,FALSE));
        }
        if (size > 3)
        {
            if(AOP_TYPE(IC_RESULT(ic)) == AOP_REG ||
               IS_AOP_PREG(IC_RESULT(ic)))
                emitcode("cjne","%s,#0x00,%05d$"
-                        ,aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE)
+                        ,aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE,FALSE)
                         ,tlbl->key+100);
            else{
                emitcode("cjne","a,%s,%05d$"
-                        ,aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE)
+                        ,aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE,FALSE)
                         ,tlbl->key+100);
            }
-           emitcode("inc","%s",aopGet(AOP(IC_RESULT(ic)),MSB32,FALSE,FALSE));
+           emitcode("inc","%s",aopGet(AOP(IC_RESULT(ic)),MSB32,FALSE,FALSE,FALSE));
        }
        
        if (emitTlbl)
@@ -2625,13 +2844,17 @@ static bool genPlusIncr (iCode *ic)
         sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
        
         if (icount > 3) {
-            MOVA(aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));       
+            MOVA(aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE,TRUE));
             emitcode("add","a,#0x%02x",((char) icount) & 0xff);
             aopPut(AOP(IC_RESULT(ic)),"a",0);
         } else {
            
+           _startLazyDPSEvaluation();
             while (icount--) 
-                emitcode ("inc","%s",aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+            {
+                emitcode ("inc","%s",aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE,FALSE));
+            }
+            _endLazyDPSEvaluation();
         }
        
         return TRUE ;
@@ -2682,45 +2905,6 @@ static void genPlusBits (iCode *ic)
     }
 }
 
-
-
-#if 0
-/* This is the original version of this code.
- *
- * This is being kept around for reference, 
- * because I am not entirely sure I got it right...
- */
-static void adjustArithmeticResult(iCode *ic)
-{
-    if (AOP_SIZE(IC_RESULT(ic)) == 3 && 
-       AOP_SIZE(IC_LEFT(ic)) == 3   &&
-       !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic))))
-       aopPut(AOP(IC_RESULT(ic)),
-              aopGet(AOP(IC_LEFT(ic)),2,FALSE,FALSE),
-              2);
-
-    if (AOP_SIZE(IC_RESULT(ic)) == 3 && 
-       AOP_SIZE(IC_RIGHT(ic)) == 3   &&
-       !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic))))
-       aopPut(AOP(IC_RESULT(ic)),
-              aopGet(AOP(IC_RIGHT(ic)),2,FALSE,FALSE),
-              2);
-    
-    if (AOP_SIZE(IC_RESULT(ic)) == 3 &&
-       AOP_SIZE(IC_LEFT(ic)) < 3    &&
-       AOP_SIZE(IC_RIGHT(ic)) < 3   &&
-       !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic))) &&
-       !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic)))) {
-       char buffer[5];
-       sprintf(buffer,"#%d",pointerCode(getSpec(operandType(IC_LEFT(ic)))));
-       aopPut(AOP(IC_RESULT(ic)),buffer,2);
-    }
-}
-#else
-/* This is the pure and virtuous version of this code.
- * I'm pretty certain it's right, but not enough to toss the old 
- * code just yet...
- */
 static void adjustArithmeticResult(iCode *ic)
 {
     if (opIsGptr(IC_RESULT(ic)) &&
@@ -2728,7 +2912,7 @@ static void adjustArithmeticResult(iCode *ic)
        !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic))))
     {
        aopPut(AOP(IC_RESULT(ic)),
-              aopGet(AOP(IC_LEFT(ic)), GPTRSIZE - 1,FALSE,FALSE),
+              aopGet(AOP(IC_LEFT(ic)), GPTRSIZE - 1,FALSE,FALSE,FALSE),
               GPTRSIZE - 1);
     }
 
@@ -2737,7 +2921,7 @@ static void adjustArithmeticResult(iCode *ic)
        !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic))))
     {
        aopPut(AOP(IC_RESULT(ic)),
-              aopGet(AOP(IC_RIGHT(ic)),GPTRSIZE - 1,FALSE,FALSE),
+              aopGet(AOP(IC_RIGHT(ic)),GPTRSIZE - 1,FALSE,FALSE,FALSE),
               GPTRSIZE - 1);
     }
 
@@ -2751,7 +2935,6 @@ static void adjustArithmeticResult(iCode *ic)
         aopPut(AOP(IC_RESULT(ic)),buffer,GPTRSIZE - 1);
      }
 }
-#endif
 
 #define AOP_OP_3(ic) \
     aopOp (IC_LEFT(ic),ic,FALSE, FALSE); \
@@ -2777,13 +2960,20 @@ static void genPlus (iCode *ic)
 {
     int size, offset = 0;
     bool pushResult = FALSE;
+    int  rSize;
 
     D(emitcode(";", "genPlus "););
 
     /* special cases :- */
 
+#ifdef LAZY_DPS_OPT
+    aopOp (IC_RIGHT(ic),ic,FALSE, FALSE);
+    aopOp (IC_LEFT(ic),ic,FALSE, 
+          (AOP_TYPE(IC_RIGHT(ic)) == AOP_DPTR));
+#else    
     aopOp (IC_LEFT(ic),ic,FALSE, TRUE);
     aopOp (IC_RIGHT(ic),ic,FALSE, FALSE);
+#endif    
     if ((AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR2) &&
         (AOP_TYPE(IC_RIGHT(ic)) == AOP_DPTR))
     {
@@ -2791,7 +2981,9 @@ static void genPlus (iCode *ic)
     }
     else
     {
-        aopOp (IC_RESULT(ic),ic,TRUE, AOP_TYPE(IC_RIGHT(ic)) == AOP_DPTR);
+        aopOp (IC_RESULT(ic),ic,TRUE, 
+               ((AOP_TYPE(IC_RIGHT(ic)) == AOP_DPTR)
+             || (AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR)));
 
     /* if literal, literal on the right or
        if left requires ACC or right is already
@@ -2823,11 +3015,13 @@ static void genPlus (iCode *ic)
             outBitC(IC_RESULT(ic));
         } else {
             size = getDataSize(IC_RESULT(ic));
+            _startLazyDPSEvaluation();
             while (size--) {
-                MOVA(aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));  
+                MOVA(aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE,TRUE));
                 emitcode("addc","a,#00");
                 aopPut(AOP(IC_RESULT(ic)),"a",offset++);
             }
+            _endLazyDPSEvaluation();
         }
         goto release ;
     }
@@ -2840,23 +3034,26 @@ static void genPlus (iCode *ic)
     }
     size = getDataSize(pushResult ? IC_LEFT(ic) : IC_RESULT(ic));
 
-    while(size--){
-       if (AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) {
-           MOVA(aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+    _startLazyDPSEvaluation();
+    while(size--)
+    {
+       if (AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) 
+       {
+           MOVA(aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE,TRUE));
            if(offset == 0)
                emitcode("add","a,%s",
-                        aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
+                        aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE,FALSE));
            else
                emitcode("addc","a,%s",
-                        aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
+                        aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE,FALSE));
        } else {
-           MOVA(aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
+           MOVA(aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE,TRUE));
            if(offset == 0)
                emitcode("add","a,%s",
-                        aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+                        aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE,FALSE));
            else
                emitcode("addc","a,%s",
-                        aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+                        aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE,FALSE));
        }
         if (!pushResult)
         {
@@ -2868,18 +3065,48 @@ static void genPlus (iCode *ic)
         }
         offset++;
     }
-
+    _endLazyDPSEvaluation();
+   
     if (pushResult)
     {
         aopOp (IC_RESULT(ic),ic,TRUE, FALSE);
 
         size = getDataSize(IC_LEFT(ic));
+       rSize = getDataSize(IC_RESULT(ic));
+       
+       /* If the pushed data is bigger than the result,
+        * simply discard unused bytes. Icky, but works.
+        *
+        * Should we throw a warning here? We're losing data...
+        */
+       while (size > rSize)
+       {
+          D(emitcode(";", "discarding unused result byte."););
+          emitcode("pop", "acc");
+          size--;
+          offset--; 
+       }
+       if (size < rSize)
+       {
+           emitcode("clr", "a");
+           /* Conversly, we haven't pushed enough here.
+            * just zero-pad, and all is well. 
+            */
+           while (size < rSize)
+           {
+               emitcode("push", "acc");
+               size++;
+               offset++;
+           }
+       }
 
+       _startLazyDPSEvaluation();
         while(size--)
         {
             emitcode("pop", "acc");
             aopPut(AOP(IC_RESULT(ic)), "a", --offset);
         }
+        _endLazyDPSEvaluation();
     }
 
     adjustArithmeticResult(ic);
@@ -2920,14 +3147,14 @@ static bool genMinusDec (iCode *ic)
             int labelRange;
 
            /* If the next instruction is a goto and the goto target
-            * is <= 10 instructions previous to this, we can generate
+         * is <= 5 instructions previous to this, we can generate
             * jumps straight to that target.
             */
             if (ic->next && ic->next->op == GOTO
                 && (labelRange = findLabelBackwards(ic, IC_LABEL(ic->next)->key)) != 0
-                && labelRange <= 10 )
+                && labelRange <= 5 )
             {        
-               emitcode(";", "tail decrement optimized");
+               emitcode(";", "tail decrement optimized (range %d)", labelRange);
                tlbl = IC_LABEL(ic->next);
                emitTlbl = 0;
             }
@@ -2937,34 +3164,34 @@ static bool genMinusDec (iCode *ic)
                 emitTlbl = 1;
             }
         
-               emitcode("dec","%s",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
+               emitcode("dec","%s",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE,FALSE));
                if(AOP_TYPE(IC_RESULT(ic)) == AOP_REG ||
                   AOP_TYPE(IC_RESULT(ic)) == AOP_DPTR ||
                   IS_AOP_PREG(IC_RESULT(ic)))
                        emitcode("cjne","%s,#0xff,%05d$"
-                                        ,aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE)
+                                        ,aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE,FALSE)
                                         ,tlbl->key+100);
                else{
                        emitcode("mov","a,#0xff");
                        emitcode("cjne","a,%s,%05d$"
-                                        ,aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE)
+                                        ,aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE,FALSE)
                                         ,tlbl->key+100);
                }
-               emitcode("dec","%s",aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE));
+               emitcode("dec","%s",aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE,FALSE));
                if (size > 2)
                {
                        if(AOP_TYPE(IC_RESULT(ic)) == AOP_REG ||
                           AOP_TYPE(IC_RESULT(ic)) == AOP_DPTR ||
                           IS_AOP_PREG(IC_RESULT(ic)))
                                emitcode("cjne","%s,#0xff,%05d$"
-                                                ,aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE)
+                                                ,aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE,FALSE)
                                                 ,tlbl->key+100);
                        else{
                                emitcode("cjne","a,%s,%05d$"
-                                                ,aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE)
+                                                ,aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE,FALSE)
                                                 ,tlbl->key+100);
                        }
-                       emitcode("dec","%s",aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE));
+                       emitcode("dec","%s",aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE,FALSE));
                }
                if (size > 3)
                {
@@ -2972,14 +3199,14 @@ static bool genMinusDec (iCode *ic)
                           AOP_TYPE(IC_RESULT(ic)) == AOP_DPTR ||
                           IS_AOP_PREG(IC_RESULT(ic)))
                                emitcode("cjne","%s,#0xff,%05d$"
-                                                ,aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE)
+                                                ,aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE,FALSE)
                                                 ,tlbl->key+100);
                        else{
                                emitcode("cjne","a,%s,%05d$"
-                                                ,aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE)
+                                                ,aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE,FALSE)
                                                 ,tlbl->key+100);
                        }
-                       emitcode("dec","%s",aopGet(AOP(IC_RESULT(ic)),MSB32,FALSE,FALSE));
+                       emitcode("dec","%s",aopGet(AOP(IC_RESULT(ic)),MSB32,FALSE,FALSE,FALSE));
                }
                if (emitTlbl)
                {
@@ -3001,8 +3228,12 @@ static bool genMinusDec (iCode *ic)
         AOP_TYPE(IC_RESULT(ic)) == AOP_REG &&
         sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic)))) {
 
+       _startLazyDPSEvaluation();
         while (icount--) 
-            emitcode ("dec","%s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+        {
+            emitcode ("dec","%s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE,FALSE));
+        }
+        _endLazyDPSEvaluation();
 
         return TRUE ;
     }
@@ -3061,6 +3292,7 @@ static void genMinusBits (iCode *ic)
 static void genMinus (iCode *ic)
 {
     int size, offset = 0;
+    int rSize;
     unsigned long lit = 0L;
     bool pushResult = FALSE;
 
@@ -3104,11 +3336,12 @@ static void genMinus (iCode *ic)
 
 
     /* if literal, add a,#-lit, else normal subb */
+    _startLazyDPSEvaluation();
     while (size--) {
-        MOVA(aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));    
+        MOVA(aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE,TRUE));
         if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT)  
             emitcode("subb","a,%s",
-                     aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
+                     aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE,FALSE));
         else{
             /* first add without previous c */
             if(!offset)
@@ -3129,12 +3362,40 @@ static void genMinus (iCode *ic)
         }
         offset++;
     }
+    _endLazyDPSEvaluation();
 
     if (pushResult)
     {
         aopOp (IC_RESULT(ic),ic,TRUE, FALSE);
 
         size = getDataSize(IC_LEFT(ic));
+        rSize = getDataSize(IC_RESULT(ic));
+
+       /* If the pushed data is bigger than the result,
+        * simply discard unused bytes. Icky, but works.
+        *
+        * Should we throw a warning here? We're losing data...
+        */
+       while (size > getDataSize(IC_RESULT(ic)))
+       {
+          emitcode(";", "discarding unused result byte.");
+          emitcode("pop", "acc");
+          size--;
+          offset--; 
+       }
+       if (size < rSize)
+       {
+           emitcode("clr", "a");
+           /* Conversly, we haven't pushed enough here.
+            * just zero-pad, and all is well. 
+            */
+           while (size < rSize)
+           {
+               emitcode("push", "acc");
+               size++;
+               offset++;
+           }
+       }
 
         while(size--)
         {
@@ -3187,8 +3448,8 @@ static void genMultOneByte (operand *left,
 
     size = AOP_SIZE(result);
     /* signed or unsigned */
-    emitcode("mov","b,%s", aopGet(AOP(right),0,FALSE,FALSE));
-    l = aopGet(AOP(left),0,FALSE,FALSE);
+    emitcode("mov","b,%s", aopGet(AOP(right),0,FALSE,FALSE,FALSE));
+    l = aopGet(AOP(left),0,FALSE,FALSE,TRUE);
     MOVA(l);       
     emitcode("mul","ab");
     /* if result size = 1, mul signed = mul unsigned */
@@ -3210,29 +3471,29 @@ static void genMultOneByte (operand *left,
                 /* AND literal negative */
                 if((int) floatFromVal (AOP(right)->aopu.aop_lit) < 0){
                     /* adjust MSB (c==0 after mul) */
-                    emitcode("subb","a,%s", aopGet(AOP(left),0,FALSE,FALSE));
+                    emitcode("subb","a,%s", aopGet(AOP(left),0,FALSE,FALSE,FALSE));
                 }
             }
             else{
                 lbl = newiTempLabel(NULL);
-                emitcode("xch","a,%s",aopGet(AOP(right),0,FALSE,FALSE));
+                emitcode("xch","a,%s",aopGet(AOP(right),0,FALSE,FALSE,FALSE));
                 emitcode("cjne","a,#0x80,%05d$", (lbl->key+100));
                 emitcode("","%05d$:",(lbl->key+100));
-                emitcode("xch","a,%s",aopGet(AOP(right),0,FALSE,FALSE));
+                emitcode("xch","a,%s",aopGet(AOP(right),0,FALSE,FALSE,FALSE));
                 lbl = newiTempLabel(NULL);      
                 emitcode("jc","%05d$",(lbl->key+100));          
-                emitcode("subb","a,%s", aopGet(AOP(left),0,FALSE,FALSE));
+                emitcode("subb","a,%s", aopGet(AOP(left),0,FALSE,FALSE,FALSE));
                 emitcode("","%05d$:",(lbl->key+100));
             }
 
             lbl = newiTempLabel(NULL);
-            emitcode("xch","a,%s",aopGet(AOP(left),0,FALSE,FALSE));
+            emitcode("xch","a,%s",aopGet(AOP(left),0,FALSE,FALSE,FALSE));
             emitcode("cjne","a,#0x80,%05d$", (lbl->key+100));
             emitcode("","%05d$:",(lbl->key+100));
-            emitcode("xch","a,%s",aopGet(AOP(left),0,FALSE,FALSE));
+            emitcode("xch","a,%s",aopGet(AOP(left),0,FALSE,FALSE,FALSE));
             lbl = newiTempLabel(NULL);      
             emitcode("jc","%05d$",(lbl->key+100));          
-            emitcode("subb","a,%s", aopGet(AOP(right),0,FALSE,FALSE));
+            emitcode("subb","a,%s", aopGet(AOP(right),0,FALSE,FALSE,FALSE));
             emitcode("","%05d$:",(lbl->key+100));
 
             aopPut(AOP(result),"a",1);
@@ -3303,12 +3564,8 @@ static void genDivbits (operand *left,
 
     char *l;
 
-    /* the result must be bit */    
-    emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE));
-    l = aopGet(AOP(left),0,FALSE,FALSE);
-
-    MOVA(l);    
-
+    /* the result must be bit */
+    LOAD_AB_FOR_DIV(left, right, l);
     emitcode("div","ab");
     emitcode("rrc","a");
     aopPut(AOP(result),"c",0);
@@ -3331,9 +3588,7 @@ static void genDivOneByte (operand *left,
     /* signed or unsigned */
     if (SPEC_USIGN(opetype)) {
         /* unsigned is easy */
-        emitcode("mov","b,%s", aopGet(AOP(right),0,FALSE,FALSE));
-        l = aopGet(AOP(left),0,FALSE,FALSE);
-        MOVA(l);        
+        LOAD_AB_FOR_DIV(left, right, l);
         emitcode("div","ab");
         aopPut(AOP(result),"a",0);
         while (size--)
@@ -3344,13 +3599,13 @@ static void genDivOneByte (operand *left,
     /* signed is a little bit more difficult */
 
     /* save the signs of the operands */
-    l = aopGet(AOP(left),0,FALSE,FALSE);    
+    l = aopGet(AOP(left),0,FALSE,FALSE,TRUE);    
     MOVA(l);    
-    emitcode("xrl","a,%s",aopGet(AOP(right),0,FALSE,TRUE));
+    emitcode("xrl","a,%s",aopGet(AOP(right),0,FALSE,TRUE,FALSE));
     emitcode("push","acc"); /* save it on the stack */
 
     /* now sign adjust for both left & right */
-    l =  aopGet(AOP(right),0,FALSE,FALSE);    
+    l =  aopGet(AOP(right),0,FALSE,FALSE,TRUE);
     MOVA(l);       
     lbl = newiTempLabel(NULL);
     emitcode("jnb","acc.7,%05d$",(lbl->key+100));   
@@ -3360,7 +3615,7 @@ static void genDivOneByte (operand *left,
     emitcode("mov","b,a");
 
     /* sign adjust left side */
-    l =  aopGet(AOP(left),0,FALSE,FALSE);    
+    l =  aopGet(AOP(left),0,FALSE,FALSE,TRUE);
     MOVA(l);
 
     lbl = newiTempLabel(NULL);
@@ -3370,6 +3625,7 @@ static void genDivOneByte (operand *left,
     emitcode("","%05d$:",(lbl->key+100));
 
     /* now the division */
+    emitcode("nop", "; workaround for DS80C390 div bug.");
     emitcode("div","ab");
     /* we are interested in the lower order
     only */
@@ -3450,11 +3706,7 @@ static void genModbits (operand *left,
     char *l;
 
     /* the result must be bit */    
-    emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE));
-    l = aopGet(AOP(left),0,FALSE,FALSE);
-
-    MOVA(l);       
-
+    LOAD_AB_FOR_DIV(left, right, l);
     emitcode("div","ab");
     emitcode("mov","a,b");
     emitcode("rrc","a");
@@ -3475,9 +3727,7 @@ static void genModOneByte (operand *left,
     /* signed or unsigned */
     if (SPEC_USIGN(opetype)) {
         /* unsigned is easy */
-        emitcode("mov","b,%s", aopGet(AOP(right),0,FALSE,FALSE));
-        l = aopGet(AOP(left),0,FALSE,FALSE);
-        MOVA(l);    
+        LOAD_AB_FOR_DIV(left, right, l);
         emitcode("div","ab");
         aopPut(AOP(result),"b",0);
         return ;
@@ -3486,14 +3736,14 @@ static void genModOneByte (operand *left,
     /* signed is a little bit more difficult */
 
     /* save the signs of the operands */
-    l = aopGet(AOP(left),0,FALSE,FALSE);    
+    l = aopGet(AOP(left),0,FALSE,FALSE,TRUE);
     MOVA(l);
 
-    emitcode("xrl","a,%s",aopGet(AOP(right),0,FALSE,FALSE));
+    emitcode("xrl","a,%s",aopGet(AOP(right),0,FALSE,FALSE,FALSE));
     emitcode("push","acc"); /* save it on the stack */
 
     /* now sign adjust for both left & right */
-    l =  aopGet(AOP(right),0,FALSE,FALSE);    
+    l =  aopGet(AOP(right),0,FALSE,FALSE,TRUE);
     MOVA(l);
 
     lbl = newiTempLabel(NULL);
@@ -3504,7 +3754,7 @@ static void genModOneByte (operand *left,
     emitcode("mov","b,a"); 
 
     /* sign adjust left side */
-    l =  aopGet(AOP(left),0,FALSE,FALSE);    
+    l =  aopGet(AOP(left),0,FALSE,FALSE,TRUE);
     MOVA(l);
 
     lbl = newiTempLabel(NULL);
@@ -3514,6 +3764,7 @@ static void genModOneByte (operand *left,
     emitcode("","%05d$:",(lbl->key+100));
 
     /* now the multiplication */
+    emitcode("nop", "; workaround for DS80C390 div bug.");
     emitcode("div","ab");
     /* we are interested in the lower order
     only */
@@ -3642,7 +3893,7 @@ static void genCmp (operand *left,operand *right,
         {
             werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
                    "both CMP operands need ACC!");
-            exit(-1);
+            exit(1);
         }
         else
         {
@@ -3671,8 +3922,8 @@ static void genCmp (operand *left,operand *right,
            (AOP_TYPE(right) == AOP_LIT && AOP_TYPE(left) != AOP_DIR )){
             symbol *lbl  = newiTempLabel(NULL);
             emitcode("cjne","%s,%s,%05d$",
-                     aopGet(AOP(left),offset,FALSE,FALSE),
-                     aopGet(AOP(right),offset,FALSE,FALSE),
+                     aopGet(AOP(left),offset,FALSE,FALSE,FALSE),
+                     aopGet(AOP(right),offset,FALSE,FALSE,FALSE),
                      lbl->key+100);
             emitcode("","%05d$:",lbl->key+100);
         } else {
@@ -3684,7 +3935,7 @@ static void genCmp (operand *left,operand *right,
                         CLRC;
                     }
                     else{
-                        MOVA(aopGet(AOP(left),AOP_SIZE(left)-1,FALSE,FALSE));
+                        MOVA(aopGet(AOP(left),AOP_SIZE(left)-1,FALSE,FALSE,TRUE));
                         if(!(AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) && ifx){
                             genIfxJump (ifx,"acc.7");
                             return;
@@ -3699,7 +3950,7 @@ static void genCmp (operand *left,operand *right,
             while (size--)
             {
                 emitcode(";", "genCmp #1: %d/%d/%d", size, sign, offset);
-                MOVA(aopGet(AOP(left),offset,FALSE,FALSE));
+                MOVA(aopGet(AOP(left),offset,FALSE,FALSE,TRUE));
                 emitcode(";", "genCmp #2");
                 if (sign && (size == 0))
                 {
@@ -3721,7 +3972,7 @@ static void genCmp (operand *left,operand *right,
                             emitcode("push", "acc");
                         }
                         emitcode("mov","b,%s",aopGet(AOP(right),offset++,
-                                  FALSE,FALSE));
+                                  FALSE,FALSE,FALSE));
                         emitcode("xrl","b,#0x80");
                         if (AOP_NEEDSACC(right))
                         {
@@ -3740,14 +3991,14 @@ static void genCmp (operand *left,operand *right,
                         /* Yuck!! */
                         emitcode(";", "genCmp #4.1");
                         emitcode("xch", "a, b");
-                        MOVA(aopGet(AOP(right),offset++,FALSE,FALSE));
+                        MOVA(aopGet(AOP(right),offset++,FALSE,FALSE,TRUE));
                         emitcode("xch", "a, b");
                         s = "b";
                     }
                     else
                     {
                         emitcode(";", "genCmp #4.2");
-                        s = aopGet(AOP(right),offset++,FALSE,FALSE);
+                        s = aopGet(AOP(right),offset++,FALSE,FALSE,FALSE);
                     }
 
                     emitcode("subb","a,%s",s);
@@ -3864,17 +4115,28 @@ static void gencjneshort(operand *left, operand *right, symbol *lbl)
         right = left;
         left = t;
     }
+    
     if(AOP_TYPE(right) == AOP_LIT)
         lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
+        
+    if (opIsGptr(left) || opIsGptr(right))
+    {
+        /* We are comparing a generic pointer to something.
+         * Exclude the generic type byte from the comparison.
+         */
+        size--;
+        D(emitcode(";", "cjneshort: generic ptr special case.");) 
+    }
+         
 
     /* if the right side is a literal then anything goes */
     if (AOP_TYPE(right) == AOP_LIT &&
         AOP_TYPE(left) != AOP_DIR ) {
         while (size--) {
-            char *l = aopGet(AOP(left), offset, FALSE, FALSE);
+            char *l = aopGet(AOP(left), offset, FALSE, FALSE,TRUE);
             MOVA(l);
             emitcode("cjne","a,%s,%05d$",
-                     aopGet(AOP(right),offset,FALSE,FALSE),
+                     aopGet(AOP(right),offset,FALSE,FALSE,FALSE),
                      lbl->key+100);
             offset++;
         }
@@ -3885,25 +4147,27 @@ static void gencjneshort(operand *left, operand *right, symbol *lbl)
     else if (AOP_TYPE(right) == AOP_REG ||
              AOP_TYPE(right) == AOP_DIR || 
              (AOP_TYPE(left) == AOP_DIR && AOP_TYPE(right) == AOP_LIT) ||
-             (IS_AOP_PREG(left) && !IS_AOP_PREG(right))) {
-        while (size--) {
-            MOVA(aopGet(AOP(left),offset,FALSE,FALSE));
+             (IS_AOP_PREG(left) && !IS_AOP_PREG(right))) 
+    {
+        while (size--) 
+        {
+            MOVA(aopGet(AOP(left),offset,FALSE,FALSE,TRUE));
             if((AOP_TYPE(left) == AOP_DIR && AOP_TYPE(right) == AOP_LIT) &&
                ((unsigned int)((lit >> (offset*8)) & 0x0FFL) == 0))
                 emitcode("jnz","%05d$",lbl->key+100);
             else
                 emitcode("cjne","a,%s,%05d$",
-                         aopGet(AOP(right),offset,FALSE,TRUE),
+                         aopGet(AOP(right),offset,FALSE,TRUE,FALSE),
                          lbl->key+100);
             offset++;
         }
     } else {
         /* right is a pointer reg need both a & b */
         while(size--) {
-            char *l = aopGet(AOP(left),offset,FALSE,FALSE);
+            char *l = aopGet(AOP(left),offset,FALSE,FALSE,TRUE);
             if(strcmp(l,"b"))
                 emitcode("mov","b,%s",l);
-            MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
+            MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
             emitcode("cjne","a,b,%05d$",lbl->key+100);    
             offset++;
         }
@@ -4313,7 +4577,7 @@ static void genAnd (iCode *ic, iCode *ifx)
                 emitcode("anl","c,%s",AOP(left)->aopu.aop_dir);
             } else {
                 // c = bit & val;
-                MOVA(aopGet(AOP(right),0,FALSE,FALSE));
+                MOVA(aopGet(AOP(right),0,FALSE,FALSE,TRUE));
                 // c = lsb
                 emitcode("rrc","a");
                 emitcode("anl","c,%s",AOP(left)->aopu.aop_dir);
@@ -4338,7 +4602,7 @@ static void genAnd (iCode *ic, iCode *ifx)
         /* left &  2^n */
         if(posbit){
             posbit--;
-            MOVA(aopGet(AOP(left),posbit>>3,FALSE,FALSE));
+            MOVA(aopGet(AOP(left),posbit>>3,FALSE,FALSE,TRUE));
             // bit = left & 2^n
             if(size)
                 emitcode("mov","c,acc.%d",posbit&0x07);
@@ -4357,14 +4621,14 @@ static void genAnd (iCode *ic, iCode *ifx)
                 emitcode("setb","c");
             while(sizel--){
                 if((bytelit = ((lit >> (offset*8)) & 0x0FFL)) != 0x0L){
-                    MOVA( aopGet(AOP(left),offset,FALSE,FALSE));
+                    MOVA( aopGet(AOP(left),offset,FALSE,FALSE,TRUE));
                     // byte ==  2^n ?
                     if((posbit = isLiteralBit(bytelit)) != 0)
                         emitcode("jb","acc.%d,%05d$",(posbit-1)&0x07,tlbl->key+100);
                     else{
                         if(bytelit != 0x0FFL)
                             emitcode("anl","a,%s",
-                                     aopGet(AOP(right),offset,FALSE,TRUE));
+                                     aopGet(AOP(right),offset,FALSE,TRUE,FALSE));
                         emitcode("jnz","%05d$",tlbl->key+100);
                     }
                 }
@@ -4397,25 +4661,25 @@ static void genAnd (iCode *ic, iCode *ifx)
                        aopPut(AOP(result),zero,offset);
                    else 
                        if (IS_AOP_PREG(result)) {
-                           MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
-                           emitcode("anl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE));
+                           MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
+                           emitcode("anl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE,FALSE));
                            aopPut(AOP(result),"a",offset);
                        } else
                            emitcode("anl","%s,%s",
-                                    aopGet(AOP(left),offset,FALSE,TRUE),
-                                    aopGet(AOP(right),offset,FALSE,FALSE));
+                                    aopGet(AOP(left),offset,FALSE,TRUE,FALSE),
+                                    aopGet(AOP(right),offset,FALSE,FALSE,FALSE));
             } else {
                if (AOP_TYPE(left) == AOP_ACC)
-                   emitcode("anl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE));
+                   emitcode("anl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE,FALSE));
                else {
-                   MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
+                   MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
                    if (IS_AOP_PREG(result)) {
-                       emitcode("anl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE));
+                       emitcode("anl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE,FALSE));
                        aopPut(AOP(result),"a",offset);
 
                    } else
                        emitcode("anl","%s,a",
-                                aopGet(AOP(left),offset,FALSE,TRUE));
+                                aopGet(AOP(left),offset,FALSE,TRUE,FALSE));
                }
             }
         }
@@ -4430,9 +4694,9 @@ static void genAnd (iCode *ic, iCode *ifx)
             if(size)
                 emitcode("setb","c");
             while(sizer--){
-                MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
+                MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
                 emitcode("anl","a,%s",
-                         aopGet(AOP(left),offset,FALSE,FALSE));
+                         aopGet(AOP(left),offset,FALSE,FALSE,FALSE));
                 emitcode("jnz","%05d$",tlbl->key+100);
                 offset++;
             }
@@ -4449,7 +4713,7 @@ static void genAnd (iCode *ic, iCode *ifx)
                if(AOP_TYPE(right) == AOP_LIT){
                    if((bytelit = (int)((lit >> (offset*8)) & 0x0FFL)) == 0x0FF){
                        aopPut(AOP(result),
-                              aopGet(AOP(left),offset,FALSE,FALSE),
+                              aopGet(AOP(left),offset,FALSE,FALSE,FALSE),
                               offset);
                        continue;
                    } else if(bytelit == 0){
@@ -4460,11 +4724,11 @@ static void genAnd (iCode *ic, iCode *ifx)
                // faster than result <- left, anl result,right
                // and better if result is SFR
                if (AOP_TYPE(left) == AOP_ACC) 
-                   emitcode("anl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE));
+                   emitcode("anl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE,FALSE));
                else {
-                   MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
+                   MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
                    emitcode("anl","a,%s",
-                            aopGet(AOP(left),offset,FALSE,FALSE));
+                            aopGet(AOP(left),offset,FALSE,FALSE,FALSE));
                }
                aopPut(AOP(result),"a",offset);
            }
@@ -4490,11 +4754,11 @@ static void genOr (iCode *ic, iCode *ifx)
 
     AOP_OP_3(ic);
     AOP_SET_LOCALS(ic);
-    #if 0
+#if 0
     aopOp((left = IC_LEFT(ic)),ic,FALSE, FALSE);
     aopOp((right= IC_RIGHT(ic)),ic,FALSE, TRUE);
     aopOp((result=IC_RESULT(ic)),ic,TRUE, FALSE);
-    #endif
+#endif
 
 #ifdef DEBUG_TYPE
     emitcode("","; Type res[%d] = l[%d]&r[%d]",
@@ -4626,24 +4890,24 @@ static void genOr (iCode *ic, iCode *ifx)
                     continue;
                 else 
                    if (IS_AOP_PREG(left)) {
-                       MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
-                       emitcode("orl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE));
+                       MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
+                       emitcode("orl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE,FALSE));
                        aopPut(AOP(result),"a",offset);
                    } else
                        emitcode("orl","%s,%s",
-                                aopGet(AOP(left),offset,FALSE,TRUE),
-                                aopGet(AOP(right),offset,FALSE,FALSE));
+                                aopGet(AOP(left),offset,FALSE,TRUE,FALSE),
+                                aopGet(AOP(right),offset,FALSE,FALSE,FALSE));
             } else {
                if (AOP_TYPE(left) == AOP_ACC) 
-                   emitcode("orl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE));
+                   emitcode("orl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE,FALSE));
                else {              
-                   MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
+                   MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
                    if (IS_AOP_PREG(left)) {
-                       emitcode("orl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE));
+                       emitcode("orl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE,FALSE));
                        aopPut(AOP(result),"a",offset);
                    } else
                        emitcode("orl","%s,a",
-                                aopGet(AOP(left),offset,FALSE,TRUE));
+                                aopGet(AOP(left),offset,FALSE,TRUE,FALSE));
                }
             }
         }
@@ -4658,9 +4922,9 @@ static void genOr (iCode *ic, iCode *ifx)
             if(size)
                 emitcode("setb","c");
             while(sizer--){
-                MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
+                MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
                 emitcode("orl","a,%s",
-                         aopGet(AOP(left),offset,FALSE,FALSE));
+                         aopGet(AOP(left),offset,FALSE,FALSE,FALSE));
                 emitcode("jnz","%05d$",tlbl->key+100);
                 offset++;
             }
@@ -4676,7 +4940,7 @@ static void genOr (iCode *ic, iCode *ifx)
             if(AOP_TYPE(right) == AOP_LIT){
                 if(((lit >> (offset*8)) & 0x0FFL) == 0x00L){
                     aopPut(AOP(result),
-                           aopGet(AOP(left),offset,FALSE,FALSE),
+                           aopGet(AOP(left),offset,FALSE,FALSE,FALSE),
                            offset);
                     continue;
                 }
@@ -4684,11 +4948,11 @@ static void genOr (iCode *ic, iCode *ifx)
             // faster than result <- left, anl result,right
             // and better if result is SFR
            if (AOP_TYPE(left) == AOP_ACC) 
-               emitcode("orl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE));
+               emitcode("orl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE,FALSE));
            else {
-               MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
+               MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
                emitcode("orl","a,%s",
-                        aopGet(AOP(left),offset,FALSE,FALSE));
+                        aopGet(AOP(left),offset,FALSE,FALSE,FALSE));
            }
            aopPut(AOP(result),"a",offset);                     
         }
@@ -4803,7 +5067,7 @@ static void genXor (iCode *ic, iCode *ifx)
                 // if val>>1 != 0, result = 1
                 emitcode("setb","c");
                 while(sizer){
-                    MOVA(aopGet(AOP(right),sizer-1,FALSE,FALSE));
+                    MOVA(aopGet(AOP(right),sizer-1,FALSE,FALSE,TRUE));
                     if(sizer == 1)
                         // test the msb of the lsb
                         emitcode("anl","a,#0xfe");
@@ -4835,24 +5099,24 @@ static void genXor (iCode *ic, iCode *ifx)
                     continue;
                 else
                    if (IS_AOP_PREG(left)) {
-                       MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
-                       emitcode("xrl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE));
+                       MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
+                       emitcode("xrl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE,FALSE));
                        aopPut(AOP(result),"a",offset);
                    } else 
                        emitcode("xrl","%s,%s",
-                                aopGet(AOP(left),offset,FALSE,TRUE),
-                                aopGet(AOP(right),offset,FALSE,FALSE));
+                                aopGet(AOP(left),offset,FALSE,TRUE,FALSE),
+                                aopGet(AOP(right),offset,FALSE,FALSE,FALSE));
             } else {
                if (AOP_TYPE(left) == AOP_ACC)
-                   emitcode("xrl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE));
+                   emitcode("xrl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE,FALSE));
                else {
-                   MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
+                   MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
                    if (IS_AOP_PREG(left)) {
-                       emitcode("xrl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE));
+                       emitcode("xrl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE,FALSE));
                        aopPut(AOP(result),"a",offset);
                    } else
                        emitcode("xrl","%s,a",
-                                aopGet(AOP(left),offset,FALSE,TRUE));
+                                aopGet(AOP(left),offset,FALSE,TRUE,FALSE));
                }
             }
         }
@@ -4869,11 +5133,11 @@ static void genXor (iCode *ic, iCode *ifx)
             while(sizer--){
                 if((AOP_TYPE(right) == AOP_LIT) &&
                    (((lit >> (offset*8)) & 0x0FFL) == 0x00L)){
-                    MOVA(aopGet(AOP(left),offset,FALSE,FALSE));
+                    MOVA(aopGet(AOP(left),offset,FALSE,FALSE,TRUE));
                 } else {
-                    MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
+                    MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
                     emitcode("xrl","a,%s",
-                             aopGet(AOP(left),offset,FALSE,FALSE));
+                             aopGet(AOP(left),offset,FALSE,FALSE,FALSE));
                 }
                 emitcode("jnz","%05d$",tlbl->key+100);
                 offset++;
@@ -4890,7 +5154,7 @@ static void genXor (iCode *ic, iCode *ifx)
             if(AOP_TYPE(right) == AOP_LIT){
                 if(((lit >> (offset*8)) & 0x0FFL) == 0x00L){
                     aopPut(AOP(result),
-                           aopGet(AOP(left),offset,FALSE,FALSE),
+                           aopGet(AOP(left),offset,FALSE,FALSE,FALSE),
                            offset);
                     continue;
                 }
@@ -4898,11 +5162,11 @@ static void genXor (iCode *ic, iCode *ifx)
             // faster than result <- left, anl result,right
             // and better if result is SFR
            if (AOP_TYPE(left) == AOP_ACC)
-               emitcode("xrl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE));
+               emitcode("xrl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE,FALSE));
            else {
-               MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
+               MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
                emitcode("xrl","a,%s",
-                        aopGet(AOP(left),offset,FALSE,TRUE));
+                        aopGet(AOP(left),offset,FALSE,TRUE,FALSE));
            }
            aopPut(AOP(result),"a",offset);
         }
@@ -4972,17 +5236,21 @@ static void genRRC (iCode *ic)
     size = AOP_SIZE(result);    
     offset = size - 1 ;
     CLRC;
+    
+    _startLazyDPSEvaluation();
     while (size--) {
-        l = aopGet(AOP(left),offset,FALSE,FALSE);
+        l = aopGet(AOP(left),offset,FALSE,FALSE,TRUE);
         MOVA(l);
         emitcode("rrc","a");
         if (AOP_SIZE(result) > 1)
             aopPut(AOP(result),"a",offset--);
     }
+    _endLazyDPSEvaluation();
+    
     /* now we need to put the carry into the
     highest order byte of the result */
     if (AOP_SIZE(result) > 1) {
-        l = aopGet(AOP(result),AOP_SIZE(result)-1,FALSE,FALSE);
+        l = aopGet(AOP(result),AOP_SIZE(result)-1,FALSE,FALSE,TRUE);
         MOVA(l);
     }
     emitcode("mov","acc.7,c");
@@ -5012,23 +5280,28 @@ static void genRLC (iCode *ic)
     size = AOP_SIZE(result);    
     offset = 0 ;
     if (size--) {
-        l = aopGet(AOP(left),offset,FALSE,FALSE);
+        l = aopGet(AOP(left),offset,FALSE,FALSE,TRUE);
         MOVA(l);
         emitcode("add","a,acc");
         if (AOP_SIZE(result) > 1)
+        {
             aopPut(AOP(result),"a",offset++);
+        }
+            
+        _startLazyDPSEvaluation();
         while (size--) {
-            l = aopGet(AOP(left),offset,FALSE,FALSE);
+            l = aopGet(AOP(left),offset,FALSE,FALSE,TRUE);
             MOVA(l);
             emitcode("rlc","a");
             if (AOP_SIZE(result) > 1)
                 aopPut(AOP(result),"a",offset++);
         }
+        _endLazyDPSEvaluation();
     }
     /* now we need to put the carry into the
     highest order byte of the result */
     if (AOP_SIZE(result) > 1) {
-        l = aopGet(AOP(result),0,FALSE,FALSE);
+        l = aopGet(AOP(result),0,FALSE,FALSE,TRUE);
         MOVA(l);
     }
     emitcode("mov","acc.0,c");
@@ -5051,7 +5324,7 @@ static void genGetHbit (iCode *ic)
     D(emitcode(";", "genGetHbit "););
 
     /* get the highest order byte into a */
-    MOVA(aopGet(AOP(left),AOP_SIZE(left) - 1,FALSE,FALSE));
+    MOVA(aopGet(AOP(left),AOP_SIZE(left) - 1,FALSE,FALSE,TRUE));
     if(AOP_TYPE(result) == AOP_CRY){
         emitcode("rlc","a");
         outBitC(result);
@@ -5143,6 +5416,8 @@ static void AccRsh (int shCount)
     }
 }
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* AccSRsh - signed right shift accumulator by known count                 */
 /*-----------------------------------------------------------------*/
@@ -5171,7 +5446,10 @@ static void AccSRsh (int shCount)
         }
     }
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* shiftR1Left2Result - shift right one byte from left to result   */
 /*-----------------------------------------------------------------*/
@@ -5179,7 +5457,7 @@ static void shiftR1Left2Result (operand *left, int offl,
                                 operand *result, int offr,
                                 int shCount, int sign)
 {
-    MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
+    MOVA(aopGet(AOP(left),offl,FALSE,FALSE,TRUE));
     /* shift right accumulator */
     if(sign)
         AccSRsh(shCount);
@@ -5187,7 +5465,10 @@ static void shiftR1Left2Result (operand *left, int offl,
         AccRsh(shCount);
     aopPut(AOP(result),"a",offr);
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* shiftL1Left2Result - shift left one byte from left to result    */
 /*-----------------------------------------------------------------*/
@@ -5195,13 +5476,16 @@ static void shiftL1Left2Result (operand *left, int offl,
                                 operand *result, int offr, int shCount)
 {
     char *l;
-    l = aopGet(AOP(left),offl,FALSE,FALSE);
+    l = aopGet(AOP(left),offl,FALSE,FALSE,TRUE);
     MOVA(l);
     /* shift left accumulator */
     AccLsh(shCount);
     aopPut(AOP(result),"a",offr);
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* movLeft2Result - move byte from left to result                  */
 /*-----------------------------------------------------------------*/
@@ -5210,7 +5494,7 @@ static void movLeft2Result (operand *left, int offl,
 {
     char *l;
     if(!sameRegs(AOP(left),AOP(result)) || (offl != offr)){
-        l = aopGet(AOP(left),offl,FALSE,FALSE);
+        l = aopGet(AOP(left),offl,FALSE,FALSE,FALSE);
 
         if (*l == '@' && (IS_AOP_PREG(result))) {
             emitcode("mov","a,%s",l);
@@ -5228,7 +5512,10 @@ static void movLeft2Result (operand *left, int offl,
         }
     }
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* AccAXRrl1 - right rotate c->a:x->c by 1                         */
 /*-----------------------------------------------------------------*/
@@ -5239,7 +5526,10 @@ static void AccAXRrl1 (char *x)
     emitcode("rrc","a");
     emitcode("xch","a,%s", x);
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* AccAXLrl1 - left rotate c<-a:x<-c by 1                          */
 /*-----------------------------------------------------------------*/
@@ -5250,7 +5540,10 @@ static void AccAXLrl1 (char *x)
     emitcode("xch","a,%s",x);
     emitcode("rlc","a");
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* AccAXLsh1 - left shift a:x<-0 by 1                              */
 /*-----------------------------------------------------------------*/
@@ -5261,7 +5554,10 @@ static void AccAXLsh1 (char *x)
     emitcode("xch","a,%s",x);
     emitcode("rlc","a");
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* AccAXLsh - left shift a:x by known count (0..7)                 */
 /*-----------------------------------------------------------------*/
@@ -5312,7 +5608,10 @@ static void AccAXLsh (char *x, int shCount)
             break;
     }
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* AccAXRsh - right shift a:x known count (0..7)                   */
 /*-----------------------------------------------------------------*/
@@ -5366,7 +5665,10 @@ static void AccAXRsh (char *x, int shCount)
             break;
     }
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* AccAXRshS - right shift signed a:x known count (0..7)           */
 /*-----------------------------------------------------------------*/
@@ -5436,7 +5738,10 @@ static void AccAXRshS (char *x, int shCount)
             break;
     }
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* shiftL2Left2Result - shift left two bytes from left to result   */
 /*-----------------------------------------------------------------*/
@@ -5446,18 +5751,20 @@ static void shiftL2Left2Result (operand *left, int offl,
     if(sameRegs(AOP(result), AOP(left)) &&
        ((offl + MSB16) == offr)){
        /* don't crash result[offr] */
-       MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
-       emitcode("xch","a,%s", aopGet(AOP(left),offl+MSB16,FALSE,FALSE));
+       MOVA(aopGet(AOP(left),offl,FALSE,FALSE,TRUE));
+       emitcode("xch","a,%s", aopGet(AOP(left),offl+MSB16,FALSE,FALSE,FALSE));
     } else {
        movLeft2Result(left,offl, result, offr, 0);
-       MOVA(aopGet(AOP(left),offl+MSB16,FALSE,FALSE));
+       MOVA(aopGet(AOP(left),offl+MSB16,FALSE,FALSE,TRUE));
     }
     /* ax << shCount (x = lsb(result))*/
-    AccAXLsh( aopGet(AOP(result),offr,FALSE,FALSE, shCount);
+    AccAXLsh( aopGet(AOP(result),offr,FALSE,FALSE,FALSE), shCount);
     aopPut(AOP(result),"a",offr+MSB16);
 }
+#endif
 
-
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* shiftR2Left2Result - shift right two bytes from left to result  */
 /*-----------------------------------------------------------------*/
@@ -5468,51 +5775,60 @@ static void shiftR2Left2Result (operand *left, int offl,
     if(sameRegs(AOP(result), AOP(left)) &&
        ((offl + MSB16) == offr)){
        /* don't crash result[offr] */
-       MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
-       emitcode("xch","a,%s", aopGet(AOP(left),offl+MSB16,FALSE,FALSE));
+       MOVA(aopGet(AOP(left),offl,FALSE,FALSE,TRUE));
+       emitcode("xch","a,%s", aopGet(AOP(left),offl+MSB16,FALSE,FALSE,FALSE));
     } else {
        movLeft2Result(left,offl, result, offr, 0);
-       MOVA(aopGet(AOP(left),offl+MSB16,FALSE,FALSE));
+       MOVA(aopGet(AOP(left),offl+MSB16,FALSE,FALSE,TRUE));
     }
     /* a:x >> shCount (x = lsb(result))*/
     if(sign)
-        AccAXRshS( aopGet(AOP(result),offr,FALSE,FALSE) , shCount);
+        AccAXRshS( aopGet(AOP(result),offr,FALSE,FALSE,FALSE) , shCount);
     else
-        AccAXRsh( aopGet(AOP(result),offr,FALSE,FALSE) , shCount);
+        AccAXRsh( aopGet(AOP(result),offr,FALSE,FALSE,FALSE) , shCount);
     if(getDataSize(result) > 1)
         aopPut(AOP(result),"a",offr+MSB16);
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* shiftLLeftOrResult - shift left one byte from left, or to result*/
 /*-----------------------------------------------------------------*/
 static void shiftLLeftOrResult (operand *left, int offl,
                                 operand *result, int offr, int shCount)
 {
-    MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
+    MOVA(aopGet(AOP(left),offl,FALSE,FALSE,TRUE));
     /* shift left accumulator */
     AccLsh(shCount);
     /* or with result */
-    emitcode("orl","a,%s", aopGet(AOP(result),offr,FALSE,FALSE));
+    emitcode("orl","a,%s", aopGet(AOP(result),offr,FALSE,FALSE,FALSE));
     /* back to result */
     aopPut(AOP(result),"a",offr);
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* shiftRLeftOrResult - shift right one byte from left,or to result*/
 /*-----------------------------------------------------------------*/
 static void shiftRLeftOrResult (operand *left, int offl,
                                 operand *result, int offr, int shCount)
 {
-    MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
+    MOVA(aopGet(AOP(left),offl,FALSE,FALSE,TRUE));
     /* shift right accumulator */
     AccRsh(shCount);
     /* or with result */
-    emitcode("orl","a,%s", aopGet(AOP(result),offr,FALSE,FALSE));
+    emitcode("orl","a,%s", aopGet(AOP(result),offr,FALSE,FALSE,FALSE));
     /* back to result */
     aopPut(AOP(result),"a",offr);
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* genlshOne - left shift a one byte quantity by known count       */
 /*-----------------------------------------------------------------*/
@@ -5521,7 +5837,10 @@ static void genlshOne (operand *result, operand *left, int shCount)
     D(emitcode(";", "genlshOne "););
     shiftL1Left2Result(left, LSB, result, LSB, shCount);
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* genlshTwo - left shift two bytes by known amount != 0           */
 /*-----------------------------------------------------------------*/
@@ -5554,7 +5873,10 @@ static void genlshTwo (operand *result,operand *left, int shCount)
             shiftL2Left2Result(left, LSB, result, LSB, shCount);
     }
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* shiftLLong - shift left one long from left to result            */
 /* offl = LSB or MSB16                                             */
@@ -5565,48 +5887,48 @@ static void shiftLLong (operand *left, operand *result, int offr )
     int size = AOP_SIZE(result);
 
     if(size >= LSB+offr){
-        l = aopGet(AOP(left),LSB,FALSE,FALSE);
+        l = aopGet(AOP(left),LSB,FALSE,FALSE,TRUE);
         MOVA(l);
         emitcode("add","a,acc");
        if (sameRegs(AOP(left),AOP(result)) && 
            size >= MSB16+offr && offr != LSB )
            emitcode("xch","a,%s",
-                    aopGet(AOP(left),LSB+offr,FALSE,FALSE));
+                    aopGet(AOP(left),LSB+offr,FALSE,FALSE,FALSE));
        else        
            aopPut(AOP(result),"a",LSB+offr);
     }
 
     if(size >= MSB16+offr){
        if (!(sameRegs(AOP(result),AOP(left)) && size >= MSB16+offr && offr != LSB) ) {
-           l = aopGet(AOP(left),MSB16,FALSE,FALSE);
+           l = aopGet(AOP(left),MSB16,FALSE,FALSE,TRUE);
            MOVA(l);
        }
         emitcode("rlc","a");
        if (sameRegs(AOP(left),AOP(result)) && 
            size >= MSB24+offr && offr != LSB)
            emitcode("xch","a,%s",
-                    aopGet(AOP(left),MSB16+offr,FALSE,FALSE));
+                    aopGet(AOP(left),MSB16+offr,FALSE,FALSE,FALSE));
        else        
            aopPut(AOP(result),"a",MSB16+offr);
     }
 
     if(size >= MSB24+offr){
        if (!(sameRegs(AOP(left),AOP(left)) && size >= MSB24+offr && offr != LSB)) {
-           l = aopGet(AOP(left),MSB24,FALSE,FALSE);
+           l = aopGet(AOP(left),MSB24,FALSE,FALSE,TRUE);
            MOVA(l);
        }
         emitcode("rlc","a");
        if (sameRegs(AOP(left),AOP(result)) && 
            size >= MSB32+offr && offr != LSB )
            emitcode("xch","a,%s",
-                    aopGet(AOP(left),MSB24+offr,FALSE,FALSE));
+                    aopGet(AOP(left),MSB24+offr,FALSE,FALSE,FALSE));
        else        
            aopPut(AOP(result),"a",MSB24+offr);
     }
 
     if(size > MSB32+offr){
        if (!(sameRegs(AOP(result),AOP(left)) && size >= MSB32+offr && offr != LSB)) {
-           l = aopGet(AOP(left),MSB32,FALSE,FALSE);
+           l = aopGet(AOP(left),MSB32,FALSE,FALSE,TRUE);
            MOVA(l);    
        }
         emitcode("rlc","a");
@@ -5615,7 +5937,10 @@ static void shiftLLong (operand *left, operand *result, int offr )
     if(offr != LSB)
         aopPut(AOP(result),zero,LSB);       
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* genlshFour - shift four byte by a known amount != 0             */
 /*-----------------------------------------------------------------*/
@@ -5699,7 +6024,10 @@ static void genlshFour (operand *result, operand *left, int shCount)
         shiftL2Left2Result(left, LSB, result, LSB, shCount);
     }
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* genLeftShiftLiteral - left shifting by known count              */
 /*-----------------------------------------------------------------*/
@@ -5754,6 +6082,7 @@ static void genLeftShiftLiteral (operand *left,
     freeAsmop(left,NULL,ic,TRUE);
     freeAsmop(result,NULL,ic,TRUE);
 }
+#endif
 
 /*-----------------------------------------------------------------*/
 /* genLeftShift - generates code for left shifting                 */
@@ -5773,14 +6102,14 @@ static void genLeftShift (iCode *ic)
 
     aopOp(right,ic,FALSE, FALSE);
 
-    #if 0
+#if 0
     /* if the shift count is known then do it 
     as efficiently as possible */
     if (AOP_TYPE(right) == AOP_LIT) {
         genLeftShiftLiteral (left,right,result,ic);
         return ;
     }
-    #endif
+#endif
 
     /* shift count is unknown then we have to form 
     a loop get the loop count in B : Note: we take
@@ -5788,7 +6117,7 @@ static void genLeftShift (iCode *ic)
     more that 32 bits make no sense anyway, ( the
     largest size of an object can be only 32 bits ) */  
 
-    emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE));
+    emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE,FALSE));
     emitcode("inc","b");
     freeAsmop (right,NULL,ic,TRUE);
     aopOp(left,ic,FALSE, FALSE);
@@ -5801,8 +6130,9 @@ static void genLeftShift (iCode *ic)
 
         size = AOP_SIZE(result);
         offset=0;
+        _startLazyDPSEvaluation();
         while (size--) {
-            l = aopGet(AOP(left),offset,FALSE,TRUE);
+            l = aopGet(AOP(left),offset,FALSE,TRUE,FALSE);
             if (*l == '@' && (IS_AOP_PREG(result))) {
 
                 emitcode("mov","a,%s",l);
@@ -5811,6 +6141,7 @@ static void genLeftShift (iCode *ic)
                 aopPut(AOP(result),l,offset);
             offset++;
         }
+        _endLazyDPSEvaluation();
     }
 
     tlbl = newiTempLabel(NULL);
@@ -5822,7 +6153,7 @@ static void genLeftShift (iCode *ic)
     if (size == 1) {
        symbol *tlbl1 = newiTempLabel(NULL);
 
-        l = aopGet(AOP(left),0,FALSE,FALSE);
+        l = aopGet(AOP(left),0,FALSE,FALSE,TRUE);
         MOVA(l);
        emitcode("sjmp","%05d$",tlbl1->key+100); 
         emitcode("","%05d$:",tlbl->key+100);
@@ -5837,16 +6168,18 @@ static void genLeftShift (iCode *ic)
     
     emitcode("sjmp","%05d$",tlbl1->key+100); 
     emitcode("","%05d$:",tlbl->key+100);    
-    l = aopGet(AOP(result),offset,FALSE,FALSE);
+    l = aopGet(AOP(result),offset,FALSE,FALSE,TRUE);
     MOVA(l);
     emitcode("add","a,acc");         
     aopPut(AOP(result),"a",offset++);
+    _startLazyDPSEvaluation();
     while (--size) {
-        l = aopGet(AOP(result),offset,FALSE,FALSE);
+        l = aopGet(AOP(result),offset,FALSE,FALSE,TRUE);
         MOVA(l);
         emitcode("rlc","a");         
         aopPut(AOP(result),"a",offset++);
     }
+    _endLazyDPSEvaluation();
     reAdjustPreg(AOP(result));
 
     emitcode("","%05d$:",tlbl1->key+100);
@@ -5856,6 +6189,8 @@ release:
     freeAsmop(result,NULL,ic,TRUE);
 }
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* genrshOne - right shift a one byte quantity by known count      */
 /*-----------------------------------------------------------------*/
@@ -5865,7 +6200,10 @@ static void genrshOne (operand *result, operand *left,
     D(emitcode(";", "genrshOne"););
     shiftR1Left2Result(left, LSB, result, LSB, shCount, sign);
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* genrshTwo - right shift two bytes by known amount != 0          */
 /*-----------------------------------------------------------------*/
@@ -5889,7 +6227,10 @@ static void genrshTwo (operand *result,operand *left,
     else
         shiftR2Left2Result(left, LSB, result, LSB, shCount, sign); 
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* shiftRLong - shift right one long from left to result           */
 /* offl = LSB or MSB16                                             */
@@ -5899,7 +6240,7 @@ static void shiftRLong (operand *left, int offl,
 {
     if(!sign)
         emitcode("clr","c");
-    MOVA(aopGet(AOP(left),MSB32,FALSE,FALSE));
+    MOVA(aopGet(AOP(left),MSB32,FALSE,FALSE,TRUE));
     if(sign)
         emitcode("mov","c,acc.7");
     emitcode("rrc","a");
@@ -5908,21 +6249,24 @@ static void shiftRLong (operand *left, int offl,
         /* add sign of "a" */
         addSign(result, MSB32, sign);
 
-    MOVA(aopGet(AOP(left),MSB24,FALSE,FALSE));
+    MOVA(aopGet(AOP(left),MSB24,FALSE,FALSE,TRUE));
     emitcode("rrc","a");
     aopPut(AOP(result),"a",MSB24-offl);
 
-    MOVA(aopGet(AOP(left),MSB16,FALSE,FALSE));
+    MOVA(aopGet(AOP(left),MSB16,FALSE,FALSE,TRUE));
     emitcode("rrc","a");
     aopPut(AOP(result),"a",MSB16-offl);
 
     if(offl == LSB){
-        MOVA(aopGet(AOP(left),LSB,FALSE,FALSE));
+        MOVA(aopGet(AOP(left),LSB,FALSE,FALSE,TRUE));
         emitcode("rrc","a");
         aopPut(AOP(result),"a",LSB);
     }
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* genrshFour - shift four byte by a known amount != 0             */
 /*-----------------------------------------------------------------*/
@@ -5981,7 +6325,10 @@ static void genrshFour (operand *result, operand *left,
         }
     }
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* genRightShiftLiteral - right shifting by known count            */
 /*-----------------------------------------------------------------*/
@@ -6019,7 +6366,7 @@ static void genRightShiftLiteral (operand *left,
     else if(shCount >= (size * 8)){
         if(sign)
             /* get sign in acc.7 */
-            MOVA(aopGet(AOP(left),size-1,FALSE,FALSE));
+            MOVA(aopGet(AOP(left),size-1,FALSE,FALSE,TRUE));
         addSign(result, LSB, sign);
     } else{
         switch (size) {
@@ -6042,6 +6389,7 @@ static void genRightShiftLiteral (operand *left,
         freeAsmop(result,NULL,ic,TRUE);
     }
 }
+#endif
 
 /*-----------------------------------------------------------------*/
 /* genSignedRightShift - right shift of signed number              */
@@ -6064,19 +6412,19 @@ static void genSignedRightShift (iCode *ic)
 
     aopOp(right,ic,FALSE, FALSE);
 
-    #if 0
+#if 0
     if ( AOP_TYPE(right) == AOP_LIT) {
        genRightShiftLiteral (left,right,result,ic,1);
        return ;
     }
-    #endif
-        /* shift count is unknown then we have to form 
+#endif
+    /* shift count is unknown then we have to form 
        a loop get the loop count in B : Note: we take
        only the lower order byte since shifting
        more that 32 bits make no sense anyway, ( the
        largest size of an object can be only 32 bits ) */  
 
-    emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE));
+    emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE,FALSE));
     emitcode("inc","b");
     freeAsmop (right,NULL,ic,TRUE);
     aopOp(left,ic,FALSE, FALSE);
@@ -6089,8 +6437,9 @@ static void genSignedRightShift (iCode *ic)
 
         size = AOP_SIZE(result);
         offset=0;
+        _startLazyDPSEvaluation();
         while (size--) {
-            l = aopGet(AOP(left),offset,FALSE,TRUE);
+            l = aopGet(AOP(left),offset,FALSE,TRUE,FALSE);
             if (*l == '@' && IS_AOP_PREG(result)) {
 
                 emitcode("mov","a,%s",l);
@@ -6099,6 +6448,7 @@ static void genSignedRightShift (iCode *ic)
                 aopPut(AOP(result),l,offset);
             offset++;
         }
+        _endLazyDPSEvaluation();
     }
 
     /* mov the highest order bit to OVR */    
@@ -6107,12 +6457,12 @@ static void genSignedRightShift (iCode *ic)
 
     size = AOP_SIZE(result);
     offset = size - 1;
-    emitcode("mov","a,%s",aopGet(AOP(left),offset,FALSE,FALSE));
+    emitcode("mov","a,%s",aopGet(AOP(left),offset,FALSE,FALSE,FALSE));
     emitcode("rlc","a");
     emitcode("mov","ov,c");
     /* if it is only one byte then */
     if (size == 1) {
-        l = aopGet(AOP(left),0,FALSE,FALSE);
+        l = aopGet(AOP(left),0,FALSE,FALSE,TRUE);
         MOVA(l);
        emitcode("sjmp","%05d$",tlbl1->key+100);
         emitcode("","%05d$:",tlbl->key+100);
@@ -6128,12 +6478,14 @@ static void genSignedRightShift (iCode *ic)
     emitcode("sjmp","%05d$",tlbl1->key+100);
     emitcode("","%05d$:",tlbl->key+100);    
     emitcode("mov","c,ov");
+    _startLazyDPSEvaluation();
     while (size--) {
-        l = aopGet(AOP(result),offset,FALSE,FALSE);
+        l = aopGet(AOP(result),offset,FALSE,FALSE,TRUE);
         MOVA(l);
         emitcode("rrc","a");         
         aopPut(AOP(result),"a",offset--);
     }
+    _endLazyDPSEvaluation();
     reAdjustPreg(AOP(result));
     emitcode("","%05d$:",tlbl1->key+100);
     emitcode("djnz","b,%05d$",tlbl->key+100);
@@ -6178,14 +6530,14 @@ static void genRightShift (iCode *ic)
 
     aopOp(right,ic,FALSE, FALSE);
 
-    #if 0
+#if 0
     /* if the shift count is known then do it 
     as efficiently as possible */
     if (AOP_TYPE(right) == AOP_LIT) {
         genRightShiftLiteral (left,right,result,ic, 0);
         return ;
     }
-    #endif
+#endif
 
     /* shift count is unknown then we have to form 
     a loop get the loop count in B : Note: we take
@@ -6193,7 +6545,7 @@ static void genRightShift (iCode *ic)
     more that 32 bits make no sense anyway, ( the
     largest size of an object can be only 32 bits ) */  
 
-    emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE));
+    emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE,FALSE));
     emitcode("inc","b");
     freeAsmop (right,NULL,ic,TRUE);
     aopOp(left,ic,FALSE, FALSE);
@@ -6206,8 +6558,9 @@ static void genRightShift (iCode *ic)
 
         size = AOP_SIZE(result);
         offset=0;
+        _startLazyDPSEvaluation();
         while (size--) {
-            l = aopGet(AOP(left),offset,FALSE,TRUE);
+            l = aopGet(AOP(left),offset,FALSE,TRUE,FALSE);
             if (*l == '@' && IS_AOP_PREG(result)) {
 
                 emitcode("mov","a,%s",l);
@@ -6216,6 +6569,7 @@ static void genRightShift (iCode *ic)
                 aopPut(AOP(result),l,offset);
             offset++;
         }
+        _endLazyDPSEvaluation();
     }
 
     tlbl = newiTempLabel(NULL);
@@ -6225,7 +6579,7 @@ static void genRightShift (iCode *ic)
 
     /* if it is only one byte then */
     if (size == 1) {
-        l = aopGet(AOP(left),0,FALSE,FALSE);
+        l = aopGet(AOP(left),0,FALSE,FALSE,TRUE);
         MOVA(l);
        emitcode("sjmp","%05d$",tlbl1->key+100);
         emitcode("","%05d$:",tlbl->key+100);
@@ -6241,12 +6595,14 @@ static void genRightShift (iCode *ic)
     emitcode("sjmp","%05d$",tlbl1->key+100);
     emitcode("","%05d$:",tlbl->key+100);    
     CLRC;
+    _startLazyDPSEvaluation();
     while (size--) {
-        l = aopGet(AOP(result),offset,FALSE,FALSE);
+        l = aopGet(AOP(result),offset,FALSE,FALSE,TRUE);
         MOVA(l);
         emitcode("rrc","a");         
         aopPut(AOP(result),"a",offset--);
     }
+    _endLazyDPSEvaluation();
     reAdjustPreg(AOP(result));
 
     emitcode("","%05d$:",tlbl1->key+100);
@@ -6378,8 +6734,9 @@ static void genDataPointerGet (operand *left,
     aopOp(result,ic,TRUE, FALSE);
 
     /* get the string representation of the name */
-    l = aopGet(AOP(left),0,FALSE,TRUE);
+    l = aopGet(AOP(left),0,FALSE,TRUE,FALSE);
     size = AOP_SIZE(result);
+    _startLazyDPSEvaluation();
     while (size--) {
        if (offset)
            sprintf(buffer,"(%s + %d)",l+1,offset);
@@ -6387,6 +6744,7 @@ static void genDataPointerGet (operand *left,
            sprintf(buffer,"%s",l+1);
        aopPut(AOP(result),buffer,offset++);
     }
+    _endLazyDPSEvaluation();
 
     freeAsmop(left,NULL,ic,TRUE);
     freeAsmop(result,NULL,ic,TRUE);
@@ -6430,10 +6788,10 @@ static void genNearPointerGet (operand *left,
        preg = getFreePtr(ic,&aop,FALSE);
        emitcode("mov","%s,%s",
                preg->name,
-               aopGet(AOP(left),0,FALSE,TRUE));
+               aopGet(AOP(left),0,FALSE,TRUE,FALSE));
        rname = preg->name ;
     } else
-       rname = aopGet(AOP(left),0,FALSE,FALSE);
+       rname = aopGet(AOP(left),0,FALSE,FALSE,FALSE);
     
     freeAsmop(left,NULL,ic,TRUE);
     aopOp (result,ic,FALSE, FALSE);
@@ -6511,10 +6869,10 @@ static void genPagedPointerGet (operand *left,
        preg = getFreePtr(ic,&aop,FALSE);
        emitcode("mov","%s,%s",
                preg->name,
-               aopGet(AOP(left),0,FALSE,TRUE));
+               aopGet(AOP(left),0,FALSE,TRUE,FALSE));
        rname = preg->name ;
     } else
-       rname = aopGet(AOP(left),0,FALSE,FALSE);
+       rname = aopGet(AOP(left),0,FALSE,FALSE,FALSE);
     
     freeAsmop(left,NULL,ic,TRUE);
     aopOp (result,ic,FALSE, FALSE);
@@ -6584,32 +6942,29 @@ static void genFarPointerGet (operand *left,
         /* if this is remateriazable */
         if (AOP_TYPE(left) == AOP_IMMD)
         {
-            emitcode("mov","dptr,%s",aopGet(AOP(left),0,TRUE,FALSE));
+            emitcode("mov","dptr,%s",aopGet(AOP(left),0,TRUE,FALSE,FALSE));
         }
         else 
         { 
             /* we need to get it byte by byte */
+            _startLazyDPSEvaluation();
            if (AOP_TYPE(left) != AOP_DPTR)
            {
-               emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE));
-               emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE));
-               if (options.model == MODEL_FLAT24)
-               {
-                           emitcode("mov", "dpx,%s",aopGet(AOP(left),2,FALSE,FALSE));
-               }
+               emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE,TRUE));
+               emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE,TRUE));
+                       emitcode("mov","dpx,%s",aopGet(AOP(left),2,FALSE,FALSE,TRUE));
             }
             else
             {
                  /* We need to generate a load to DPTR indirect through DPTR. */
                  D(emitcode(";", "genFarPointerGet -- indirection special case."););
-                 emitcode("push", "%s", aopGet(AOP(left),0,FALSE,TRUE));
-                 emitcode("push", "%s", aopGet(AOP(left),1,FALSE,TRUE));
-                 emitcode("mov", "dpx,%s",aopGet(AOP(left),2,FALSE,FALSE));
-                 emitcode("pop", "acc");
-                 emitcode("mov", "dph,a");
-                 emitcode("pop", "acc");
-                 emitcode("mov", "dpl,a");
+                 emitcode("push", "%s", aopGet(AOP(left),0,FALSE,TRUE,TRUE));
+                 emitcode("push", "%s", aopGet(AOP(left),1,FALSE,TRUE,TRUE));
+                 emitcode("mov", "dpx,%s",aopGet(AOP(left),2,FALSE,FALSE,TRUE));
+                 emitcode("pop", "dph");
+                 emitcode("pop", "dpl");
             }
+            _endLazyDPSEvaluation();
         }
     }
     /* so dptr know contains the address */
@@ -6623,12 +6978,19 @@ static void genFarPointerGet (operand *left,
         size = AOP_SIZE(result);
         offset = 0 ;
 
+       _startLazyDPSEvaluation();
         while (size--) {
+            
+            genSetDPTR(0);
+            _flushLazyDPS();
+            
             emitcode("movx","a,@dptr");
-            aopPut(AOP(result),"a",offset++);
             if (size)
-                emitcode("inc","dptr");
+                emitcode("inc","dptr");            
+
+            aopPut(AOP(result),"a",offset++);
         }
+        _endLazyDPSEvaluation();
     }
 
     freeAsmop(result,NULL,ic,TRUE);
@@ -6650,19 +7012,18 @@ static void emitcodePointerGet (operand *left,
     if (AOP_TYPE(left) != AOP_STR) {
         /* if this is remateriazable */
         if (AOP_TYPE(left) == AOP_IMMD)
-            emitcode("mov","dptr,%s",aopGet(AOP(left),0,TRUE,FALSE));
+            emitcode("mov","dptr,%s",aopGet(AOP(left),0,TRUE,FALSE,FALSE));
         else { /* we need to get it byte by byte */
-            emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE));
-            emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE));
-            if (options.model == MODEL_FLAT24)
-            {
-               emitcode("mov", "dpx,%s",aopGet(AOP(left),2,FALSE,FALSE));
-            }
+            _startLazyDPSEvaluation();
+            emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE,TRUE));
+            emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE,TRUE));
+            emitcode("mov","dpx,%s",aopGet(AOP(left),2,FALSE,FALSE,TRUE));
+            _endLazyDPSEvaluation();
         }
     }
     /* so dptr know contains the address */
     freeAsmop(left,NULL,ic,TRUE);
-    aopOp(result,ic,FALSE, FALSE);
+    aopOp(result,ic,FALSE, TRUE);
 
     /* if bit then unpack */
     if (IS_BITVAR(retype)) 
@@ -6671,13 +7032,19 @@ static void emitcodePointerGet (operand *left,
         size = AOP_SIZE(result);
         offset = 0 ;
 
-        while (size--) {
+       _startLazyDPSEvaluation();
+        while (size--) 
+        {
+            genSetDPTR(0);
+            _flushLazyDPS();
+                              
             emitcode("clr","a");
             emitcode("movc","a,@a+dptr");
-            aopPut(AOP(result),"a",offset++);
             if (size)
-                emitcode("inc","dptr");
+                emitcode("inc","dptr");            
+            aopPut(AOP(result),"a",offset++);
         }
+        _endLazyDPSEvaluation();
     }
 
     freeAsmop(result,NULL,ic,TRUE);
@@ -6699,21 +7066,23 @@ static void genGenPointerGet (operand *left,
     if (AOP_TYPE(left) != AOP_STR) {
         /* if this is remateriazable */
         if (AOP_TYPE(left) == AOP_IMMD) {
-            emitcode("mov","dptr,%s",aopGet(AOP(left),0,TRUE,FALSE));
+            emitcode("mov","dptr,%s",aopGet(AOP(left),0,TRUE,FALSE,FALSE));
            emitcode("mov","b,#%d",pointerCode(retype));
        }
         else { /* we need to get it byte by byte */
-            emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE));
-            emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE));
+            _startLazyDPSEvaluation();
+            emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE,TRUE));
+            emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE,TRUE));
             if (options.model == MODEL_FLAT24)
             {
-               emitcode("mov", "dpx,%s",aopGet(AOP(left),2,FALSE,FALSE));
-               emitcode("mov","b,%s",aopGet(AOP(left),3,FALSE,FALSE));
+               emitcode("mov", "dpx,%s",aopGet(AOP(left),2,FALSE,FALSE,TRUE));
+               emitcode("mov","b,%s",aopGet(AOP(left),3,FALSE,FALSE,TRUE));
             }
             else
             {
-               emitcode("mov","b,%s",aopGet(AOP(left),2,FALSE,FALSE));
+               emitcode("mov","b,%s",aopGet(AOP(left),2,FALSE,FALSE,TRUE));
             }
+            _endLazyDPSEvaluation();
         }
     }
     /* so dptr know contains the address */
@@ -6823,7 +7192,7 @@ static void genPackBits (link    *etype ,
     blen = SPEC_BLEN(etype);
     bstr = SPEC_BSTR(etype);
 
-    l = aopGet(AOP(right),offset++,FALSE,FALSE);
+    l = aopGet(AOP(right),offset++,FALSE,FALSE,TRUE);
     MOVA(l);   
 
     /* if the bit lenth is less than or    */
@@ -6889,7 +7258,7 @@ static void genPackBits (link    *etype ,
     /* now generate for lengths greater than one byte */
     while (1) {
 
-        l = aopGet(AOP(right),offset++,FALSE,TRUE);
+        l = aopGet(AOP(right),offset++,FALSE,TRUE,FALSE);
 
         rLen -= 8 ;
         if (rLen <= 0 )
@@ -6975,7 +7344,7 @@ static void genDataPointerSet(operand *right,
 
     aopOp(right,ic,FALSE, FALSE);
     
-    l = aopGet(AOP(result),0,FALSE,TRUE);
+    l = aopGet(AOP(result),0,FALSE,TRUE,FALSE);
     size = AOP_SIZE(right);
     while (size--) {
        if (offset)
@@ -6983,7 +7352,7 @@ static void genDataPointerSet(operand *right,
        else
            sprintf(buffer,"%s",l+1);
        emitcode("mov","%s,%s",buffer,
-                aopGet(AOP(right),offset++,FALSE,FALSE));
+                aopGet(AOP(right),offset++,FALSE,FALSE,FALSE));
     }
 
     freeAsmop(right,NULL,ic,TRUE);
@@ -7024,10 +7393,10 @@ static void genNearPointerSet (operand *right,
         preg = getFreePtr(ic,&aop,FALSE);
         emitcode("mov","%s,%s",
                  preg->name,
-                 aopGet(AOP(result),0,FALSE,TRUE));
+                 aopGet(AOP(result),0,FALSE,TRUE,FALSE));
         rname = preg->name ;
     } else
-        rname = aopGet(AOP(result),0,FALSE,FALSE);
+        rname = aopGet(AOP(result),0,FALSE,FALSE,FALSE);
 
     freeAsmop(result,NULL,ic,TRUE);
     aopOp (right,ic,FALSE, FALSE);
@@ -7041,7 +7410,7 @@ static void genNearPointerSet (operand *right,
         int offset = 0 ;    
 
         while (size--) {
-            l = aopGet(AOP(right),offset,FALSE,TRUE);
+            l = aopGet(AOP(right),offset,FALSE,TRUE,FALSE);
             if (*l == '@' ) {
                 MOVA(l);
                 emitcode("mov","@%s,a",rname);
@@ -7103,10 +7472,10 @@ static void genPagedPointerSet (operand *right,
        preg = getFreePtr(ic,&aop,FALSE);
        emitcode("mov","%s,%s",
                preg->name,
-               aopGet(AOP(result),0,FALSE,TRUE));
+               aopGet(AOP(result),0,FALSE,TRUE,FALSE));
        rname = preg->name ;
     } else
-       rname = aopGet(AOP(result),0,FALSE,FALSE);
+       rname = aopGet(AOP(result),0,FALSE,FALSE,FALSE);
     
     freeAsmop(result,NULL,ic,TRUE);
     aopOp (right,ic,FALSE, FALSE);
@@ -7120,7 +7489,7 @@ static void genPagedPointerSet (operand *right,
        int offset = 0 ;        
        
        while (size--) {
-           l = aopGet(AOP(right),offset,FALSE,TRUE);
+           l = aopGet(AOP(right),offset,FALSE,TRUE,TRUE);
            
            MOVA(l);
            emitcode("movx","@%s,a",rname);
@@ -7174,31 +7543,28 @@ static void genFarPointerSet (operand *right,
     if (AOP_TYPE(result) != AOP_STR) {
         /* if this is remateriazable */
         if (AOP_TYPE(result) == AOP_IMMD)
-            emitcode("mov","dptr,%s",aopGet(AOP(result),0,TRUE,FALSE));
+            emitcode("mov","dptr,%s",aopGet(AOP(result),0,TRUE,FALSE,FALSE));
         else 
         {
             /* we need to get it byte by byte */
+            _startLazyDPSEvaluation();
            if (AOP_TYPE(result) != AOP_DPTR)
            {
-               emitcode("mov","dpl,%s",aopGet(AOP(result),0,FALSE,FALSE));
-               emitcode("mov","dph,%s",aopGet(AOP(result),1,FALSE,FALSE));
-               if (options.model == MODEL_FLAT24)
-               {
-                           emitcode("mov", "dpx,%s",aopGet(AOP(result),2,FALSE,FALSE));
-               }
+               emitcode("mov","dpl,%s",aopGet(AOP(result),0,FALSE,FALSE,TRUE));
+               emitcode("mov","dph,%s",aopGet(AOP(result),1,FALSE,FALSE,TRUE));
+                       emitcode("mov", "dpx,%s",aopGet(AOP(result),2,FALSE,FALSE,TRUE));
             }
             else
             {
                  /* We need to generate a load to DPTR indirect through DPTR. */
                  D(emitcode(";", "genFarPointerSet -- indirection special case."););
-                 emitcode("push", "%s", aopGet(AOP(result),0,FALSE,TRUE));
-                 emitcode("push", "%s", aopGet(AOP(result),1,FALSE,TRUE));
-                 emitcode("mov", "dpx,%s",aopGet(AOP(result),2,FALSE,FALSE));
-                 emitcode("pop", "acc");
-                 emitcode("mov", "dph,a");
-                 emitcode("pop", "acc");
-                 emitcode("mov", "dpl,a");
+                 emitcode("push", "%s", aopGet(AOP(result),0,FALSE,TRUE,TRUE));
+                 emitcode("push", "%s", aopGet(AOP(result),1,FALSE,TRUE,TRUE));
+                 emitcode("mov", "dpx,%s",aopGet(AOP(result),2,FALSE,FALSE,TRUE));
+                 emitcode("pop", "dph");
+                 emitcode("pop", "dpl");
             }
+            _endLazyDPSEvaluation();
         }
     }
     /* so dptr know contains the address */
@@ -7212,13 +7578,19 @@ static void genFarPointerSet (operand *right,
         size = AOP_SIZE(right);
         offset = 0 ;
 
+       _startLazyDPSEvaluation();
         while (size--) {
-            char *l = aopGet(AOP(right),offset++,FALSE,FALSE);
+            char *l = aopGet(AOP(right),offset++,FALSE,FALSE,TRUE);
             MOVA(l);
+            
+            genSetDPTR(0);
+            _flushLazyDPS();
+            
             emitcode("movx","@dptr,a");
             if (size)
                 emitcode("inc","dptr");
         }
+        _endLazyDPSEvaluation();
     }
 
     freeAsmop(right,NULL,ic,TRUE);
@@ -7238,24 +7610,19 @@ static void genGenPointerSet (operand *right,
     /* if the operand is already in dptr 
     then we do nothing else we move the value to dptr */
     if (AOP_TYPE(result) != AOP_STR) {
+       _startLazyDPSEvaluation();
         /* if this is remateriazable */
         if (AOP_TYPE(result) == AOP_IMMD) {
-            emitcode("mov","dptr,%s",aopGet(AOP(result),0,TRUE,FALSE));
-            emitcode("mov","b,%s + 1",aopGet(AOP(result),0,TRUE,FALSE));
+            emitcode("mov","dptr,%s",aopGet(AOP(result),0,TRUE,FALSE,FALSE));
+            emitcode("mov","b,%s + 1",aopGet(AOP(result),0,TRUE,FALSE,FALSE));
         }
         else { /* we need to get it byte by byte */
-            emitcode("mov","dpl,%s",aopGet(AOP(result),0,FALSE,FALSE));
-            emitcode("mov","dph,%s",aopGet(AOP(result),1,FALSE,FALSE));
-            if (options.model == MODEL_FLAT24)
-            {
-               emitcode("mov", "dpx,%s",aopGet(AOP(result),2,FALSE,FALSE));
-               emitcode("mov","b,%s",aopGet(AOP(result),3,FALSE,FALSE));
-            }
-            else
-            {
-               emitcode("mov","b,%s",aopGet(AOP(result),2,FALSE,FALSE));
-            }
+            emitcode("mov","dpl,%s",aopGet(AOP(result),0,FALSE,FALSE,TRUE));
+            emitcode("mov","dph,%s",aopGet(AOP(result),1,FALSE,FALSE,TRUE));
+            emitcode("mov","dpx,%s",aopGet(AOP(result),2,FALSE,FALSE,TRUE));
+            emitcode("mov","b,%s",aopGet(AOP(result),3,FALSE,FALSE,TRUE));
         }
+        _endLazyDPSEvaluation();
     }
     /* so dptr know contains the address */
     freeAsmop(result,NULL,ic,TRUE);
@@ -7268,13 +7635,19 @@ static void genGenPointerSet (operand *right,
         size = AOP_SIZE(right);
         offset = 0 ;
 
+       _startLazyDPSEvaluation();
         while (size--) {
-            char *l = aopGet(AOP(right),offset++,FALSE,FALSE);
+            char *l = aopGet(AOP(right),offset++,FALSE,FALSE,TRUE);
             MOVA(l);
+            
+            genSetDPTR(0);
+            _flushLazyDPS();
+            
             emitcode("lcall","__gptrput");
             if (size)
                 emitcode("inc","dptr");
         }
+        _endLazyDPSEvaluation();
     }
 
     freeAsmop(right,NULL,ic,TRUE);
@@ -7463,15 +7836,42 @@ static void genFarFarAssign (operand *result, operand *right, iCode *ic)
 {
     int size = AOP_SIZE(right);
     int offset = 0;
-    char *l ;
+    char *l;
+
+#ifdef LAZY_DPS_OPT
+    if (size > 1)
+    {
+       /* This is a net loss for size == 1, but a big gain
+        * otherwise.
+        */
+       D(emitcode(";", "genFarFarAssign (improved)"););
+
+       aopOp(result,ic,TRUE, TRUE);
+
+       _startLazyDPSEvaluation();
+       while (size--) 
+       {
+           aopPut(AOP(result),
+                  aopGet(AOP(right),offset,FALSE,FALSE,FALSE),
+                  offset);
+           offset++;
+       }
+       _endLazyDPSEvaluation();    
+       freeAsmop(result,NULL,ic,FALSE);
+       freeAsmop(right,NULL,ic,FALSE);
+    }
+    else
+#endif
+    {
+    D(emitcode(";", "genFarFarAssign "););
+
     /* first push the right side on to the stack */
+    _startLazyDPSEvaluation();
     while (size--) {
-       l = aopGet(AOP(right),offset++,FALSE,FALSE);
+       l = aopGet(AOP(right),offset++,FALSE,FALSE,TRUE);
        MOVA(l);
        emitcode ("push","acc");
     }
-    
-    D(emitcode(";", "genFarFarAssign "););
 
     freeAsmop(right,NULL,ic,FALSE);
     /* now assign DPTR to result */
@@ -7482,7 +7882,8 @@ static void genFarFarAssign (operand *result, operand *right, iCode *ic)
        aopPut(AOP(result),"a",--offset);
     }
     freeAsmop(result,NULL,ic,FALSE);
-       
+    _endLazyDPSEvaluation();
+    }
 }
 
 /*-----------------------------------------------------------------*/
@@ -7557,27 +7958,64 @@ static void genAssign (iCode *ic)
     offset = 0 ;
     if(AOP_TYPE(right) == AOP_LIT)
        lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
+    
     if((size > 1) &&
        (AOP_TYPE(result) != AOP_REG) &&
        (AOP_TYPE(right) == AOP_LIT) &&
-       !IS_FLOAT(operandType(right)) &&
-       (lit < 256L)){
+       !IS_FLOAT(operandType(right)) 
+#ifndef LAZY_DPS_OPT
+       && (lit < 256L)
+#endif       
+       )
+    {
+#ifdef LAZY_DPS_OPT
+       D(emitcode(";", "Kevin's better literal load code"););
+       _startLazyDPSEvaluation();
+    while (size && ((unsigned int)(lit >> (offset*8)) != 0))
+       {
+           aopPut(AOP(result),
+                  aopGet(AOP(right),offset,FALSE,FALSE,TRUE),
+                  offset);
+           offset++;
+           size--;
+       }
+       /* And now fill the rest with zeros. */
+       if (size)
+       {
+           emitcode("clr","a");
+       }
+       while (size--)
+       {
+           aopPut(AOP(result), "a", offset++);
+       }
+       _endLazyDPSEvaluation();
+#else
        emitcode("clr","a");
-       while (size--) {
+       
+       _startLazyDPSEvaluation();
+       while (size--) 
+       {
            if((unsigned int)((lit >> (size*8)) & 0x0FFL)== 0)
                aopPut(AOP(result),"a",size);
            else
                aopPut(AOP(result),
-                      aopGet(AOP(right),size,FALSE,FALSE),
+                      aopGet(AOP(right),size,FALSE,FALSE,FALSE),
                       size);
        }
-    } else {
-       while (size--) {
+       _endLazyDPSEvaluation();
+#endif 
+    } 
+    else 
+    {
+       _startLazyDPSEvaluation();
+       while (size--) 
+       {
            aopPut(AOP(result),
-                  aopGet(AOP(right),offset,FALSE,FALSE),
+                  aopGet(AOP(right),offset,FALSE,FALSE,FALSE),
                   offset);
            offset++;
        }
+       _endLazyDPSEvaluation();
     }
     
 release:
@@ -7586,7 +8024,7 @@ release:
 }   
 
 /*-----------------------------------------------------------------*/
-/* genJumpTab - genrates code for jump table                       */
+/* genJumpTab - generates code for jump table                      */
 /*-----------------------------------------------------------------*/
 static void genJumpTab (iCode *ic)
 {
@@ -7597,11 +8035,11 @@ static void genJumpTab (iCode *ic)
 
     aopOp(IC_JTCOND(ic),ic,FALSE, FALSE);
     /* get the condition into accumulator */
-    l = aopGet(AOP(IC_JTCOND(ic)),0,FALSE,FALSE);
+    l = aopGet(AOP(IC_JTCOND(ic)),0,FALSE,FALSE,TRUE);
     MOVA(l);
-    /* multiply by three */
+    /* multiply by four! */
+    emitcode("add","a,acc");
     emitcode("add","a,acc");
-    emitcode("add","a,%s",aopGet(AOP(IC_JTCOND(ic)),0,FALSE,FALSE));
     freeAsmop(IC_JTCOND(ic),NULL,ic,TRUE);
 
     jtab = newiTempLabel(NULL);
@@ -7671,12 +8109,14 @@ static void genCast (iCode *ic)
         /* if they in different places then copy */
         size = AOP_SIZE(result);
         offset = 0 ;
+        _startLazyDPSEvaluation();
         while (size--) {
             aopPut(AOP(result),
-                   aopGet(AOP(right),offset,FALSE,FALSE),
+                   aopGet(AOP(right),offset,FALSE,FALSE,FALSE),
                    offset);
             offset++;
         }
+        _endLazyDPSEvaluation();
         goto release;
     }
 
@@ -7686,28 +8126,68 @@ static void genCast (iCode *ic)
 
        int p_type;
        link *type = operandType(right);
-       link *etype = getSpec(type);
 
        /* pointer to generic pointer */
        if (IS_GENPTR(ctype)) {
            char *l = zero;
            
            if (IS_PTR(type)) 
+           {
                p_type = DCL_TYPE(type);
-           else {
+           }
+           else 
+           {
+#if OLD_CAST_BEHAVIOR
+               /* KV: we are converting a non-pointer type to
+                * a generic pointer. This (ifdef'd out) code
+                * says that the resulting generic pointer 
+                * should have the same class as the storage
+                * location of the non-pointer variable.
+                * 
+                * For example, converting an int (which happens
+                * to be stored in DATA space) to a pointer results
+                * in a DATA generic pointer; if the original int
+                * in XDATA space, so will be the resulting pointer.
+                *
+                * I don't like that behavior, and thus this change:
+                * all such conversions will be forced to XDATA and
+                * throw a warning. If you want some non-XDATA
+                * type, or you want to suppress the warning, you
+                * must go through an intermediate cast, like so:
+                *
+                * char _generic *gp = (char _xdata *)(intVar);
+                */
+               link *etype = getSpec(type);             
+
                /* we have to go by the storage class */
-               p_type = PTR_TYPE(SPEC_OCLS(etype));
+               if (SPEC_OCLS(etype) != generic)
+               {
+                   p_type = PTR_TYPE(SPEC_OCLS(etype));
+               }
+               else
+#endif         
+               {
+                   /* Converting unknown class (i.e. register variable)
+                    * to generic pointer. This is not good, but
+                    * we'll make a guess (and throw a warning).
+                    */
+                   p_type = FPOINTER;
+                   werror(W_INT_TO_GEN_PTR_CAST);           
+               }
            }
                
            /* the first two bytes are known */
            size = GPTRSIZE - 1; 
            offset = 0 ;
+           _startLazyDPSEvaluation();
            while (size--) {
                aopPut(AOP(result),
-                      aopGet(AOP(right),offset,FALSE,FALSE),
+                      aopGet(AOP(right),offset,FALSE,FALSE,FALSE),
                       offset);
                offset++;
            }
+           _endLazyDPSEvaluation();
+           
            /* the last byte depending on type */
            switch (p_type) {
            case IPOINTER:
@@ -7726,7 +8206,7 @@ static void genCast (iCode *ic)
                
            default:
                /* this should never happen */
-        werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
+               werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
                       "got unknown pointer type");
                exit(1);
            }
@@ -7737,12 +8217,14 @@ static void genCast (iCode *ic)
        /* just copy the pointers */
        size = AOP_SIZE(result);
        offset = 0 ;
+       _startLazyDPSEvaluation();
        while (size--) {
            aopPut(AOP(result),
-                  aopGet(AOP(right),offset,FALSE,FALSE),
+                  aopGet(AOP(right),offset,FALSE,FALSE,FALSE),
                   offset);
            offset++;
        }
+       _endLazyDPSEvaluation();
        goto release ;
     }
     
@@ -7751,23 +8233,33 @@ static void genCast (iCode *ic)
     /* we move to result for the size of source */
     size = AOP_SIZE(right);
     offset = 0 ;
+    _startLazyDPSEvaluation();
     while (size--) {
         aopPut(AOP(result),
-               aopGet(AOP(right),offset,FALSE,FALSE),
+               aopGet(AOP(right),offset,FALSE,FALSE,FALSE),
                offset);
         offset++;
     }
+    _endLazyDPSEvaluation();
 
     /* now depending on the sign of the source && destination */
     size = AOP_SIZE(result) - AOP_SIZE(right);
     /* if unsigned or not an integral type */
-    if (SPEC_USIGN(rtype) || !IS_SPEC(rtype)) {
+    /* also, if the source is a bit, we don't need to sign extend, because
+     * it can't possibly have set the sign bit.
+     */
+    if (SPEC_USIGN(rtype) || !IS_SPEC(rtype) || AOP_TYPE(right) == AOP_CRY) 
+    {
         while (size--)
+        {
             aopPut(AOP(result),zero,offset++);
-    } else {
+        }
+    } 
+    else 
+    {
         /* we need to extend the sign :{ */
         char *l = aopGet(AOP(right),AOP_SIZE(right) - 1,
-                         FALSE,FALSE);
+                         FALSE,FALSE,TRUE);
         MOVA(l);
         emitcode("rlc","a");
         emitcode("subb","a,acc");
@@ -7819,11 +8311,11 @@ static int genDjnz (iCode *ic, iCode *ifx)
     
     if (IS_AOP_PREG(IC_RESULT(ic))) {
        emitcode("dec","%s",
-                aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
-       emitcode("mov","a,%s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+                aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE,FALSE));
+       emitcode("mov","a,%s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE,FALSE));
        emitcode("jnz","%05d$",lbl->key+100);
     } else {   
-       emitcode ("djnz","%s,%05d$",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE),
+       emitcode ("djnz","%s,%05d$",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE,FALSE),
                  lbl->key+100);
     }
     emitcode ("sjmp","%05d$",lbl1->key+100);
@@ -7873,7 +8365,7 @@ static void genReceive (iCode *ic)
 }
 
 /*-----------------------------------------------------------------*/
-/* gen390Code - generate code for 8051 based controllers            */
+/* gen390Code - generate code for Dallas 390 based controllers     */
 /*-----------------------------------------------------------------*/
 void gen390Code (iCode *lic)
 {
@@ -7882,12 +8374,15 @@ void gen390Code (iCode *lic)
 
     lineHead = lineCurr = NULL;
 
+#if 0
+    //REMOVE ME!!!
     /* print the allocation information */
     if (allocInfo)
        printAllocInfo( currFunc, codeOutFile);
+#endif
     /* if debug information required */
-/*     if (options.debug && currFunc) { */
-    if (currFunc) {
+    if (options.debug && currFunc) {
+    //jwk if (currFunc) {
        cdbSymbol(currFunc,cdbFile,FALSE,TRUE);
        _G.debugLine = 1;
        if (IS_STATIC(currFunc->etype))