changed inline asm buffers from static to dynamic size
[fw/sdcc] / src / avr / gen.c
index 8954f2131ae9133cf3c7b062aa1160adf35a3fc0..b16ce95425ff357429a4c7f8516cb2c3c3b2b515 100644 (file)
@@ -86,6 +86,8 @@ static void saverbank (int, iCode *, bool);
                          IC_RESULT(x)->aop->type == AOP_STK )
 
 #define MOVR0(x) if (strcmp(x,"r0")) emitcode("mov","r0,%s",x);
+#define MOVR24(x) if (strcmp(x,"r24")) emitcode("mov","r24,%s",x);
+#define AOP_ISHIGHREG(a,n) (a->type == AOP_REG && a->aopu.aop_reg[n] && a->aopu.aop_reg[n]->rIdx >= R16_IDX)
 #define CLRC    emitcode("clc","")
 #define SETC    emitcode("stc","")
 #define MOVA(x)
@@ -113,7 +115,7 @@ static void
 emitcode (char *inst, char *fmt, ...)
 {
        va_list ap;
-       char lb[MAX_INLINEASM];
+       char lb[INITIAL_INLINEASM];
        char *lbp = lb;
 
        va_start (ap, fmt);
@@ -140,6 +142,36 @@ emitcode (char *inst, char *fmt, ...)
        va_end (ap);
 }
 
+/*-----------------------------------------------------------------*/
+/* hasInc - operand is incremented before any other use            */
+/*-----------------------------------------------------------------*/
+static iCode *
+hasInc (operand *op, iCode *ic)
+{
+  sym_link *type = operandType(op);
+  sym_link *retype = getSpec (type);
+  iCode *lic = ic->next;
+  int isize ;
+  
+  if (IS_BITVAR(retype)||!IS_PTR(type)) return NULL;
+  isize = getSize(type->next);
+  while (lic) {
+    /* if operand of the form op = op + <sizeof *op> */
+    if (lic->op == '+' && isOperandEqual(IC_LEFT(lic),op) &&
+       isOperandEqual(IC_RESULT(lic),op) && 
+       isOperandLiteral(IC_RIGHT(lic)) &&
+       operandLitValue(IC_RIGHT(lic)) == isize) {
+      return lic;
+    }
+    /* if the operand used or deffed */
+    if (bitVectBitValue(ic->uses,op->key) || ((unsigned) ic->defKey == op->key)) {
+      return NULL;
+    }
+    lic = lic->next;
+  }
+  return NULL;
+}
+
 /*-----------------------------------------------------------------*/
 /* getFreePtr - returns X or Z whichever is free or can be pushed  */
 /*-----------------------------------------------------------------*/
@@ -226,7 +258,6 @@ getFreePtr (iCode * ic, asmop ** aopp, bool result, bool zonly)
                return NULL;
        }
 
-       piCode (ic, stdout);
        /* other wise this is true end of the world */
        werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
                "getFreePtr should never reach here");
@@ -506,7 +537,7 @@ sameRegs (asmop * aop1, asmop * aop2)
 static int
 isRegPair (asmop * aop)
 {
-       if (!aop || aop->size != 2)
+       if (!aop || aop->size < 2)
                return 0;
        if (aop->type == AOP_X || aop->type == AOP_Z)
                return 1;
@@ -568,7 +599,7 @@ aopOp (operand * op, iCode * ic, bool result)
 
 
        /* if the type is a conditional */
-       if (sym->regType == REG_CND) {
+       if (sym->regType & REG_CND) {
                aop = op->aop = sym->aop = newAsmop (AOP_CRY);
                aop->size = 0;
                return;
@@ -1126,17 +1157,17 @@ genNot (iCode * ic)
                genNotFloat (IC_LEFT (ic), IC_RESULT (ic));
                goto release;
        }
-       emitcode ("clr", "r0");
+       emitcode ("clr", "r24");
        tlbl = newiTempLabel (NULL);
        size = AOP_SIZE (IC_LEFT (ic));
        offset = 0;
        if (size == 1) {
-               emitcode ("cpse", "%s,r0", aopGet (AOP (IC_LEFT (ic)), 0));
+               emitcode ("cpse", "%s,r24", aopGet (AOP (IC_LEFT (ic)), 0));
        }
        else {
                while (size--) {
                        if (offset)
-                               emitcode ("cpc", "%s,r0",
+                               emitcode ("cpc", "%s,r24",
                                          aopGet (AOP (IC_LEFT (ic)),
                                                  offset));
                        else
@@ -1147,9 +1178,9 @@ genNot (iCode * ic)
                }
                emitcode ("bne", "L%05d", tlbl->key);
        }
-       emitcode ("ldi", "r0,1");
+       emitcode ("ldi", "r24,1");
        emitcode ("", "L%05d:", tlbl->key);
-       aopPut (AOP (IC_RESULT (ic)), "r0", 0);
+       aopPut (AOP (IC_RESULT (ic)), "r24", 0);
        size = AOP_SIZE (IC_RESULT (ic)) - 1;
        offset = 1;
        while (size--)
@@ -1694,11 +1725,11 @@ genEndFunction (iCode * ic)
        }
        if (bitVectBitValue (sym->regsUsed, R27_IDX)) {
                _G.nRegsSaved--;
-               emitcode ("push", "r27");
+               emitcode ("pop", "r27");
        }
        if (bitVectBitValue (sym->regsUsed, R26_IDX)) {
                _G.nRegsSaved--;
-               emitcode ("push", "r26");
+               emitcode ("pop", "r26");
        }
        for (i = R15_IDX; i >= R2_IDX; i--) {
                if (bitVectBitValue (sym->regsUsed, i)) {
@@ -1785,7 +1816,7 @@ genLabel (iCode * ic)
 static void
 genGoto (iCode * ic)
 {
-       emitcode ("rjmp", "L%05d:", (IC_LABEL (ic)->key + 100));
+       emitcode ("rjmp", "L%05d", (IC_LABEL (ic)->key + 100));
 }
 
 /*-----------------------------------------------------------------*/
@@ -1845,7 +1876,7 @@ genPlusIncr (iCode * ic)
                        return TRUE;
                }
                emitcode ("subi", "%s,lo8(%d)",
-                         aopGet (AOP (IC_LEFT (ic)), 0), -icount);
+                         aopGet (AOP (IC_LEFT (ic)), 0), 0-icount);
                return TRUE;
        }
 
@@ -1862,21 +1893,21 @@ genPlusIncr (iCode * ic)
 
                /* use subi */
                emitcode ("subi", "%s,lo8(%d)",
-                         aopGet (AOP (IC_RESULT (ic)), 0), -icount);
+                         aopGet (AOP (IC_RESULT (ic)), 0), 0-icount);
                emitcode ("sbci", "%s,hi8(%d)",
-                         aopGet (AOP (IC_RESULT (ic)), 1), -icount);
+                         aopGet (AOP (IC_RESULT (ic)), 1), 0-icount);
                return TRUE;
        }
 
        /* for 32 bit longs */
        emitcode ("subi", "%s,lo8(%d)", aopGet (AOP (IC_RESULT (ic)), 0),
-                 -icount);
+                 0-icount);
        emitcode ("sbci", "%s,hi8(%d)", aopGet (AOP (IC_RESULT (ic)), 1),
-                 -icount);
+                 0-icount);
        emitcode ("sbci", "%s,hlo8(%d)", aopGet (AOP (IC_RESULT (ic)), 2),
-                 -icount);
+                 0-icount);
        emitcode ("sbci", "%s,hhi8(%d)", aopGet (AOP (IC_RESULT (ic)), 3),
-                 -icount);
+                 0-icount);
        return TRUE;
 
 }
