]> git.sur5r.net Git - cc65/blobdiff - src/cc65/opcodes.c
Fixed wrong code generation for
[cc65] / src / cc65 / opcodes.c
index 7bd8b50322eb887eb4dfc1ae9e858b3107c21e68..2c838a695f6c5038092dad89ccb85d6fc17dfe44 100644 (file)
@@ -6,9 +6,9 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2001-2002 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
+/* (C) 2001-2004 Ullrich von Bassewitz                                       */
+/*               Römerstraße 52                                              */
+/*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
@@ -55,7 +55,7 @@
 
 
 /* Opcode description table */
-const OPCDesc OPCTable[OPCODE_COUNT] = {
+const OPCDesc OPCTable[OP65_COUNT] = {
 
     /* 65XX opcodes */
     {   OP65_ADC,                                      /* opcode */
@@ -63,21 +63,21 @@ const OPCDesc OPCTable[OPCODE_COUNT] = {
                0,                                      /* size */
                REG_A,                                  /* use */
                REG_A,                                  /* chg */
-       OF_SETF                                 /* flags */
+       OF_SETF                                 /* flags */
     },
     {   OP65_AND,                                      /* opcode */
                "and",                                  /* mnemonic */
                0,                                      /* size */
                REG_A,                                  /* use */
                REG_A,                                  /* chg */
-       OF_SETF                                 /* flags */
+       OF_SETF                                 /* flags */
     },
     {   OP65_ASL,                                      /* opcode */
                "asl",                                  /* mnemonic */
                0,                                      /* size */
                REG_NONE,                               /* use */
                REG_NONE,                               /* chg */
-       OF_SETF                                 /* flags */
+               OF_SETF | OF_NOIMP                      /* flags */
     },
     {   OP65_BCC,                                      /* opcode */
                "bcc",                                  /* mnemonic */
@@ -154,7 +154,7 @@ const OPCDesc OPCTable[OPCODE_COUNT] = {
                2,                                      /* size */
                REG_NONE,                               /* use */
                REG_NONE,                               /* chg */
-       OF_CBRA                                 /* flags */
+       OF_CBRA                                 /* flags */
     },
     {   OP65_CLC,                                      /* opcode */
                "clc",                                  /* mnemonic */
@@ -217,7 +217,7 @@ const OPCDesc OPCTable[OPCODE_COUNT] = {
                0,                                      /* size */
                REG_NONE,                               /* use */
                REG_NONE,                               /* chg */
-               OF_SETF                                 /* flags */
+               OF_SETF | OF_NOIMP                      /* flags */
     },
     {   OP65_DEX,                                      /* opcode */
                "dex",                                  /* mnemonic */
@@ -238,7 +238,7 @@ const OPCDesc OPCTable[OPCODE_COUNT] = {
                0,                                      /* size */
                REG_A,                                  /* use */
                REG_A,                                  /* chg */
-               OF_SETF                                 /* flags */
+               OF_SETF                                 /* flags */
     },
     {   OP65_INA,                                      /* opcode */
                "ina",                                  /* mnemonic */
@@ -252,7 +252,7 @@ const OPCDesc OPCTable[OPCODE_COUNT] = {
                0,                                      /* size */
                REG_NONE,                               /* use */
                REG_NONE,                               /* chg */
-       OF_SETF                                 /* flags */
+       OF_SETF | OF_NOIMP                      /* flags */
     },
     {   OP65_INX,                                      /* opcode */
                "inx",                                  /* mnemonic */
@@ -329,7 +329,7 @@ const OPCDesc OPCTable[OPCODE_COUNT] = {
                5,                                      /* size */
                REG_NONE,                               /* use */
                REG_NONE,                               /* chg */
-       OF_CBRA | OF_LBRA                       /* flags */
+       OF_CBRA | OF_LBRA                       /* flags */
     },
     {   OP65_JVS,                                      /* opcode */
                "jvs",                                  /* mnemonic */
@@ -364,7 +364,7 @@ const OPCDesc OPCTable[OPCODE_COUNT] = {
                0,                                      /* size */
                REG_NONE,                               /* use */
                REG_NONE,                               /* chg */
-       OF_SETF                                 /* flags */
+       OF_SETF | OF_NOIMP                      /* flags */
     },
     {   OP65_NOP,                                      /* opcode */
                "nop",                                  /* mnemonic */
@@ -420,7 +420,7 @@ const OPCDesc OPCTable[OPCODE_COUNT] = {
                1,                                      /* size */
                REG_NONE,                               /* use */
                REG_NONE,                               /* chg */
-       OF_NONE                                 /* flags */
+       OF_NONE                                 /* flags */
     },
     {   OP65_PLX,                                      /* opcode */
                "plx",                                  /* mnemonic */
@@ -441,84 +441,87 @@ const OPCDesc OPCTable[OPCODE_COUNT] = {
                0,                                      /* size */
                REG_NONE,                               /* use */
                REG_NONE,                               /* chg */
-       OF_SETF                                 /* flags */
+       OF_SETF | OF_NOIMP                      /* flags */
     },
     {   OP65_ROR,                                      /* opcode */
                "ror",                                  /* mnemonic */
                0,                                      /* size */
                REG_NONE,                               /* use */
                REG_NONE,                               /* chg */
-       OF_SETF                                 /* flags */
+       OF_SETF | OF_NOIMP                      /* flags */
     },
+    /* Mark RTI as "uses all registers but doesn't change them", so the
+     * optimizer won't remove preceeding loads.
+     */
     {   OP65_RTI,                                      /* opcode */
                "rti",                                  /* mnemonic */
                1,                                      /* size */
-               REG_NONE,                               /* use */
+               REG_AXY,                                /* use */
                REG_NONE,                               /* chg */
-       OF_RET                                  /* flags */
+       OF_RET                                  /* flags */
     },
     {   OP65_RTS,                                      /* opcode */
                "rts",                                  /* mnemonic */
                1,                                      /* size */
                REG_NONE,                               /* use */
                REG_NONE,                               /* chg */
-       OF_RET                                  /* flags */
+       OF_RET                                  /* flags */
     },
     {   OP65_SBC,                                      /* opcode */
                "sbc",                                  /* mnemonic */
                0,                                      /* size */
                REG_A,                                  /* use */
                REG_A,                                  /* chg */
-       OF_SETF                                 /* flags */
+       OF_SETF                                 /* flags */
     },
     {   OP65_SEC,                                      /* opcode */
                "sec",                                  /* mnemonic */
                1,                                      /* size */
                REG_NONE,                               /* use */
                REG_NONE,                               /* chg */
-       OF_NONE                                 /* flags */
+       OF_NONE                                 /* flags */
     },
     {   OP65_SED,                                      /* opcode */
                "sed",                                  /* mnemonic */
                1,                                      /* size */
                REG_NONE,                               /* use */
                REG_NONE,                               /* chg */
-       OF_NONE                                 /* flags */
+       OF_NONE                                 /* flags */
     },
     {   OP65_SEI,                                      /* opcode */
                "sei",                                  /* mnemonic */
                1,                                      /* size */
                REG_NONE,                               /* use */
                REG_NONE,                               /* chg */
-       OF_NONE                                 /* flags */
+       OF_NONE                                 /* flags */
     },
     {   OP65_STA,                                      /* opcode */
                "sta",                                  /* mnemonic */
                0,                                      /* size */
                REG_A,                                  /* use */
                REG_NONE,                               /* chg */
-       OF_STORE                                /* flags */
+       OF_STORE                                /* flags */
     },
     {   OP65_STX,                                      /* opcode */
                "stx",                                  /* mnemonic */
                0,                                      /* size */
                REG_X,                                  /* use */
                REG_NONE,                               /* chg */
-       OF_STORE                                /* flags */
+       OF_STORE                                /* flags */
     },
     {   OP65_STY,                                      /* opcode */
                "sty",                                  /* mnemonic */
                0,                                      /* size */
                REG_Y,                                  /* use */
                REG_NONE,                               /* chg */
-       OF_STORE                                /* flags */
+       OF_STORE                                /* flags */
     },
     {   OP65_STZ,                                      /* opcode */
                "stz",                                  /* mnemonic */
                0,                                      /* size */
                REG_NONE,                               /* use */
                REG_NONE,                               /* chg */
-       OF_STORE                                /* flags */
+       OF_STORE                                /* flags */
     },
     {   OP65_TAX,                                      /* opcode */
                "tax",                                  /* mnemonic */
@@ -546,7 +549,7 @@ const OPCDesc OPCTable[OPCODE_COUNT] = {
                0,                                      /* size */
                REG_A,                                  /* use */
                REG_NONE,                               /* chg */
-       OF_SETF                                 /* flags */
+       OF_SETF                                 /* flags */
     },
     {   OP65_TSX,                                      /* opcode */
                "tsx",                                  /* mnemonic */
@@ -567,7 +570,7 @@ const OPCDesc OPCTable[OPCODE_COUNT] = {
                1,                                      /* size */
                REG_X,                                  /* use */
                REG_NONE,                               /* chg */
-       OF_XFR                                  /* flags */
+       OF_XFR                                  /* flags */
     },
     {   OP65_TYA,                                      /* opcode */
                "tya",                                  /* mnemonic */
@@ -617,7 +620,7 @@ const OPCDesc* FindOP65 (const char* M)
     Mnemo[I] = '\0';
 
     /* Search for the mnemonic in the table and return the result */
-    return bsearch (Mnemo, OPCTable+OP65_FIRST, OP65_COUNT,
+    return bsearch (Mnemo, OPCTable, OP65_COUNT,
                    sizeof (OPCTable[0]), FindCmp );
 }
 
@@ -723,7 +726,7 @@ opc_t MakeShortBranch (opc_t OPC)
                case OP65_BVS:
                case OP65_JVS:  return OP65_BVS;
                case OP65_BRA:
-       case OP65_JMP:  return (CPU == CPU_65C02)? OP65_BRA : OP65_JMP;
+       case OP65_JMP:  return (CPUIsets[CPU] & CPU_ISET_65SC02)? OP65_BRA : OP65_JMP;
                default:
            Internal ("MakeShortBranch: Invalid opcode: %d", OPC);
            return 0;