mirror of
https://github.com/cc65/cc65.git
synced 2025-01-11 11:30:13 +00:00
Use MakeHexArg, replace STX and STY by STZ if possible
git-svn-id: svn://svn.cc65.org/cc65/trunk@1191 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
1118dd1237
commit
0655cac6a6
@ -214,7 +214,7 @@ const char* MakeHexArg (unsigned Num)
|
|||||||
* safe).
|
* safe).
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
static char Buf[4];
|
static char Buf[16];
|
||||||
xsprintf (Buf, sizeof (Buf), "$%02X", (char) Num);
|
xsprintf (Buf, sizeof (Buf), "$%02X", (char) Num);
|
||||||
return Buf;
|
return Buf;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 2001 Ullrich von Bassewitz */
|
/* (C) 2001-2002 Ullrich von Bassewitz */
|
||||||
/* Wacholderweg 14 */
|
/* Wacholderweg 14 */
|
||||||
/* D-70597 Stuttgart */
|
/* D-70597 Stuttgart */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@ -33,9 +33,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* common */
|
|
||||||
#include "xsprintf.h"
|
|
||||||
|
|
||||||
/* cc65 */
|
/* cc65 */
|
||||||
#include "codeent.h"
|
#include "codeent.h"
|
||||||
#include "codeinfo.h"
|
#include "codeinfo.h"
|
||||||
@ -191,12 +188,12 @@ unsigned OptAdd2 (CodeSeg* S)
|
|||||||
(GetRegInfo (S, I+4, REG_AX) & REG_AX) == 0) {
|
(GetRegInfo (S, I+4, REG_AX) & REG_AX) == 0) {
|
||||||
|
|
||||||
/* Insert new code behind the addeqysp */
|
/* Insert new code behind the addeqysp */
|
||||||
char Buf [20];
|
const char* Arg;
|
||||||
CodeEntry* X;
|
CodeEntry* X;
|
||||||
|
|
||||||
/* ldy #xx-1 */
|
/* ldy #xx-1 */
|
||||||
xsprintf (Buf, sizeof (Buf), "$%02X", (int)(L[0]->Num-1));
|
Arg = MakeHexArg (L[0]->Num-1);
|
||||||
X = NewCodeEntry (OP65_LDY, AM65_IMM, Buf, 0, L[0]->LI);
|
X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, L[0]->LI);
|
||||||
CS_InsertEntry (S, X, I+4);
|
CS_InsertEntry (S, X, I+4);
|
||||||
|
|
||||||
/* lda (sp),y */
|
/* lda (sp),y */
|
||||||
@ -228,8 +225,8 @@ unsigned OptAdd2 (CodeSeg* S)
|
|||||||
CS_InsertEntry (S, X, I+11);
|
CS_InsertEntry (S, X, I+11);
|
||||||
|
|
||||||
/* ldy #yy+1 */
|
/* ldy #yy+1 */
|
||||||
xsprintf (Buf, sizeof (Buf), "$%02X", (int)(L[2]->Num+1));
|
Arg = MakeHexArg (L[2]->Num+1);
|
||||||
X = NewCodeEntry (OP65_LDY, AM65_IMM, Buf, 0, L[2]->LI);
|
X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, L[2]->LI);
|
||||||
CS_InsertEntry (S, X, I+12);
|
CS_InsertEntry (S, X, I+12);
|
||||||
|
|
||||||
/* adc (sp),y */
|
/* adc (sp),y */
|
||||||
|
@ -201,11 +201,14 @@ unsigned Opt65C02Stores (CodeSeg* S)
|
|||||||
/* Get next entry */
|
/* Get next entry */
|
||||||
CodeEntry* E = CS_GetEntry (S, I);
|
CodeEntry* E = CS_GetEntry (S, I);
|
||||||
|
|
||||||
/* Check for the sequence */
|
/* Check for a store with a register value of zero and an addressing
|
||||||
if (E->OPC == OP65_STA &&
|
* mode available with STZ.
|
||||||
|
*/
|
||||||
|
if (((E->OPC == OP65_STA && E->RI->In.RegA == 0) ||
|
||||||
|
(E->OPC == OP65_STX && E->RI->In.RegX == 0) ||
|
||||||
|
(E->OPC == OP65_STY && E->RI->In.RegY == 0)) &&
|
||||||
(E->AM == AM65_ZP || E->AM == AM65_ABS ||
|
(E->AM == AM65_ZP || E->AM == AM65_ABS ||
|
||||||
E->AM == AM65_ZPX || E->AM == AM65_ABSX ) &&
|
E->AM == AM65_ZPX || E->AM == AM65_ABSX)) {
|
||||||
E->RI->In.RegA == 0) {
|
|
||||||
|
|
||||||
/* Replace by STZ */
|
/* Replace by STZ */
|
||||||
CodeEntry* X = NewCodeEntry (OP65_STZ, E->AM, E->Arg, 0, E->LI);
|
CodeEntry* X = NewCodeEntry (OP65_STZ, E->AM, E->Arg, 0, E->LI);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 2001 Ullrich von Bassewitz */
|
/* (C) 2001-2002 Ullrich von Bassewitz */
|
||||||
/* Wacholderweg 14 */
|
/* Wacholderweg 14 */
|
||||||
/* D-70597 Stuttgart */
|
/* D-70597 Stuttgart */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@ -33,10 +33,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* common */
|
/* cc65 */
|
||||||
#include "xsprintf.h"
|
|
||||||
|
|
||||||
/* cc65 */
|
|
||||||
#include "codeent.h"
|
#include "codeent.h"
|
||||||
#include "codeinfo.h"
|
#include "codeinfo.h"
|
||||||
#include "coptpush.h"
|
#include "coptpush.h"
|
||||||
@ -86,12 +83,12 @@ unsigned OptPush1 (CodeSeg* S)
|
|||||||
(GetRegInfo (S, I+3, REG_AX) & REG_AX) == 0) {
|
(GetRegInfo (S, I+3, REG_AX) & REG_AX) == 0) {
|
||||||
|
|
||||||
/* Insert new code behind the pushax */
|
/* Insert new code behind the pushax */
|
||||||
char Buf [20];
|
const char* Arg;
|
||||||
CodeEntry* X;
|
CodeEntry* X;
|
||||||
|
|
||||||
/* ldy #xx+1 */
|
/* ldy #xx+1 */
|
||||||
xsprintf (Buf, sizeof (Buf), "$%02X", (int)(L[0]->Num+2));
|
Arg = MakeHexArg (L[0]->Num+2);
|
||||||
X = NewCodeEntry (OP65_LDY, AM65_IMM, Buf, 0, L[0]->LI);
|
X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, L[0]->LI);
|
||||||
CS_InsertEntry (S, X, I+3);
|
CS_InsertEntry (S, X, I+3);
|
||||||
|
|
||||||
/* jsr pushwysp */
|
/* jsr pushwysp */
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 2001 Ullrich von Bassewitz */
|
/* (C) 2001-2002 Ullrich von Bassewitz */
|
||||||
/* Wacholderweg 14 */
|
/* Wacholderweg 14 */
|
||||||
/* D-70597 Stuttgart */
|
/* D-70597 Stuttgart */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@ -35,9 +35,6 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/* common */
|
|
||||||
#include "xsprintf.h"
|
|
||||||
|
|
||||||
/* cc65 */
|
/* cc65 */
|
||||||
#include "codeent.h"
|
#include "codeent.h"
|
||||||
#include "codeinfo.h"
|
#include "codeinfo.h"
|
||||||
@ -89,10 +86,8 @@ static unsigned AdjustStackOffset (CodeSeg* S, unsigned Start, unsigned Stop,
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* Insert a new load instruction before the stack access */
|
/* Insert a new load instruction before the stack access */
|
||||||
char Buf [16];
|
const char* Arg = MakeHexArg (E->RI->In.RegY - Offs);
|
||||||
CodeEntry* X;
|
CodeEntry* X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, E->LI);
|
||||||
xsprintf (Buf, sizeof (Buf), "$%02X", E->RI->In.RegY - Offs);
|
|
||||||
X = NewCodeEntry (OP65_LDY, AM65_IMM, Buf, 0, E->LI);
|
|
||||||
CS_InsertEntry (S, X, I);
|
CS_InsertEntry (S, X, I);
|
||||||
|
|
||||||
/* One more inserted entries */
|
/* One more inserted entries */
|
||||||
@ -185,9 +180,8 @@ static unsigned Opt_staxspidx (CodeSeg* S, unsigned Push, unsigned Store,
|
|||||||
CS_InsertEntry (S, X, Store+2);
|
CS_InsertEntry (S, X, Store+2);
|
||||||
if (StoreEntry->RI->In.RegX >= 0) {
|
if (StoreEntry->RI->In.RegX >= 0) {
|
||||||
/* Value of X is known */
|
/* Value of X is known */
|
||||||
char Buf [16];
|
const char* Arg = MakeHexArg (StoreEntry->RI->In.RegX);
|
||||||
xsprintf (Buf, sizeof (Buf), "$%02X", StoreEntry->RI->In.RegX);
|
X = NewCodeEntry (OP65_LDA, AM65_IMM, Arg, 0, StoreEntry->LI);
|
||||||
X = NewCodeEntry (OP65_LDA, AM65_IMM, Buf, 0, StoreEntry->LI);
|
|
||||||
} else {
|
} else {
|
||||||
/* Value unknown */
|
/* Value unknown */
|
||||||
X = NewCodeEntry (OP65_TXA, AM65_IMP, 0, 0, StoreEntry->LI);
|
X = NewCodeEntry (OP65_TXA, AM65_IMP, 0, 0, StoreEntry->LI);
|
||||||
@ -271,9 +265,8 @@ static unsigned Opt_tosaddax (CodeSeg* S, unsigned Push, unsigned Add,
|
|||||||
CodeLabel* L;
|
CodeLabel* L;
|
||||||
if (PushEntry->RI->In.RegX >= 0) {
|
if (PushEntry->RI->In.RegX >= 0) {
|
||||||
/* Value of first op high byte is known */
|
/* Value of first op high byte is known */
|
||||||
char Buf [16];
|
const char* Arg = MakeHexArg (PushEntry->RI->In.RegX);
|
||||||
xsprintf (Buf, sizeof (Buf), "$%02X", PushEntry->RI->In.RegX);
|
X = NewCodeEntry (OP65_LDX, AM65_IMM, Arg, 0, AddEntry->LI);
|
||||||
X = NewCodeEntry (OP65_LDX, AM65_IMM, Buf, 0, AddEntry->LI);
|
|
||||||
} else {
|
} else {
|
||||||
/* Value of first op high byte is unknown */
|
/* Value of first op high byte is unknown */
|
||||||
X = NewCodeEntry (OP65_LDX, AM65_ZP, ZPHi, 0, AddEntry->LI);
|
X = NewCodeEntry (OP65_LDX, AM65_ZP, ZPHi, 0, AddEntry->LI);
|
||||||
@ -429,10 +422,8 @@ static unsigned Opt_tosorax (CodeSeg* S, unsigned Push, unsigned Or,
|
|||||||
CS_InsertEntry (S, X, Or+1);
|
CS_InsertEntry (S, X, Or+1);
|
||||||
if (PushEntry->RI->In.RegX >= 0 && OrEntry->RI->In.RegX >= 0) {
|
if (PushEntry->RI->In.RegX >= 0 && OrEntry->RI->In.RegX >= 0) {
|
||||||
/* Both values known, precalculate the result */
|
/* Both values known, precalculate the result */
|
||||||
char Buf [16];
|
const char* Arg = MakeHexArg (PushEntry->RI->In.RegX | OrEntry->RI->In.RegX);
|
||||||
int Val = (PushEntry->RI->In.RegX | OrEntry->RI->In.RegX);
|
X = NewCodeEntry (OP65_LDX, AM65_IMM, Arg, 0, OrEntry->LI);
|
||||||
xsprintf (Buf, sizeof (Buf), "$%02X", Val);
|
|
||||||
X = NewCodeEntry (OP65_LDX, AM65_IMM, Buf, 0, OrEntry->LI);
|
|
||||||
CS_InsertEntry (S, X, Or+2);
|
CS_InsertEntry (S, X, Or+2);
|
||||||
} else if (PushEntry->RI->In.RegX != 0) {
|
} else if (PushEntry->RI->In.RegX != 0) {
|
||||||
/* High byte is unknown */
|
/* High byte is unknown */
|
||||||
@ -506,10 +497,8 @@ static unsigned Opt_tosxorax (CodeSeg* S, unsigned Push, unsigned Xor,
|
|||||||
CS_InsertEntry (S, X, Xor+1);
|
CS_InsertEntry (S, X, Xor+1);
|
||||||
if (PushEntry->RI->In.RegX >= 0 && XorEntry->RI->In.RegX >= 0) {
|
if (PushEntry->RI->In.RegX >= 0 && XorEntry->RI->In.RegX >= 0) {
|
||||||
/* Both values known, precalculate the result */
|
/* Both values known, precalculate the result */
|
||||||
char Buf [16];
|
const char* Arg = MakeHexArg (PushEntry->RI->In.RegX ^ XorEntry->RI->In.RegX);
|
||||||
int Val = (PushEntry->RI->In.RegX ^ XorEntry->RI->In.RegX);
|
X = NewCodeEntry (OP65_LDX, AM65_IMM, Arg, 0, XorEntry->LI);
|
||||||
xsprintf (Buf, sizeof (Buf), "$%02X", Val);
|
|
||||||
X = NewCodeEntry (OP65_LDX, AM65_IMM, Buf, 0, XorEntry->LI);
|
|
||||||
CS_InsertEntry (S, X, Xor+2);
|
CS_InsertEntry (S, X, Xor+2);
|
||||||
} else if (PushEntry->RI->In.RegX != 0) {
|
} else if (PushEntry->RI->In.RegX != 0) {
|
||||||
/* High byte is unknown */
|
/* High byte is unknown */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user