@@ -2605,62 +2636,40 @@ genBitWise (iCode * ic, iCode * ifx, int bitop)
                        else {  /* right not power of two */
                                int eh = OP_SYMBOL (left)->liveTo <= ic->seq;
                                if (size == 1) {
-                                       if (eh) {
+                                       if (eh && AOP_ISHIGHREG(AOP(IC_LEFT(ic)),0)) {
                                                emitcode (bopnames_lit[bitop],
                                                          "%s,lo8(%d)",
-                                                         aopGet (AOP
-                                                                 (IC_LEFT
-                                                                  (ic)), 0),
-                                                         lit);
+                                                         aopGet (AOP (IC_LEFT (ic)), 0), lit);
                                        }
                                        else {
-                                               MOVR0 (aopGet
-                                                      (AOP (IC_LEFT (ic)),
-                                                       0));
-                                               emitcode (bopnames_lit[bitop],
-                                                         "r0,lo8(%d)", lit);
+                                               MOVR24 (aopGet (AOP (IC_LEFT (ic)), 0));
+                                               emitcode (bopnames_lit[bitop], "r24,lo8(%d)", lit);
                                        }
                                        lbl = newiTempLabel (NULL);
                                        if (IC_TRUE (ifx)) {
-                                               emitcode ("breq", "L%05d",
-                                                         lbl->key);
-                                               emitcode ("rjmp", "L%05d",
-                                                         IC_TRUE (ifx)->key);
+                                               emitcode ("breq", "L%05d", lbl->key);
+                                               emitcode ("rjmp", "L%05d", IC_TRUE (ifx)->key);
                                        }
                                        else {
-                                               emitcode ("brne", "L%05d",
-                                                         lbl->key);
-                                               emitcode ("rjmp", "L%05d",
-                                                         IC_FALSE (ifx)->
-                                                         key);
+                                               emitcode ("brne", "L%05d", lbl->key);
+                                               emitcode ("rjmp", "L%05d", IC_FALSE (ifx)-> key);
                                        }
                                        emitcode ("", "L%05d:", lbl->key);
                                }
                                else if (size == 2) {
-                                       emitcode ("mov", "r24,%s",
-                                                 aopGet (AOP (IC_LEFT (ic)),
-                                                         0));
-                                       emitcode ("mov", "r25,%s",
-                                                 aopGet (AOP (IC_LEFT (ic)),
-                                                         1));
-                                       emitcode (bopnames_lit[bitop],
-                                                 "r24,lo8(%d)", lit);
-                                       emitcode (bopnames_lit[bitop],
-                                                 "r25,hi8(%d)", lit);
+                                       emitcode ("mov", "r24,%s", aopGet (AOP (IC_LEFT (ic)), 0));
+                                       emitcode ("mov", "r25,%s", aopGet (AOP (IC_LEFT (ic)), 1));
+                                       emitcode (bopnames_lit[bitop], "r24,lo8(%d)", lit);
+                                       emitcode (bopnames_lit[bitop], "r25,hi8(%d)", lit);
                                        emitcode ("sbiw", "r24,0");
                                        lbl = newiTempLabel (NULL);
                                        if (IC_TRUE (ifx)) {
-                                               emitcode ("breq", "L%05d",
-                                                         lbl->key);
-                                               emitcode ("rjmp", "L%05d",
-                                                         IC_TRUE (ifx)->key);
+                                               emitcode ("breq", "L%05d", lbl->key);
+                                               emitcode ("rjmp", "L%05d", IC_TRUE (ifx)->key);
                                        }
                                        else {
-                                               emitcode ("brne", "L%05d",
-                                                         lbl->key);
-                                               emitcode ("rjmp", "L%05d",
-                                                         IC_FALSE (ifx)->
-                                                         key);
+                                               emitcode ("brne", "L%05d", lbl->key);
+                                               emitcode ("rjmp", "L%05d", IC_FALSE (ifx)->key);
                                        }
                                        emitcode ("", "L%05d:", lbl->key);
                                }
@@ -2668,43 +2677,28 @@ genBitWise (iCode * ic, iCode * ifx, int bitop)
                                        lbl = newiTempLabel (NULL);
                                        lbl1 = newiTempLabel (NULL);
                                        while (size--) {
-                                               if (eh) {
-                                                       emitcode (bopnames_lit
-                                                                 [bitop],
-                                                                 "%s,lo8(%d)",
-                                                                 aopGet (AOP
-                                                                         (IC_LEFT
-                                                                          (ic)),
-                                                                         offset),
+                                               if (eh && AOP_ISHIGHREG(AOP(IC_LEFT(ic)),offset)) {
+                                                       emitcode (bopnames_lit [bitop], "%s,lo8(%d)",
+                                                                 aopGet (AOP (IC_LEFT (ic)), offset),
                                                                  lit);
                                                }
                                                else {
-                                                       MOVR0 (aopGet
-                                                              (AOP
-                                                               (IC_LEFT
-                                                                (ic)),
-                                                               offset));
-                                                       emitcode ("andi",
-                                                                 "r0,lo8(%d)",
-                                                                 lit);
+                                                       char *l = aopGet (AOP (IC_LEFT (ic)), offset);
+                                                       MOVR24 (l);
+                                                       emitcode ("andi", "r24,lo8(%d)", lit);
                                                }
-                                               emitcode ("brne", "L%05d",
-                                                         lbl->key);
+                                               emitcode ("brne", "L%05d", lbl->key);
                                                offset++;
                                        }
                                        /* all are zero */
                                        if (IC_FALSE (ifx))
-                                               emitcode ("rjmp", "L%05d",
-                                                         IC_FALSE (ifx)->
-                                                         key);
+                                               emitcode ("rjmp", "L%05d", IC_FALSE (ifx)-> key);
                                        else
-                                               emitcode ("rjmp", "L%05d",
-                                                         lbl1->key);
+                                               emitcode ("rjmp", "L%05d", lbl1->key);
                                        emitcode ("", "L%05d:", lbl->key);
                                        /* not zero */
                                        if (IC_TRUE (ifx))
-                                               emitcode ("rjmp", "L%05d",
-                                                         IC_TRUE (ifx)->key);
+                                               emitcode ("rjmp", "L%05d", IC_TRUE (ifx)->key);
                                        emitcode ("", "L%05d:", lbl1->key);
 
                                }
@@ -2715,25 +2709,18 @@ genBitWise (iCode * ic, iCode * ifx, int bitop)
                        int reh = OP_SYMBOL (right)->liveTo <= ic->seq;
                        if (size == 1) {
                                if (eh) {
-                                       emitcode (bopnames[bitop], "%s,%s",
-                                                 aopGet (AOP (IC_LEFT (ic)),
-                                                         0),
-                                                 aopGet (AOP (IC_RIGHT (ic)),
-                                                         0));
+                                       emitcode (bopnames[bitop], "%s,%s", aopGet (AOP (IC_LEFT (ic)), 0),
+                                                 aopGet (AOP (IC_RIGHT (ic)), 0));
                                }
                                else if (reh) {
                                        emitcode (bopnames[bitop], "%s,%s",
-                                                 aopGet (AOP (IC_RIGHT (ic)),
-                                                         0),
-                                                 aopGet (AOP (IC_LEFT (ic)),
-                                                         0));
+                                                 aopGet (AOP (IC_RIGHT (ic)), 0),
+                                                 aopGet (AOP (IC_LEFT (ic)), 0));
                                }
                                else {
-                                       MOVR0 (aopGet
-                                              (AOP (IC_LEFT (ic)), 0));
+                                       MOVR0 (aopGet (AOP (IC_LEFT (ic)), 0));
                                        emitcode (bopnames[bitop], "r0,%s",
-                                                 aopGet (AOP (IC_RIGHT (ic)),
-                                                         0));
+                                                 aopGet (AOP (IC_RIGHT (ic)), 0));
                                }
                                lbl = newiTempLabel (NULL);
                                if (IC_TRUE (ifx)) {
@@ -2761,13 +2748,11 @@ genBitWise (iCode * ic, iCode * ifx, int bitop)
                                lbl = newiTempLabel (NULL);
                                if (IC_TRUE (ifx)) {
                                        emitcode ("breq", "L%05d", lbl->key);
-                                       emitcode ("rjmp", "L%05d",
-                                                 IC_TRUE (ifx)->key);
+                                       emitcode ("rjmp", "L%05d", IC_TRUE (ifx)->key);
                                }
                                else {
                                        emitcode ("brne", "L%05d", lbl->key);
-                                       emitcode ("rjmp", "L%05d",
-                                                 IC_FALSE (ifx)->key);
+                                       emitcode ("rjmp", "L%05d", IC_FALSE (ifx)->key);
                                }
                                emitcode ("", "L%05d:", lbl->key);
                        }
@@ -2776,54 +2761,32 @@ genBitWise (iCode * ic, iCode * ifx, int bitop)
                                lbl1 = newiTempLabel (NULL);
                                while (size--) {
                                        if (eh) {
-                                               emitcode (bopnames[bitop],
-                                                         "%s,%s",
-                                                         aopGet (AOP
-                                                                 (IC_LEFT
-                                                                  (ic)),
-                                                                 offset),
-                                                         aopGet (AOP
-                                                                 (IC_RIGHT
-                                                                  (ic)),
-                                                                 offset));
+                                               emitcode (bopnames[bitop], "%s,%s",
+                                                         aopGet (AOP (IC_LEFT (ic)), offset),
+                                                         aopGet (AOP (IC_RIGHT (ic)), offset));
                                        }
                                        else if (reh) {
-                                               emitcode (bopnames[bitop],
-                                                         "%s,%s",
-                                                         aopGet (AOP
-                                                                 (IC_RIGHT
-                                                                  (ic)),
-                                                                 offset),
-                                                         aopGet (AOP
-                                                                 (IC_LEFT
-                                                                  (ic)),
-                                                                 offset));
+                                               emitcode (bopnames[bitop], "%s,%s",
+                                                         aopGet (AOP (IC_RIGHT (ic)), offset),
+                                                         aopGet (AOP (IC_LEFT (ic)), offset));
                                        }
                                        else {
-                                               MOVR0 (aopGet
-                                                      (AOP (IC_LEFT (ic)),
-                                                       offset));
-                                               emitcode (bopnames[bitop],
-                                                         "r0,%s",
-                                                         aopGet (AOP
-                                                                 (IC_RIGHT
-                                                                  (ic)),
-                                                                 offset));
+                                               MOVR0 (aopGet (AOP (IC_LEFT (ic)), offset));
+                                               emitcode (bopnames[bitop], "r0,%s",
+                                                         aopGet (AOP (IC_RIGHT (ic)), offset));
                                        }
                                        emitcode ("brne", "L%05d", lbl->key);
                                        offset++;
                                }
                                /* all are zero */
                                if (IC_FALSE (ifx))
-                                       emitcode ("rjmp", "L%05d",
-                                                 IC_FALSE (ifx)->key);
+                                       emitcode ("rjmp", "L%05d", IC_FALSE (ifx)->key);
                                else
                                        emitcode ("rjmp", "L%05d", lbl1->key);
                                emitcode ("", "L%05d:", lbl->key);
                                /* not zero */
                                if (IC_TRUE (ifx))
-                                       emitcode ("rjmp", "L%05d",
-                                                 IC_TRUE (ifx)->key);
+                                       emitcode ("rjmp", "L%05d", IC_TRUE (ifx)->key);
                                emitcode ("", "L%05d:", lbl1->key);
 
                        }
