/* Store the value into the zeropage instead of pushing it */
     ReplacePushByStore (D);
 
-    /* Inline the shift */
-    D->IP = D->OpIndex+1;
-
-    /* tay */
-    X = NewCodeEntry (OP65_TAY, AM65_IMP, 0, 0, D->OpEntry->LI);
-    InsertEntry (D, X, D->IP++);
-
     /* If the lhs is direct (but not stack relative), we can just reload the
      * data later.
      */
         CodeEntry* LoadX = D->Lhs.X.LoadEntry;
         CodeEntry* LoadA = D->Lhs.A.LoadEntry;
 
+        /* Inline the shift */
+        D->IP = D->OpIndex+1;
+
+        /* tay */
+        X = NewCodeEntry (OP65_TAY, AM65_IMP, 0, 0, D->OpEntry->LI);
+        InsertEntry (D, X, D->IP++);
+
         /* lda */
         X = NewCodeEntry (OP65_LDA, LoadA->AM, LoadA->Arg, 0, D->OpEntry->LI);
         InsertEntry (D, X, D->IP++);
         AddStoreX (D);
         AddStoreA (D);
 
+        /* Be sure to setup IP after adding the stores, otherwise it will get
+         * messed up.   
+         */
+        D->IP = D->OpIndex+1;
+
+        /* tay */
+        X = NewCodeEntry (OP65_TAY, AM65_IMP, 0, 0, D->OpEntry->LI);
+        InsertEntry (D, X, D->IP++);
+
         /* lda zp */
         X = NewCodeEntry (OP65_LDA, AM65_ZP, D->ZPLo, 0, D->OpEntry->LI);
         InsertEntry (D, X, D->IP++);
     X = NewCodeEntry (OP65_JSR, AM65_ABS, Name, 0, D->OpEntry->LI);
     InsertEntry (D, X, D->IP++);
 
-    /* Remove the push and the call to the tossubax function */
+    /* Remove the push and the call to the shift function */
     RemoveRemainders (D);
 
     /* We changed the sequence */