@@ -2856,19 +2819,18 @@ genBitWise (iCode * ic, iCode * ifx, int bitop)
                        }
                }
                if (samerl) {
-                       if (AOP_TYPE (IC_RIGHT (ic)) == AOP_LIT
-                           && (bitop == AVR_AND || bitop == AVR_OR)) {
+                       if (AOP_TYPE (IC_RIGHT (ic)) == AOP_LIT && 
+                           AOP_ISHIGHREG(AOP(IC_LEFT(ic)),offset) &&
+                           (bitop == AVR_AND || bitop == AVR_OR)) {
                                emitcode (bopnames_lit[bitop], "%s,%s(%d)",
                                          aopGet (AOP (IC_LEFT (ic)), offset),
                                          larray[offset],
-                                         (int) floatFromVal (AOP (right)->
-                                                             aopu.aop_lit));
+                                         (int) floatFromVal (AOP (right)-> aopu.aop_lit));
                        }
                        else {
                                emitcode (bopnames[bitop], "%s,%s",
                                          aopGet (AOP (IC_LEFT (ic)), offset),
-                                         aopGet (AOP (IC_RIGHT (ic)),
-                                                 offset));
+                                         aopGet (AOP (IC_RIGHT (ic)), offset));
                        }
                }
                else if (samerr) {
@@ -2924,11 +2886,11 @@ genXor (iCode * ic, iCode * ifx)
 static void
 genInline (iCode * ic)
 {
-       char buffer[MAX_INLINEASM];
-       char *bp = buffer;
-       char *bp1 = buffer;
+       char *buffer, *bp, *bp1;
 
        _G.inLine += (!options.asmpeep);
+
+       buffer = bp = bp1 = Safe_calloc(1, strlen(IC_INLINE(ic)+1));
        strcpy (buffer, IC_INLINE (ic));
 
        /* emit each line as a code */
@@ -3087,8 +3049,14 @@ genShiftLeftLit (iCode * ic)
                if (!sameRegs (AOP (left), AOP (result)))
                        aopPut (AOP (result), aopGet (AOP (left), 0), 0);
                if (shCount >= 4) {
-                       emitcode ("swap", "%s", aopGet (AOP (result), 0));
-                       emitcode ("andi", "%s,0xf0");
+                       if (AOP_ISHIGHREG(AOP(result),0)) {
+                               emitcode ("swap", "%s", aopGet (AOP (result), 0));
+                               emitcode ("andi", "%s,0xf0");
+                       } else {
+                               emitcode ("ldi","r24,0xf0");
+                               emitcode ("swap", "%s", aopGet (AOP (result), 0));
+                               emitcode ("and", "%s,r24");
+                       }
                        shCount -= 4;
                }
                if (shCount == 1) {
@@ -3102,10 +3070,14 @@ genShiftLeftLit (iCode * ic)
        case 2:
                if (shCount >= 12) {
                        aopPut (AOP (result), aopGet (AOP (left), 0), 1);
-                       aopPut (AOP (result), zero, 0);
+                       aopPut (AOP (result), zero, 0);                 
                        emitcode ("swap", "%s", aopGet (AOP (result), 1));
-                       emitcode ("andi", "%s,0xf0",
-                                 aopGet (AOP (result), 1));
+                       if (AOP_ISHIGHREG(AOP(result),1)) {
+                               emitcode ("andi", "%s,0xf0", aopGet (AOP (result), 1));
+                       } else {
+                               emitcode ("ldi","r24,0xf0");
+                               emitcode ("and", "%s,r24", aopGet (AOP (result), 1));
+                       }
                        shCount -= 12;
                        lByteZ = 1;
                }
@@ -3123,20 +3095,27 @@ genShiftLeftLit (iCode * ic)
                                aopPut (AOP (result), aopGet (AOP (left), 1),
                                        1);
                        }
-                       emitcode ("mov", "r1,%s", aopGet (AOP (result), 0));
+                       emitcode ("mov", "r24,%s", aopGet (AOP (result), 0));
+                       emitcode ("andi", "r24,0x0f");
+                       if (!(AOP_ISHIGHREG(AOP(result),0) && AOP_ISHIGHREG(AOP(result),1))) {
+                               emitcode("ldi","r25,0xf0");
+                       }
                        emitcode ("swap", "%s", aopGet (AOP (result), 0));
-                       emitcode ("andi", "%s,0xf0",
-                                 aopGet (AOP (result), 0));
-                       emitcode ("andi", "r1,0x0f");
+                       if (AOP_ISHIGHREG(AOP(result),0)) {
+                               emitcode ("andi", "%s,0xf0", aopGet (AOP (result), 0));
+                       } else {
+                               emitcode ("and", "%s,r25", aopGet (AOP (result), 0));
+                       }
                        emitcode ("swap", "%s", aopGet (AOP (result), 1));
-                       emitcode ("andi", "%s,0xf0",
-                                 aopGet (AOP (result), 1));
-                       emitcode ("or", "%s,r1", aopGet (AOP (result), 1));
+                       if (AOP_ISHIGHREG(AOP(result),1)) {
+                               emitcode ("andi", "%s,0xf0", aopGet (AOP (result), 1));
+                       } else {
+                               emitcode ("and", "%s,r25", aopGet (AOP (result), 1));
+                       }
+                       emitcode ("or", "%s,r24", aopGet (AOP (result), 1));
                        while (shCount--) {
-                               emitcode ("lsl", "%s",
-                                         aopGet (AOP (result), 0));
-                               emitcode ("rol", "%s",
-                                         aopGet (AOP (result), 1));
+                               emitcode ("lsl", "%s", aopGet (AOP (result), 0));
+                               emitcode ("rol", "%s", aopGet (AOP (result), 1));
                        }
                }
                if (!lByteZ && !sameRegs (AOP (result), AOP (left))
@@ -3150,14 +3129,11 @@ genShiftLeftLit (iCode * ic)
                }
                while (shCount--) {
                        if (lByteZ) {
-                               emitcode ("lsl", "%s",
-                                         aopGet (AOP (result), 1));
+                               emitcode ("lsl", "%s", aopGet (AOP (result), 1));
                        }
                        else {
-                               emitcode ("lsl", "%s",
-                                         aopGet (AOP (result), 0));
-                               emitcode ("rol", "%s",
-                                         aopGet (AOP (result), 1));
+                               emitcode ("lsl", "%s", aopGet (AOP (result), 0));
+                               emitcode ("rol", "%s", aopGet (AOP (result), 1));
                        }
                }
                break;
@@ -3204,38 +3180,28 @@ genShiftLeftLit (iCode * ic)
                        switch (lByteZ) {
                        case 0:
                                while (shCount--) {
-                                       emitcode ("lsl", "%s",
-                                                 aopGet (AOP (result), 0));
-                                       emitcode ("rol", "%s",
-                                                 aopGet (AOP (result), 1));
-                                       emitcode ("rol", "%s",
-                                                 aopGet (AOP (result), 2));
-                                       emitcode ("rol", "%s",
-                                                 aopGet (AOP (result), 3));
+                                       emitcode ("lsl", "%s", aopGet (AOP (result), 0));
+                                       emitcode ("rol", "%s", aopGet (AOP (result), 1));
+                                       emitcode ("rol", "%s", aopGet (AOP (result), 2));
+                                       emitcode ("rol", "%s", aopGet (AOP (result), 3));
                                }
                                break;
                        case 1:
                                while (shCount--) {
-                                       emitcode ("lsl", "%s",
-                                                 aopGet (AOP (result), 1));
-                                       emitcode ("rol", "%s",
-                                                 aopGet (AOP (result), 2));
-                                       emitcode ("rol", "%s",
-                                                 aopGet (AOP (result), 3));
+                                       emitcode ("lsl", "%s", aopGet (AOP (result), 1));
+                                       emitcode ("rol", "%s", aopGet (AOP (result), 2));
+                                       emitcode ("rol", "%s", aopGet (AOP (result), 3));
                                }
                                break;
                        case 2:
                                while (shCount--) {
-                                       emitcode ("lsl", "%s",
-                                                 aopGet (AOP (result), 2));
-                                       emitcode ("rol", "%s",
-                                                 aopGet (AOP (result), 3));
+                                       emitcode ("lsl", "%s", aopGet (AOP (result), 2));
+                                       emitcode ("rol", "%s", aopGet (AOP (result), 3));
                                }
                                break;
                        case 3:
                                while (shCount--) {
-                                       emitcode ("lsl", "%s",
-                                                 aopGet (AOP (result), 3));
+                                       emitcode ("lsl", "%s", aopGet (AOP (result), 3));
                                }
                                break;
                        }
@@ -3358,15 +3324,9 @@ genShiftRightLit (iCode * ic)
                                size = AOP_SIZE (result);
                                while (size--) {
                                        if (offset == (size - 1))
-                                               emitcode ("asr", "%s",
-                                                         aopGet (AOP
-                                                                 (result),
-                                                                 offset));
+                                               emitcode ("asr", "%s", aopGet (AOP (result), offset));
                                        else
-                                               emitcode ("lsr", "%s",
-                                                         aopGet (AOP
-                                                                 (result),
-                                                                 offset));
+                                               emitcode ("lsr", "%s", aopGet (AOP (result), offset));
                                        offset--;
                                }
                        }
@@ -3378,13 +3338,9 @@ genShiftRightLit (iCode * ic)
                        offset = size - 1;
                        while (size--) {
                                if (offset == (size - 1))
-                                       emitcode ("asr", "%s",
-                                                 aopGet (AOP (result),
-                                                         offset));
+                                       emitcode ("asr", "%s", aopGet (AOP (result), offset));
                                else
-                                       emitcode ("lsr", "%s",
-                                                 aopGet (AOP (result),
-                                                         offset));
+                                       emitcode ("lsr", "%s", aopGet (AOP (result), offset));
                                offset--;
                        }
                        emitcode ("dec", "r24");
@@ -3404,7 +3360,12 @@ genShiftRightLit (iCode * ic)
                        aopPut (AOP (result), aopGet (AOP (left), 0), 0);
                if (shCount >= 4) {
                        emitcode ("swap", "%s", aopGet (AOP (result), 0));
-                       emitcode ("andi", "%s,0x0f");
+                       if (AOP_ISHIGHREG(AOP(result),0)) {
+                               emitcode ("andi", "%s,0x0f",aopGet(AOP(result),0));
+                       } else {
+                               emitcode ("ldi","r24,0x0f");
+                               emitcode ("and", "%s,r24",aopGet(AOP(result),0));
+                       }
                        shCount -= 4;
                }
                while (shCount--)
@@ -3415,8 +3376,12 @@ genShiftRightLit (iCode * ic)
                        aopPut (AOP (result), aopGet (AOP (left), 1), 0);
                        aopPut (AOP (result), zero, 1);
                        emitcode ("swap", "%s", aopGet (AOP (result), 0));
-                       emitcode ("andi", "%s,0x0f",
-                                 aopGet (AOP (result), 0));
+                       if (AOP_ISHIGHREG(AOP(result),0)) {
+                               emitcode ("andi", "%s,0x0f", aopGet (AOP (result), 0));
+                       } else {
+                               emitcode ("ldi","r24,0x0f");
+                               emitcode ("and", "%s,r24",aopGet(AOP(result),0));
+                       }
                        shCount -= 12;
                        hByteZ = 1;
                }
@@ -3429,25 +3394,30 @@ genShiftRightLit (iCode * ic)
                if (shCount >= 4) {
                        shCount -= 4;
                        if (!sameRegs (AOP (left), AOP (result))) {
-                               aopPut (AOP (result), aopGet (AOP (left), 0),
-                                       0);
-                               aopPut (AOP (result), aopGet (AOP (left), 1),
-                                       1);
+                               aopPut (AOP (result), aopGet (AOP (left), 0), 0);
+                               aopPut (AOP (result), aopGet (AOP (left), 1), 1);
+                       }
+                       if (!(AOP_ISHIGHREG(AOP(result),0) && AOP_ISHIGHREG(AOP(result),1))) {
+                               emitcode("ldi","r25,0x0f");
                        }
-                       emitcode ("mov", "r1,%s", aopGet (AOP (result), 1));
+                       emitcode ("mov", "r24,%s", aopGet (AOP (result), 1));
+                       emitcode ("andi", "r24,0xf0");
                        emitcode ("swap", "%s", aopGet (AOP (result), 0));
-                       emitcode ("andi", "%s,0x0f",
-                                 aopGet (AOP (result), 0));
-                       emitcode ("andi", "r1,0xf0");
-                       emitcode ("or", "%s,r1", aopGet (AOP (result), 0));
+                       if (AOP_ISHIGHREG(AOP(result),0)) {
+                               emitcode ("andi", "%s,0x0f", aopGet (AOP (result), 0));
+                       } else {
+                               emitcode ("and", "%s,r25", aopGet (AOP (result), 0));
+                       }
+                       emitcode ("or", "%s,r24", aopGet (AOP (result), 0));
                        emitcode ("swap", "%s", aopGet (AOP (result), 1));
-                       emitcode ("andi", "%s,0x0f",
-                                 aopGet (AOP (result), 1));
+                       if (AOP_ISHIGHREG(AOP(result),1)) {
+                               emitcode ("andi", "%s,0x0f", aopGet (AOP (result), 1));
+                       } else {
+                               emitcode ("and", "%s,r24", aopGet (AOP (result), 1));                           
+                       }
                        while (shCount--) {
-                               emitcode ("lsr", "%s",
-                                         aopGet (AOP (result), 1));
-                               emitcode ("ror", "%s",
-                                         aopGet (AOP (result), 0));
+                               emitcode ("lsr", "%s", aopGet (AOP (result), 1));
+                               emitcode ("ror", "%s", aopGet (AOP (result), 0));
                        }
 
                }
@@ -3455,21 +3425,17 @@ genShiftRightLit (iCode * ic)
                    && shCount) {
                        offset = 0;
                        while (size--) {
-                               aopPut (AOP (result),
-                                       aopGet (AOP (left), offset), offset);
+                               aopPut (AOP (result), aopGet (AOP (left), offset), offset);
                                offset++;
                        }
                }
                while (shCount--) {
                        if (hByteZ) {
-                               emitcode ("lsr", "%s",
-                                         aopGet (AOP (result), 0));
+                               emitcode ("lsr", "%s", aopGet (AOP (result), 0));
                        }
                        else {
-                               emitcode ("lsr", "%s",
-                                         aopGet (AOP (result), 1));
-                               emitcode ("ror", "%s",
-                                         aopGet (AOP (result), 0));
+                               emitcode ("lsr", "%s", aopGet (AOP (result), 1));
+                               emitcode ("ror", "%s", aopGet (AOP (result), 0));
                        }
                }
                break;
@@ -3517,38 +3483,28 @@ genShiftRightLit (iCode * ic)
                        switch (hByteZ) {
                        case 0:
                                while (shCount--) {
-                                       emitcode ("lsr", "%s",
-                                                 aopGet (AOP (result), 3));
-                                       emitcode ("ror", "%s",
-                                                 aopGet (AOP (result), 2));
-                                       emitcode ("ror", "%s",
-                                                 aopGet (AOP (result), 1));
-                                       emitcode ("ror", "%s",
-                                                 aopGet (AOP (result), 0));
+                                       emitcode ("lsr", "%s", aopGet (AOP (result), 3));
+                                       emitcode ("ror", "%s", aopGet (AOP (result), 2));
+                                       emitcode ("ror", "%s", aopGet (AOP (result), 1));
+                                       emitcode ("ror", "%s", aopGet (AOP (result), 0));
                                }
                                break;
                        case 1:
                                while (shCount--) {
-                                       emitcode ("lsr", "%s",
-                                                 aopGet (AOP (result), 2));
-                                       emitcode ("ror", "%s",
-                                                 aopGet (AOP (result), 1));
-                                       emitcode ("ror", "%s",
-                                                 aopGet (AOP (result), 0));
+                                       emitcode ("lsr", "%s", aopGet (AOP (result), 2));
+                                       emitcode ("ror", "%s", aopGet (AOP (result), 1));
+                                       emitcode ("ror", "%s", aopGet (AOP (result), 0));
                                }
                                break;
                        case 2:
                                while (shCount--) {
-                                       emitcode ("lsr", "%s",
-                                                 aopGet (AOP (result), 1));
-                                       emitcode ("ror", "%s",
-                                                 aopGet (AOP (result), 0));
+                                       emitcode ("lsr", "%s", aopGet (AOP (result), 1));
+                                       emitcode ("ror", "%s", aopGet (AOP (result), 0));
                                }
                                break;
                        case 3:
                                while (shCount--) {
-                                       emitcode ("lsr", "%s",
-                                                 aopGet (AOP (result), 0));
+                                       emitcode ("lsr", "%s", aopGet (AOP (result), 0));
                                }
                                break;
                        }
@@ -3601,8 +3557,7 @@ genRightShift (iCode * ic)
        sign = !SPEC_USIGN (letype);
        if (!sameRegs (AOP (left), AOP (result))) {
                while (size--) {
-                       aopPut (AOP (result), aopGet (AOP (left), offset),
-                               offset);
+                       aopPut (AOP (result), aopGet (AOP (left), offset), offset);
                        offset++;
                }
                size = AOP_SIZE (result);
@@ -3611,11 +3566,9 @@ genRightShift (iCode * ic)
        while (size--) {
                if (first) {
                        if (sign)
-                               emitcode ("asr", "%s",
-                                         aopGet (AOP (result), offset));
+                               emitcode ("asr", "%s", aopGet (AOP (result), offset));
                        else
-                               emitcode ("lsr", "%s",
-                                         aopGet (AOP (result), offset));
+                               emitcode ("lsr", "%s", aopGet (AOP (result), offset));
                        first = 0;
                }
                else
@@ -3633,10 +3586,53 @@ genRightShift (iCode * ic)
 }
 
 /*-----------------------------------------------------------------*/
-/* R0Rsh - shift right r0 by known count                           */
+/* RRsh - shift right rn by known count                            */
+/*-----------------------------------------------------------------*/
+static void
+RRsh (int shCount,int reg)
+{
+       shCount &= 0x0007;      // shCount : 0..7
+
+       switch (shCount) {
+       case 0:
+               break;
+       case 1:
+               emitcode ("lsr", "r%d",reg);
+               break;
+       case 2:
+               emitcode ("lsr", "r%d",reg);
+               emitcode ("lsr", "r%d",reg);
+               break;
+       case 3:
+               emitcode ("swap", "r%d",reg);
+               emitcode ("lsl", "r%d",reg);
+               break;
+       case 4:
+               emitcode ("swap", "r%d",reg);
+               break;
+       case 5:
+               emitcode ("swap", "r%d",reg);
+               emitcode ("lsr", "r%d",reg);
+               break;
+       case 6:
+               emitcode ("swap","r%d",reg);
+               emitcode ("lsr", "r%d",reg);
+               emitcode ("lsr", "r%d",reg);
+               break;
+       case 7:
+               emitcode ("swap","r%d",reg);
+               emitcode ("lsr", "r%d",reg);
+               emitcode ("lsr", "r%d",reg);
+               emitcode ("lsr", "r%d",reg);
+               break;
+       }
+}
+
+/*-----------------------------------------------------------------*/
+/* RLsh - shift left rn by known count                             */
 /*-----------------------------------------------------------------*/
 static void
-R0Rsh (int shCount)
+RLsh (int shCount, int reg)
 {
        shCount &= 0x0007;      // shCount : 0..7
 
@@ -3644,33 +3640,33 @@ R0Rsh (int shCount)
        case 0:
                break;
        case 1:
-               emitcode ("lsr", "r0");
+               emitcode ("lsl", "r%d",reg);
                break;
        case 2:
-               emitcode ("lsr", "r0");
-               emitcode ("lsr", "r0");
+               emitcode ("lsl", "r%d",reg);
+               emitcode ("lsl", "r%d",reg);
                break;
        case 3:
-               emitcode ("swap", "r0");
-               emitcode ("lsl", "r0");
+               emitcode ("swap","r%d",reg);
+               emitcode ("lsr", "r%d",reg);
                break;
        case 4:
-               emitcode ("swap", "r0");
+               emitcode ("swap", "r%d",reg);
                break;
        case 5:
-               emitcode ("swap", "r0");
-               emitcode ("lsr", "r0");
+               emitcode ("swap","r%d",reg);
+               emitcode ("lsl", "r%d",reg);
                break;
        case 6:
-               emitcode ("swap", "r0");
-               emitcode ("lsr", "r0");
-               emitcode ("lsr", "r0");
+               emitcode ("swap","r%d",reg);
+               emitcode ("lsl", "r%d",reg);
+               emitcode ("lsl", "r%d",reg);
                break;
        case 7:
-               emitcode ("swap", "r0");
-               emitcode ("lsr", "r0");
-               emitcode ("lsr", "r0");
-               emitcode ("lsr", "r0");
+               emitcode ("swap","r%d",reg);
+               emitcode ("lsl", "r%d",reg);
+               emitcode ("lsl", "r%d",reg);
+               emitcode ("lsl", "r%d",reg);
                break;
        }
 }
@@ -3696,15 +3692,16 @@ genUnpackBits (operand * result, char *rname, int ptype)
        case IPOINTER:
        case PPOINTER:
        case FPOINTER:
-               emitcode ("ld", "r0,%s+", rname);
+               emitcode ("ld", "r24,%s+", rname);
                break;
 
        case CPOINTER:
-               emitcode ("lpm", "r0,%s+", rname);
+               emitcode ("lpm", "r24,%s+", rname);
                break;
 
        case GPOINTER:
                emitcode ("call","__gptrget_pi");
+               emitcode ("mov","r24,r0");
                break;
        }
 
@@ -3716,16 +3713,16 @@ genUnpackBits (operand * result, char *rname, int ptype)
        if ((shCnt = SPEC_BSTR (etype)) || (SPEC_BLEN (etype) <= 8)) {
 
                /* shift right acc */
-               R0Rsh (shCnt);
+               RRsh (shCnt,24);
 
-               emitcode ("andi", "r0,lo(0x%x)",
+               emitcode ("andi", "r24,lo(0x%x)",
                          ((unsigned char) -1) >> (8 - SPEC_BLEN (etype)));
-               aopPut (AOP (result), "r0", offset++);
+               aopPut (AOP (result), "r24", offset++);
                goto finish;
        }
 
        /* bit field did not fit in a byte  */
-       aopPut (AOP (result), "r0", offset++);
+       aopPut (AOP (result), "r24", offset++);
 
        while (1) {
 
@@ -3735,11 +3732,11 @@ genUnpackBits (operand * result, char *rname, int ptype)
                case IPOINTER:
                case PPOINTER:
                case FPOINTER:
-                       emitcode ("ld", "r0,%s+");
+                       emitcode ("ld", "r24,%s+");
                        break;
 
                case CPOINTER:
-                       emitcode ("lpm", "r0,%s+");
+                       emitcode ("lpm", "r24,%s+");
                        break;
 
                case GPOINTER:
@@ -3752,12 +3749,12 @@ genUnpackBits (operand * result, char *rname, int ptype)
                if (rlen < 8)
                        break;
 
-               aopPut (AOP (result), "r0", offset++);
+               aopPut (AOP (result), "r24", offset++);
 
-       }
+       }
 
        if (rlen) {
-               aopPut (AOP (result), "r0", offset++);
+               aopPut (AOP (result), "r24", offset++);
        }
 
       finish:
@@ -3785,9 +3782,9 @@ genDataPointerGet (operand * left, operand * result, iCode * ic)
        size = AOP_SIZE (result);
        while (size--) {
                if (offset)
-                       sprintf (buffer, "(%s + %d)", l + 1, offset);
+                       sprintf (buffer, "(%s + %d)", l, offset);
                else
-                       sprintf (buffer, "%s", l + 1);
+                       sprintf (buffer, "%s", l);
                emitcode ("lds", "%s,%s", aopGet (AOP (result), offset++),
                          buffer);
        }
@@ -3800,7 +3797,7 @@ genDataPointerGet (operand * left, operand * result, iCode * ic)
 /* genNearPointerGet - emitcode for near pointer fetch             */
 /*-----------------------------------------------------------------*/
 static void
-genMemPointerGet (operand * left, operand * result, iCode * ic)
+genMemPointerGet (operand * left, operand * result, iCode * ic, iCode *pi)
 {
        asmop *aop = NULL;
        regs *preg = NULL;
@@ -3831,7 +3828,9 @@ genMemPointerGet (operand * left, operand * result, iCode * ic)
                aop = newAsmop (0);
                preg = getFreePtr (ic, &aop, FALSE, 0);
                if (isRegPair (AOP (left) )) {
-                   emitcode ("movw", "%s,%s",aop->aopu.aop_ptr->name);
+                       emitcode ("movw", "%s,%s",
+                                 aop->aopu.aop_ptr->name,
+                                 aopGet(AOP(left),0));
                } else {
                        emitcode ("mov", "%s,%s", aop->aopu.aop_ptr->name, 
                                  aopGet (AOP (left), 0));
@@ -3854,7 +3853,6 @@ genMemPointerGet (operand * left, operand * result, iCode * ic)
                exit (0);
        }
 
-       freeAsmop (left, NULL, ic, TRUE);
        aopOp (result, ic, FALSE);
 
        /* if bitfield then unpack the bits */
@@ -3866,7 +3864,7 @@ genMemPointerGet (operand * left, operand * result, iCode * ic)
                int offset = 0;
 
                while (size--) {
-                       if (size) {
+                       if (size || pi) {
                                emitcode ("ld","%s,%s+",aopGet(AOP(result),offset), rname);
                        } else {
                                emitcode ("ld","%s,%s",aopGet(AOP(result),offset), rname);
@@ -3877,6 +3875,20 @@ genMemPointerGet (operand * left, operand * result, iCode * ic)
        /* now some housekeeping stuff */
        if (gotFreePtr) {
                /* we had to allocate for this iCode */
+               if (pi) {
+                       if (isRegPair (AOP (left) )) {
+                               emitcode ("movw", "%s,%s",
+                                         aopGet (AOP(left),0),
+                                         aop->aopu.aop_ptr->name);
+                       } else {
+                               emitcode ("mov", "%s,%s", 
+                                         aopGet (AOP (left), 0),
+                                         aop->aopu.aop_ptr->name);
+                               emitcode ("mov", "%s,%s", 
+                                         aopGet (AOP (left), 1),
+                                         aop->aop_ptr2->name);
+                       }
+               }
                freeAsmop (NULL, aop, ic, TRUE);
        } else {
 
@@ -3885,15 +3897,17 @@ genMemPointerGet (operand * left, operand * result, iCode * ic)
                   if size > 0 && this could be used again
                   we have to point it back to where it
                   belongs */
-               if (AOP_SIZE (result) > 1 &&
-                   !OP_SYMBOL (left)->remat &&
-                   (OP_SYMBOL (left)->liveTo > ic->seq || ic->depth)) {
+               if ((AOP_SIZE (result) > 1 &&
+                    !OP_SYMBOL (left)->remat &&
+                    (OP_SYMBOL (left)->liveTo > ic->seq || ic->depth)) && !pi) {
                        int size = AOP_SIZE (result) - 1;
                        emitcode ("sbiw", "%s,%d",frname,size);
                }
        }
 
        /* done */
+       if (pi) pi->generated = 1;
+       freeAsmop (left, NULL, ic, TRUE);
        freeAsmop (result, NULL, ic, TRUE);
 
 }
@@ -3902,11 +3916,12 @@ genMemPointerGet (operand * left, operand * result, iCode * ic)
 /* genCodePointerGet - gget value from code space                  */
 /*-----------------------------------------------------------------*/
 static void
-genCodePointerGet (operand * left, operand * result, iCode * ic)
+genCodePointerGet (operand * left, operand * result, iCode * ic, iCode *pi)
 {
        int size, offset;
        sym_link *retype = getSpec (operandType (result));      
        asmop *aop = NULL;
+       int gotFreePtr = 0;
 
        aopOp (left, ic, FALSE);
 
@@ -3923,7 +3938,9 @@ genCodePointerGet (operand * left, operand * result, iCode * ic)
                        emitcode ("mov", "r30,%s", aopGet (AOP (left), 0));
                        emitcode ("mov", "r31,%s", aopGet (AOP (left), 1));
                }
+               gotFreePtr = 1;
        } 
+
        aopOp (result, ic, FALSE);
 
        /* if bit then unpack */
@@ -3934,71 +3951,129 @@ genCodePointerGet (operand * left, operand * result, iCode * ic)
                offset = 0;
 
                while (size--) {
-                       emitcode ("clr", "a");
-                       emitcode ("movc", "a,@a+dptr");
-                       aopPut (AOP (result), "a", offset++);
-                       if (size)
-                               emitcode ("inc", "dptr");
+                       if (size || pi) {
+                               emitcode ("lpm","%s,Z+",aopGet(AOP(result),offset++));
+                       } else {
+                               emitcode ("lpm","%s,Z",aopGet(AOP(result),offset++));
+                       }
                }
        }
 
+       /* now some housekeeping stuff */
+       if (gotFreePtr) {
+               /* we had to allocate for this iCode */
+               if (pi) {
+                       if (isRegPair(AOP (left))) {
+                               emitcode ("movw","%s,r30",aopGet (AOP (left), 0));
+                       } else {                        
+                               emitcode ("mov", "%s,r30", aopGet (AOP (left), 0));
+                               emitcode ("mov", "%s,r31", aopGet (AOP (left), 1));
+                       }
+               }
+               freeAsmop (NULL, aop, ic, TRUE);
+       } else {
+
+               /* we did not allocate which means left
+                  already in a pointer register, then
+                  if size > 0 && this could be used again
+                  we have to point it back to where it
+                  belongs */
+               if ((AOP_SIZE (result) > 1 &&
+                    !OP_SYMBOL (left)->remat &&
+                    (OP_SYMBOL (left)->liveTo > ic->seq || ic->depth)) &&
+                   !pi) {
+                       int size = AOP_SIZE (result) - 1;
+                       emitcode ("sbiw", "r30,%d",size);
+               }
+       }
+
+       /* done */
+       if (pi) pi->generated=1;
        freeAsmop (left, NULL, ic, TRUE);
        freeAsmop (result, NULL, ic, TRUE);
+
 }
 
 /*-----------------------------------------------------------------*/
 /* genGenPointerGet - gget value from generic pointer space        */
 /*-----------------------------------------------------------------*/
 static void
-genGenPointerGet (operand * left, operand * result, iCode * ic)
+genGenPointerGet (operand * left, operand * result, iCode * ic, iCode *pi)
 {
        int size, offset;
+       int gotFreePtr = 0;
        sym_link *retype = getSpec (operandType (result));
+       asmop *aop = NULL;
 
        aopOp (left, ic, FALSE);
 
        /* if the operand is already in dptr
           then we do nothing else we move the value to dptr */
-       if (AOP_TYPE (left) != AOP_STR) {
-               /* if this is remateriazable */
-               if (AOP_TYPE (left) == AOP_IMMD) {
-                       emitcode ("mov", "dptr,%s", aopGet (AOP (left), 0));
-                       emitcode ("mov", "b,#%d", pointerCode (retype));
-               }
-               else {          /* we need to get it byte by byte */
-                       emitcode ("mov", "dpl,%s", aopGet (AOP (left), 0));
-                       emitcode ("mov", "dph,%s", aopGet (AOP (left), 1));
-                       if (options.model == MODEL_FLAT24) {
-                               emitcode ("mov", "dpx,%s",
-                                         aopGet (AOP (left), 2));
-                               emitcode ("mov", "b,%s",
-                                         aopGet (AOP (left), 3));
-                       }
-                       else {
-                               emitcode ("mov", "b,%s",
-                                         aopGet (AOP (left), 2));
-                       }
+       if (AOP_ISZ(AOP(left))) {
+               aop = AOP(left);
+       } else {
+               aop = newAsmop(0);
+               getFreePtr(ic,&aop,FALSE,TRUE);
+               if (isRegPair(AOP(left))) {
+                       emitcode ("movw", "r30,%s", aopGet (AOP (left), 0));
+               } else {
+                       emitcode ("mov", "r30,%s", aopGet (AOP (left), 0));
+                       emitcode ("mov", "r31,%s", aopGet (AOP (left), 1));
                }
+               emitcode ("mov", "r24,%s", aopGet (AOP (left), 2));
+               gotFreePtr=1;
        }
-       /* so dptr know contains the address */
-       freeAsmop (left, NULL, ic, TRUE);
+
+       /* so Z register now contains the address */
+
        aopOp (result, ic, FALSE);
 
        /* if bit then unpack */
        if (IS_BITVAR (retype))
-               genUnpackBits (result, "dptr", GPOINTER);
+               genUnpackBits (result, "Z", GPOINTER);
        else {
                size = AOP_SIZE (result);
                offset = 0;
 
                while (size--) {
-                       emitcode ("lcall", "__gptrget");
-                       aopPut (AOP (result), "a", offset++);
-                       if (size)
-                               emitcode ("inc", "dptr");
+                       if (size || pi) 
+                               emitcode ("call", "__gptrget_pi");
+                       else
+                               emitcode ("call", "__gptrget");
+                       aopPut (AOP (result), "r0", offset++);
                }
        }
 
+
+       /* now some housekeeping stuff */
+       if (gotFreePtr) {
+               /* we had to allocate for this iCode */
+               if (pi) {
+                       if (isRegPair(AOP (left))) {
+                               emitcode ("movw","%s,r30",aopGet (AOP (left), 0));
+                       } else {                        
+                               emitcode ("mov", "%s,r30", aopGet (AOP (left), 0));
+                               emitcode ("mov", "%s,r31", aopGet (AOP (left), 1));
+                       }
+               }
+               freeAsmop (NULL, aop, ic, TRUE);
+       } else {
+
+               /* we did not allocate which means left
+                  already in a pointer register, then
+                  if size > 0 && this could be used again
+                  we have to point it back to where it
+                  belongs */
+               if ((AOP_SIZE (result) > 1 &&
+                    !OP_SYMBOL (left)->remat &&
+                    (OP_SYMBOL (left)->liveTo > ic->seq || ic->depth)) &&
+                   !pi) {
+                       int size = AOP_SIZE (result) - 1;
+                       emitcode ("sbiw", "r30,%d",size);
+               }
+       }
+       if (pi) pi->generated=1;
+       freeAsmop (left, NULL, ic, TRUE);
        freeAsmop (result, NULL, ic, TRUE);
 }
 
@@ -4006,7 +4081,7 @@ genGenPointerGet (operand * left, operand * result, iCode * ic)
 /* genPointerGet - generate code for pointer get                   */
 /*-----------------------------------------------------------------*/
 static void
-genPointerGet (iCode * ic)
+genPointerGet (iCode * ic, iCode *pi)
 {
        operand *left, *result;
        sym_link *type, *etype;
@@ -4037,15 +4112,15 @@ genPointerGet (iCode * ic)
        case IPOINTER:
        case PPOINTER:
        case FPOINTER:
-               genMemPointerGet (left, result, ic);
+               genMemPointerGet (left, result, ic, pi);
                break;
 
        case CPOINTER:
-               genCodePointerGet (left, result, ic);
+               genCodePointerGet (left, result, ic, pi);
                break;
 
        case GPOINTER:
-               genGenPointerGet (left, result, ic);
+               genGenPointerGet (left, result, ic, pi);
                break;
        }
 
@@ -4055,7 +4130,9 @@ genPointerGet (iCode * ic)
 /* genPackBits - generates code for packed bit storage             */
 /*-----------------------------------------------------------------*/
 static void
-genPackBits (sym_link * etype, operand * right, char *rname, int p_type)
+genPackBits (sym_link * etype,
+            operand * right,
+            char *rname, int p_type)
 {
        int shCount = 0;
        int offset = 0;
@@ -4067,7 +4144,7 @@ genPackBits (sym_link * etype, operand * right, char *rname, int p_type)
        bstr = SPEC_BSTR (etype);
 
        l = aopGet (AOP (right), offset++);
-       MOVA (l);
+       MOVR24 (l);
 
        /* if the bit lenth is less than or    */
        /* it exactly fits a byte then         */
@@ -4075,50 +4152,47 @@ genPackBits (sym_link * etype, operand * right, char *rname, int p_type)
                shCount = SPEC_BSTR (etype);
 
                /* shift left acc */
-               //    AccLsh(shCount);
-
-               if (SPEC_BLEN (etype) < 8) {    /* if smaller than a byte */
+               RLsh (shCount,24);
 
+               if (SPEC_BLEN (etype) < 8) {                    /* if smaller than a byte */
 
                        switch (p_type) {
                        case POINTER:
-                               emitcode ("mov", "b,a");
-                               emitcode ("mov", "a,@%s", rname);
-                               break;
-
+                       case IPOINTER:
+                       case PPOINTER:
                        case FPOINTER:
-                               emitcode ("mov", "b,a");
-                               emitcode ("movx", "a,@dptr");
+                               emitcode ("ld", "r1,%s",rname);
                                break;
 
                        case GPOINTER:
-                               emitcode ("push", "b");
-                               emitcode ("push", "acc");
-                               emitcode ("lcall", "__gptrget");
-                               emitcode ("pop", "b");
+                               emitcode ("push", "r1");
+                               emitcode ("push", "r24");
+                               emitcode ("call", "__gptrget");
+                               emitcode ("pop", "r1");
+                               emitcode ("mov","r24,r0");
                                break;
                        }
 
-                       emitcode ("anl", "a,#0x%02x", (unsigned char)
+                       emitcode ("andi", "r24,#0x%02x", (unsigned char)
                                  ((unsigned char) (0xFF << (blen + bstr)) |
                                   (unsigned char) (0xFF >> (8 - bstr))));
-                       emitcode ("orl", "a,b");
+                       emitcode ("or", "r24,r1");
                        if (p_type == GPOINTER)
-                               emitcode ("pop", "b");
+                               emitcode ("pop", "r1");
                }
        }
 
        switch (p_type) {
        case POINTER:
-               emitcode ("mov", "@%s,a", rname);
-               break;
-
+       case IPOINTER:
+       case PPOINTER:
        case FPOINTER:
-               emitcode ("movx", "@dptr,a");
+               emitcode("st","%s+,r24");
                break;
 
        case GPOINTER:
-               emitcode ("lcall", "__gptrput");
+               emitcode("mov","r0,r24");
+               emitcode ("call", "__gptrput_pi");
                break;
        }
 
@@ -4126,7 +4200,6 @@ genPackBits (sym_link * etype, operand * right, char *rname, int p_type)
        if (SPEC_BLEN (etype) <= 8)
                return;
 
-       emitcode ("inc", "%s", rname);
        rLen = SPEC_BLEN (etype);
 
        /* now generate for lengths greater than one byte */
@@ -4135,75 +4208,64 @@ genPackBits (sym_link * etype, operand * right, char *rname, int p_type)
                l = aopGet (AOP (right), offset++);
 
                rLen -= 8;
-               if (rLen <= 0)
+               if (rLen < 8)
                        break;
 
                switch (p_type) {
                case POINTER:
-                       if (*l == '@') {
-                               MOVA (l);
-                               emitcode ("mov", "@%s,a", rname);
-                       }
-                       else
-                               emitcode ("mov", "@%s,%s", rname, l);
-                       break;
-
+               case IPOINTER:
+               case PPOINTER:
                case FPOINTER:
-                       MOVA (l);
-                       emitcode ("movx", "@dptr,a");
+                       emitcode ("st", "%s+,%s",rname,l);
                        break;
 
                case GPOINTER:
-                       MOVA (l);
-                       emitcode ("lcall", "__gptrput");
+                       MOVR0 (l);
+                       emitcode ("lcall", "__gptrput_pi");
                        break;
                }
-               emitcode ("inc", "%s", rname);
        }
 
-       MOVA (l);
+       MOVR24 (l);
 
        /* last last was not complete */
        if (rLen) {
                /* save the byte & read byte */
                switch (p_type) {
                case POINTER:
-                       emitcode ("mov", "b,a");
-                       emitcode ("mov", "a,@%s", rname);
-                       break;
-
+               case IPOINTER:
+               case PPOINTER:
                case FPOINTER:
-                       emitcode ("mov", "b,a");
-                       emitcode ("movx", "a,@dptr");
+                       emitcode ("st","%s+,r24",rname);
                        break;
-
                case GPOINTER:
-                       emitcode ("push", "b");
-                       emitcode ("push", "acc");
+                       emitcode ("push", "r1");
+                       emitcode ("push", "r24");
                        emitcode ("lcall", "__gptrget");
-                       emitcode ("pop", "b");
+                       emitcode ("mov","r24,r0");
+                       emitcode ("pop", "r1");
                        break;
                }
 
-               emitcode ("anl", "a,#0x%02x", ((unsigned char) -1 << -rLen));
-               emitcode ("orl", "a,b");
+               emitcode ("andi", "r24,0x%02x", (((unsigned char) -1 << rLen) & 0xff));
+               emitcode ("or", "r24,r1");
        }
 
        if (p_type == GPOINTER)
-               emitcode ("pop", "b");
+               emitcode ("pop", "r1");
 
        switch (p_type) {
 
        case POINTER:
-               emitcode ("mov", "@%s,a", rname);
-               break;
-
+       case IPOINTER:
+       case PPOINTER:
        case FPOINTER:
-               emitcode ("movx", "@dptr,a");
+               emitcode ("st", "%s,r24", rname);
                break;
 
        case GPOINTER:
-               emitcode ("lcall", "__gptrput");
+               emitcode ("mov","r0,r24");
+               emitcode ("call", "__gptrput");
                break;
        }
 }
@@ -4223,10 +4285,10 @@ genDataPointerSet (operand * right, operand * result, iCode * ic)
        size = AOP_SIZE (right);
        while (size--) {
                if (offset)
-                       sprintf (buffer, "(%s + %d)", l + 1, offset);
+                       sprintf (buffer, "(%s + %d)", l, offset);
                else
-                       sprintf (buffer, "%s", l + 1);
-               emitcode ("mov", "%s,%s", buffer,
+                       sprintf (buffer, "%s", l);
+               emitcode ("sts", "%s,%s", buffer,
                          aopGet (AOP (right), offset++));
        }
 
@@ -4235,21 +4297,21 @@ genDataPointerSet (operand * right, operand * result, iCode * ic)
 }
 
 /*-----------------------------------------------------------------*/
-/* genNearPointerSet - emitcode for near pointer put                */
+/* genNearPointerSet - emitcode for near pointer put               */
 /*-----------------------------------------------------------------*/
 static void
-genNearPointerSet (operand * right, operand * result, iCode * ic)
+genMemPointerSet (operand * right, operand * result, iCode * ic, iCode *pi)
 {
        asmop *aop = NULL;
-       regs *preg = NULL;
-       char *rname, *l;
+       char *frname = NULL, *rname, *l;
+       int gotFreePtr = 0;
        sym_link *retype;
        sym_link *ptype = operandType (result);
-
+       
        retype = getSpec (operandType (right));
-
+       
        aopOp (result, ic, FALSE);
-
+       
        /* if the result is rematerializable &
           in data space & not a bit variable */
        if (AOP_TYPE (result) == AOP_IMMD &&
@@ -4257,23 +4319,35 @@ genNearPointerSet (operand * right, operand * result, iCode * ic)
                genDataPointerSet (right, result, ic);
                return;
        }
-
-       /* if the value is already in a pointer register
-          then don't need anything more */
-       if (!AOP_INPREG (AOP (result))) {
+       if (!AOP_INPREG(AOP(result))) {
                /* otherwise get a free pointer register */
                aop = newAsmop (0);
-               preg = getFreePtr (ic, &aop, FALSE, 0);
-               emitcode ("mov", "%s,%s",
-                         preg->name, aopGet (AOP (result), 0));
-               rname = preg->name;
+               getFreePtr (ic, &aop, FALSE, 0);
+               if (isRegPair (AOP (result) )) {
+                       emitcode ("movw", "%s,%s",aop->aopu.aop_ptr->name,
+                                 aopGet(AOP (result), 0));
+               } else {
+                       emitcode ("mov", "%s,%s", aop->aopu.aop_ptr->name, 
+                                 aopGet (AOP (result), 0));
+                       emitcode ("mov", "%s,%s", aop->aop_ptr2->name,
+                                 aopGet (AOP (result), 1));
+               }
+               gotFreePtr = 1;         
+       } else {
+               aop = AOP(result);
+               frname = aopGet(aop,0);
        }
-       else
-               rname = aopGet (AOP (result), 0);
-
-       freeAsmop (result, NULL, ic, TRUE);
+       
        aopOp (right, ic, FALSE);
-
+       if (AOP_ISX(aop)) {
+               rname = "X";
+       } else if (AOP_ISZ(aop)) {
+               rname = "Z";
+       } else {
+               werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+                       "pointer not in correct register");
+               exit (0);
+       }
        /* if bitfield then unpack the bits */
        if (IS_BITVAR (retype))
                genPackBits (retype, right, rname, POINTER);
@@ -4284,234 +4358,138 @@ genNearPointerSet (operand * right, operand * result, iCode * ic)
 
                while (size--) {
                        l = aopGet (AOP (right), offset);
-                       if (*l == '@') {
-                               MOVA (l);
-                               emitcode ("mov", "@%s,a", rname);
-                       }
+                       if (size || pi)
+                               emitcode ("st", "%s+,%s", rname,l);
                        else
-                               emitcode ("mov", "@%s,%s", rname, l);
-                       if (size)
-                               emitcode ("inc", "%s", rname);
+                               emitcode ("st", "%s,%s", rname,l);                              
                        offset++;
                }
        }
-
+       
        /* now some housekeeping stuff */
-       if (aop) {
+       if (gotFreePtr) {
                /* we had to allocate for this iCode */
-               freeAsmop (NULL, aop, ic, TRUE);
-       }
-       else {
-               /* we did not allocate which means left
-                  already in a pointer register, then
-                  if size > 0 && this could be used again
-                  we have to point it back to where it
-                  belongs */
-               if (AOP_SIZE (right) > 1 &&
-                   !OP_SYMBOL (result)->remat &&
-                   (OP_SYMBOL (result)->liveTo > ic->seq || ic->depth)) {
-                       int size = AOP_SIZE (right) - 1;
-                       while (size--)
-                               emitcode ("dec", "%s", rname);
-               }
-       }
-
-       /* done */
-       freeAsmop (right, NULL, ic, TRUE);
-
-
-}
-
-/*-----------------------------------------------------------------*/
-/* genPagedPointerSet - emitcode for Paged pointer put             */
-/*-----------------------------------------------------------------*/
-static void
-genPagedPointerSet (operand * right, operand * result, iCode * ic)
-{
-       asmop *aop = NULL;
-       regs *preg = NULL;
-       char *rname, *l;
-       sym_link *retype;
-
-       retype = getSpec (operandType (right));
-
-       aopOp (result, ic, FALSE);
-
-       /* if the value is already in a pointer register
-          then don't need anything more */
-       if (!AOP_INPREG (AOP (result))) {
-               /* otherwise get a free pointer register */
-               aop = newAsmop (0);
-               preg = getFreePtr (ic, &aop, FALSE, 0);
-               emitcode ("mov", "%s,%s",
-                         preg->name, aopGet (AOP (result), 0));
-               rname = preg->name;
-       }
-       else
-               rname = aopGet (AOP (result), 0);
-
-       freeAsmop (result, NULL, ic, TRUE);
-       aopOp (right, ic, FALSE);
-
-       /* if bitfield then unpack the bits */
-       if (IS_BITVAR (retype))
-               genPackBits (retype, right, rname, PPOINTER);
-       else {
-               /* we have can just get the values */
-               int size = AOP_SIZE (right);
-               int offset = 0;
-
-               while (size--) {
-                       l = aopGet (AOP (right), offset);
-
-                       MOVA (l);
-                       emitcode ("movx", "@%s,a", rname);
-
-                       if (size)
-                               emitcode ("inc", "%s", rname);
-
-                       offset++;
+               if (pi) {
+                       if (isRegPair (AOP (result) )) {
+                               emitcode ("movw", "%s,%s",
+                                         aopGet(AOP(result),0),
+                                         aop->aopu.aop_ptr->name);
+                       } else {
+                               emitcode ("mov", "%s,%s", aop->aopu.aop_ptr->name, 
+                                         aopGet (AOP (result), 0));
+                               emitcode ("mov", "%s,%s", aop->aop_ptr2->name,
+                                         aopGet (AOP (result), 1));
+                       }
                }
-       }
-
-       /* now some housekeeping stuff */
-       if (aop) {
-               /* we had to allocate for this iCode */
                freeAsmop (NULL, aop, ic, TRUE);
-       }
-       else {
+       } else {
+
                /* we did not allocate which means left
                   already in a pointer register, then
                   if size > 0 && this could be used again
                   we have to point it back to where it
                   belongs */
-               if (AOP_SIZE (right) > 1 &&
-                   !OP_SYMBOL (result)->remat &&
-                   (OP_SYMBOL (result)->liveTo > ic->seq || ic->depth)) {
+               if ((AOP_SIZE (right) > 1 &&
+                    !OP_SYMBOL (result)->remat &&
+                    (OP_SYMBOL (right)->liveTo > ic->seq || ic->depth)) && !pi) {
                        int size = AOP_SIZE (right) - 1;
-                       while (size--)
-                               emitcode ("dec", "%s", rname);
+                       emitcode ("sbiw", "%s,%d",frname,size);
                }
        }
 
        /* done */
+       if (pi) pi->generated = 1;
+       freeAsmop (result, NULL, ic, TRUE);
        freeAsmop (right, NULL, ic, TRUE);
-
-
 }
 
 /*-----------------------------------------------------------------*/
-/* genFarPointerSet - set value from far space                     */
+/* genGenPointerSet - set value from generic pointer space         */
 /*-----------------------------------------------------------------*/
 static void
-genFarPointerSet (operand * right, operand * result, iCode * ic)
+genGenPointerSet (operand * right, operand * result, iCode * ic, iCode *pi)
 {
        int size, offset;
+       int gotFreePtr = 0;
        sym_link *retype = getSpec (operandType (right));
-
+       asmop *aop = NULL;       
+       
        aopOp (result, ic, FALSE);
-
+       
        /* if the operand is already in dptr
           then we do nothing else we move the value to dptr */
-       if (AOP_TYPE (result) != AOP_STR) {
-               /* if this is remateriazable */
-               if (AOP_TYPE (result) == AOP_IMMD)
-                       emitcode ("mov", "dptr,%s", aopGet (AOP (result), 0));
-               else {          /* we need to get it byte by byte */
-                       emitcode ("mov", "dpl,%s", aopGet (AOP (result), 0));
-                       emitcode ("mov", "dph,%s", aopGet (AOP (result), 1));
-                       if (options.model == MODEL_FLAT24) {
-                               emitcode ("mov", "dpx,%s",
-                                         aopGet (AOP (result), 2));
-                       }
+       if (AOP_ISZ(AOP(result))) {
+               aop = AOP(right);
+       } else {
+               aop = newAsmop(0);
+               getFreePtr(ic,&aop,FALSE,TRUE);
+               if (isRegPair(AOP(result))) {
+                       emitcode ("movw", "r30,%s", aopGet (AOP (result), 0));
+               } else {
+                       emitcode ("mov", "r30,%s", aopGet (AOP (result), 0));
+                       emitcode ("mov", "r31,%s", aopGet (AOP (result), 1));
                }
+               emitcode ("mov", "r24,%s",  aopGet (AOP (result), 2));
+               gotFreePtr=1;
        }
-       /* so dptr know contains the address */
-       freeAsmop (result, NULL, ic, TRUE);
+       
+       /* so Z register now contains the address */
        aopOp (right, ic, FALSE);
-
+       
        /* if bit then unpack */
        if (IS_BITVAR (retype))
-               genPackBits (retype, right, "dptr", FPOINTER);
+               genUnpackBits (result, "Z", GPOINTER);
        else {
                size = AOP_SIZE (right);
                offset = 0;
-
+               
                while (size--) {
-                       char *l = aopGet (AOP (right), offset++);
-                       MOVA (l);
-                       emitcode ("movx", "@dptr,a");
-                       if (size)
-                               emitcode ("inc", "dptr");
+                       char *l = aopGet(AOP (right), offset++);
+                       MOVR0(l);
+                       
+                       if (size || pi) 
+                               emitcode ("call", "__gptrput_pi");
+                       else
+                               emitcode ("call", "__gptrput");
                }
        }
 
-       freeAsmop (right, NULL, ic, TRUE);
-}
-
-/*-----------------------------------------------------------------*/
-/* genGenPointerSet - set value from generic pointer space         */
-/*-----------------------------------------------------------------*/
-static void
-genGenPointerSet (operand * right, operand * result, iCode * ic)
-{
-       int size, offset;
-       sym_link *retype = getSpec (operandType (right));
-
-       aopOp (result, ic, FALSE);
-
-       /* if the operand is already in dptr
-          then we do nothing else we move the value to dptr */
-       if (AOP_TYPE (result) != AOP_STR) {
-               /* if this is remateriazable */
-               if (AOP_TYPE (result) == AOP_IMMD) {
-                       emitcode ("mov", "dptr,%s", aopGet (AOP (result), 0));
-                       emitcode ("mov", "b,%s + 1",
-                                 aopGet (AOP (result), 0));
-               }
-               else {          /* we need to get it byte by byte */
-                       emitcode ("mov", "dpl,%s", aopGet (AOP (result), 0));
-                       emitcode ("mov", "dph,%s", aopGet (AOP (result), 1));
-                       if (options.model == MODEL_FLAT24) {
-                               emitcode ("mov", "dpx,%s",
-                                         aopGet (AOP (result), 2));
-                               emitcode ("mov", "b,%s",
-                                         aopGet (AOP (result), 3));
-                       }
-                       else {
-                               emitcode ("mov", "b,%s",
-                                         aopGet (AOP (result), 2));
+       /* now some housekeeping stuff */
+       if (gotFreePtr) {
+               /* we had to allocate for this iCode */
+               if (pi) {
+                       if (isRegPair(AOP(result))) {
+                               emitcode ("movw", "%s,r30", aopGet (AOP (result), 0));
+                       } else {
+                               emitcode ("mov", "%s,r30", aopGet (AOP (result), 0));
+                               emitcode ("mov", "%s,r31", aopGet (AOP (result), 1));
                        }
                }
-       }
-       /* so dptr know contains the address */
-       freeAsmop (result, NULL, ic, TRUE);
-       aopOp (right, ic, FALSE);
-
-       /* if bit then unpack */
-       if (IS_BITVAR (retype))
-               genPackBits (retype, right, "dptr", GPOINTER);
-       else {
-               size = AOP_SIZE (right);
-               offset = 0;
+               freeAsmop (NULL, aop, ic, TRUE);
+       } else {
 
-               while (size--) {
-                       char *l = aopGet (AOP (right), offset++);
-                       MOVA (l);
-                       emitcode ("lcall", "__gptrput");
-                       if (size)
-                               emitcode ("inc", "dptr");
+               /* we did not allocate which means left
+                  already in a pointer register, then
+                  if size > 0 && this could be used again
+                  we have to point it back to where it
+                  belongs */
+               if ((AOP_SIZE (right) > 1 &&
+                    !OP_SYMBOL (result)->remat &&
+                    (OP_SYMBOL (result)->liveTo > ic->seq || ic->depth)) && !pi) {
+                       int size = AOP_SIZE (right) - 1;
+                       emitcode ("sbiw", "r30,%d",size);
                }
        }
-
+       if (pi) pi->generated = 1;
        freeAsmop (right, NULL, ic, TRUE);
+       freeAsmop (result, NULL, ic, TRUE);
 }
 
 /*-----------------------------------------------------------------*/
 /* genPointerSet - stores the value into a pointer location        */
 /*-----------------------------------------------------------------*/
 static void
-genPointerSet (iCode * ic)
+genPointerSet (iCode * ic, iCode *pi)
 {
        operand *right, *result;
        sym_link *type, *etype;
@@ -4532,20 +4510,6 @@ genPointerSet (iCode * ic)
                /* we have to go by the storage class */
                p_type = PTR_TYPE (SPEC_OCLS (etype));
 
-               /*  if (SPEC_OCLS(etype)->codesp ) { */
-               /*      p_type = CPOINTER ;  */
-               /*  } */
-               /*  else */
-               /*      if (SPEC_OCLS(etype)->fmap && !SPEC_OCLS(etype)->paged) */
-               /*    p_type = FPOINTER ; */
-               /*      else */
-               /*    if (SPEC_OCLS(etype)->fmap && SPEC_OCLS(etype)->paged) */
-               /*        p_type = PPOINTER ; */
-               /*    else */
-               /*        if (SPEC_OCLS(etype) == idata ) */
-               /*      p_type = IPOINTER ; */
-               /*        else */
-               /*      p_type = POINTER ; */
        }
 
        /* now that we have the pointer type we assign
@@ -4554,19 +4518,13 @@ genPointerSet (iCode * ic)
 
        case POINTER:
        case IPOINTER:
-               genNearPointerSet (right, result, ic);
-               break;
-
        case PPOINTER:
-               genPagedPointerSet (right, result, ic);
-               break;
-
        case FPOINTER:
-               genFarPointerSet (right, result, ic);
+               genMemPointerSet (right, result, ic, pi);
                break;
 
        case GPOINTER:
-               genGenPointerSet (right, result, ic);
+               genGenPointerSet (right, result, ic, pi);
                break;
        }
 
@@ -4579,35 +4537,39 @@ static void
 genIfx (iCode * ic, iCode * popIc)
 {
        operand *cond = IC_COND (ic);
-       int isbit = 0;
+       char *cname ;
+       symbol *lbl;
 
        aopOp (cond, ic, FALSE);
 
-       /* get the value into acc */
-       if (AOP_TYPE (cond) != AOP_CRY)
-               toBoolean (cond, "", 0);
-       else
-               isbit = 1;
+       /* get the value into acc */    
+       if (AOP_SIZE(cond) == 1 && AOP_ISHIGHREG(AOP(cond),0)) {
+               cname = aopGet(AOP(cond),0);
+       } else {
+               toBoolean (cond, "r24", 1);
+               cname = "r24";
+       }
        /* the result is now in the accumulator */
        freeAsmop (cond, NULL, ic, TRUE);
 
        /* if there was something to be popped then do it */
        if (popIc)
                genIpop (popIc);
-
-       /* if the condition is  a bit variable */
-       /*     if (isbit && IS_ITEMP(cond) && SPIL_LOC(cond)) { */
-       /*  //  genIfxJump(ic,SPIL_LOC(cond)->rname); */
-       /*     } */
-       /*     else */
-       /*  if (isbit && !IS_ITEMP(cond)) */
-       /*    //      genIfxJump(ic,OP_SYMBOL(cond)->rname); */
-       /*  else */
-       /*    // genIfxJump(ic,"a"); */
-
+       
+       emitcode("cpi","%s,0",cname);
+       lbl = newiTempLabel(NULL);
+       if (IC_TRUE(ic)) {
+               emitcode ("brne","L%05d",lbl->key);
+               emitcode ("jmp","L%05d",IC_TRUE(ic)->key);
+               emitcode ("","L%05d:",lbl->key);
+       } else {
+               emitcode ("breq","L%05d",lbl->key);
+               emitcode ("jmp","L%05d",IC_FALSE(ic)->key);
+               emitcode ("","L%05d:",lbl->key);
+       }
        ic->generated = 1;
 }
-
+/* here */
 /*-----------------------------------------------------------------*/
 /* genAddrOf - generates code for address of                       */
 /*-----------------------------------------------------------------*/
@@ -4623,8 +4585,7 @@ genAddrOf (iCode * ic)
           need to get the stack offset of this
           variable */
        if (sym->onStack) {
-               /* if it has an offset then we need to compute
-                  it */
+               /* if it has an offset then we need to compute it */
                if (sym->stack) {
                        emitcode ("mov", "a,_bp");
                        emitcode ("add", "a,#0x%02x",
@@ -4636,24 +4597,10 @@ genAddrOf (iCode * ic)
                        aopPut (AOP (IC_RESULT (ic)), "_bp", 0);
                }
                /* fill the result with zero */
-               size = AOP_SIZE (IC_RESULT (ic)) - 1;
-
-
-               if (options.stack10bit && size < (FPTRSIZE - 1)) {
-                       fprintf (stderr,
-                                "*** warning: pointer to stack var truncated.\n");
-               }
-
-               offset = 1;
+               size = AOP_SIZE (IC_RESULT (ic)) - 2;
+               offset = 2;
                while (size--) {
-                       /* Yuck! */
-                       if (options.stack10bit && offset == 2) {
-                               aopPut (AOP (IC_RESULT (ic)), "#0x40",
-                                       offset++);
-                       }
-                       else {
-                               aopPut (AOP (IC_RESULT (ic)), zero, offset++);
-                       }
+                       aopPut (AOP (IC_RESULT (ic)), zero, offset++);
                }
 
                goto release;
@@ -4666,9 +4613,9 @@ genAddrOf (iCode * ic)
        while (size--) {
                char s[SDCC_NAME_MAX];
                if (offset)
-                       sprintf (s, "#(%s >> %d)", sym->rname, offset * 8);
+                       sprintf (s, "(%s >> %d)", sym->rname, offset * 8);
                else
-                       sprintf (s, "#%s", sym->rname);
+                       sprintf (s, "%s", sym->rname);
                aopPut (AOP (IC_RESULT (ic)), s, offset++);
        }
 
@@ -4926,10 +4873,10 @@ genCast (iCode * ic)
                                l = one;
                                break;
                        case CPOINTER:
-                               l = "#0x02";
+                               l = "0x02";
                                break;
                        case PPOINTER:
-                               l = "#0x03";
+                               l = "0x03";
                                break;
 
                        default:
@@ -5260,12 +5207,12 @@ genAVRCode (iCode * lic)
                        break;
 
                case GET_VALUE_AT_ADDRESS:
-                       genPointerGet (ic);
+                       genPointerGet (ic, hasInc(IC_LEFT(ic),ic));
                        break;
 
                case '=':
                        if (POINTER_SET (ic))
-                               genPointerSet (ic);
+                               genPointerSet (ic, hasInc(IC_RESULT(ic),ic));
                        else
                                genAssign (ic);
                        break;
@@ -5296,8 +5243,6 @@ genAVRCode (iCode * lic)
 
                default:
                        ic = ic;
-                       /*      piCode(ic,stdout); */
-
                }
        }