mirror of
https://github.com/cc65/cc65.git
synced 2024-12-23 04:30:10 +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).
|
||||
*/
|
||||
{
|
||||
static char Buf[4];
|
||||
static char Buf[16];
|
||||
xsprintf (Buf, sizeof (Buf), "$%02X", (char) Num);
|
||||
return Buf;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2001 Ullrich von Bassewitz */
|
||||
/* (C) 2001-2002 Ullrich von Bassewitz */
|
||||
/* Wacholderweg 14 */
|
||||
/* D-70597 Stuttgart */
|
||||
/* EMail: uz@cc65.org */
|
||||
@ -33,9 +33,6 @@
|
||||
|
||||
|
||||
|
||||
/* common */
|
||||
#include "xsprintf.h"
|
||||
|
||||
/* cc65 */
|
||||
#include "codeent.h"
|
||||
#include "codeinfo.h"
|
||||
@ -191,12 +188,12 @@ unsigned OptAdd2 (CodeSeg* S)
|
||||
(GetRegInfo (S, I+4, REG_AX) & REG_AX) == 0) {
|
||||
|
||||
/* Insert new code behind the addeqysp */
|
||||
char Buf [20];
|
||||
const char* Arg;
|
||||
CodeEntry* X;
|
||||
|
||||
/* ldy #xx-1 */
|
||||
xsprintf (Buf, sizeof (Buf), "$%02X", (int)(L[0]->Num-1));
|
||||
X = NewCodeEntry (OP65_LDY, AM65_IMM, Buf, 0, L[0]->LI);
|
||||
Arg = MakeHexArg (L[0]->Num-1);
|
||||
X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, L[0]->LI);
|
||||
CS_InsertEntry (S, X, I+4);
|
||||
|
||||
/* lda (sp),y */
|
||||
@ -228,8 +225,8 @@ unsigned OptAdd2 (CodeSeg* S)
|
||||
CS_InsertEntry (S, X, I+11);
|
||||
|
||||
/* ldy #yy+1 */
|
||||
xsprintf (Buf, sizeof (Buf), "$%02X", (int)(L[2]->Num+1));
|
||||
X = NewCodeEntry (OP65_LDY, AM65_IMM, Buf, 0, L[2]->LI);
|
||||
Arg = MakeHexArg (L[2]->Num+1);
|
||||
X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, L[2]->LI);
|
||||
CS_InsertEntry (S, X, I+12);
|
||||
|
||||
/* adc (sp),y */
|
||||
|
@ -201,11 +201,14 @@ unsigned Opt65C02Stores (CodeSeg* S)
|
||||
/* Get next entry */
|
||||
CodeEntry* E = CS_GetEntry (S, I);
|
||||
|
||||
/* Check for the sequence */
|
||||
if (E->OPC == OP65_STA &&
|
||||
/* Check for a store with a register value of zero and an addressing
|
||||
* 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_ZPX || E->AM == AM65_ABSX ) &&
|
||||
E->RI->In.RegA == 0) {
|
||||
E->AM == AM65_ZPX || E->AM == AM65_ABSX)) {
|
||||
|
||||
/* Replace by STZ */
|
||||
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 */
|
||||
/* D-70597 Stuttgart */
|
||||
/* EMail: uz@cc65.org */
|
||||
@ -33,10 +33,7 @@
|
||||
|
||||
|
||||
|
||||
/* common */
|
||||
#include "xsprintf.h"
|
||||
|
||||
/* cc65 */
|
||||
/* cc65 */
|
||||
#include "codeent.h"
|
||||
#include "codeinfo.h"
|
||||
#include "coptpush.h"
|
||||
@ -86,12 +83,12 @@ unsigned OptPush1 (CodeSeg* S)
|
||||
(GetRegInfo (S, I+3, REG_AX) & REG_AX) == 0) {
|
||||
|
||||
/* Insert new code behind the pushax */
|
||||
char Buf [20];
|
||||
const char* Arg;
|
||||
CodeEntry* X;
|
||||
|
||||
/* ldy #xx+1 */
|
||||
xsprintf (Buf, sizeof (Buf), "$%02X", (int)(L[0]->Num+2));
|
||||
X = NewCodeEntry (OP65_LDY, AM65_IMM, Buf, 0, L[0]->LI);
|
||||
Arg = MakeHexArg (L[0]->Num+2);
|
||||
X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, L[0]->LI);
|
||||
CS_InsertEntry (S, X, I+3);
|
||||
|
||||
/* jsr pushwysp */
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2001 Ullrich von Bassewitz */
|
||||
/* (C) 2001-2002 Ullrich von Bassewitz */
|
||||
/* Wacholderweg 14 */
|
||||
/* D-70597 Stuttgart */
|
||||
/* EMail: uz@cc65.org */
|
||||
@ -35,9 +35,6 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/* common */
|
||||
#include "xsprintf.h"
|
||||
|
||||
/* cc65 */
|
||||
#include "codeent.h"
|
||||
#include "codeinfo.h"
|
||||
@ -89,10 +86,8 @@ static unsigned AdjustStackOffset (CodeSeg* S, unsigned Start, unsigned Stop,
|
||||
} else {
|
||||
|
||||
/* Insert a new load instruction before the stack access */
|
||||
char Buf [16];
|
||||
CodeEntry* X;
|
||||
xsprintf (Buf, sizeof (Buf), "$%02X", E->RI->In.RegY - Offs);
|
||||
X = NewCodeEntry (OP65_LDY, AM65_IMM, Buf, 0, E->LI);
|
||||
const char* Arg = MakeHexArg (E->RI->In.RegY - Offs);
|
||||
CodeEntry* X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, E->LI);
|
||||
CS_InsertEntry (S, X, I);
|
||||
|
||||
/* One more inserted entries */
|
||||
@ -185,9 +180,8 @@ static unsigned Opt_staxspidx (CodeSeg* S, unsigned Push, unsigned Store,
|
||||
CS_InsertEntry (S, X, Store+2);
|
||||
if (StoreEntry->RI->In.RegX >= 0) {
|
||||
/* Value of X is known */
|
||||
char Buf [16];
|
||||
xsprintf (Buf, sizeof (Buf), "$%02X", StoreEntry->RI->In.RegX);
|
||||
X = NewCodeEntry (OP65_LDA, AM65_IMM, Buf, 0, StoreEntry->LI);
|
||||
const char* Arg = MakeHexArg (StoreEntry->RI->In.RegX);
|
||||
X = NewCodeEntry (OP65_LDA, AM65_IMM, Arg, 0, StoreEntry->LI);
|
||||
} else {
|
||||
/* Value unknown */
|
||||
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;
|
||||
if (PushEntry->RI->In.RegX >= 0) {
|
||||
/* Value of first op high byte is known */
|
||||
char Buf [16];
|
||||
xsprintf (Buf, sizeof (Buf), "$%02X", PushEntry->RI->In.RegX);
|
||||
X = NewCodeEntry (OP65_LDX, AM65_IMM, Buf, 0, AddEntry->LI);
|
||||
const char* Arg = MakeHexArg (PushEntry->RI->In.RegX);
|
||||
X = NewCodeEntry (OP65_LDX, AM65_IMM, Arg, 0, AddEntry->LI);
|
||||
} else {
|
||||
/* Value of first op high byte is unknown */
|
||||
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);
|
||||
if (PushEntry->RI->In.RegX >= 0 && OrEntry->RI->In.RegX >= 0) {
|
||||
/* Both values known, precalculate the result */
|
||||
char Buf [16];
|
||||
int Val = (PushEntry->RI->In.RegX | OrEntry->RI->In.RegX);
|
||||
xsprintf (Buf, sizeof (Buf), "$%02X", Val);
|
||||
X = NewCodeEntry (OP65_LDX, AM65_IMM, Buf, 0, OrEntry->LI);
|
||||
const char* Arg = MakeHexArg (PushEntry->RI->In.RegX | OrEntry->RI->In.RegX);
|
||||
X = NewCodeEntry (OP65_LDX, AM65_IMM, Arg, 0, OrEntry->LI);
|
||||
CS_InsertEntry (S, X, Or+2);
|
||||
} else if (PushEntry->RI->In.RegX != 0) {
|
||||
/* High byte is unknown */
|
||||
@ -506,10 +497,8 @@ static unsigned Opt_tosxorax (CodeSeg* S, unsigned Push, unsigned Xor,
|
||||
CS_InsertEntry (S, X, Xor+1);
|
||||
if (PushEntry->RI->In.RegX >= 0 && XorEntry->RI->In.RegX >= 0) {
|
||||
/* Both values known, precalculate the result */
|
||||
char Buf [16];
|
||||
int Val = (PushEntry->RI->In.RegX ^ XorEntry->RI->In.RegX);
|
||||
xsprintf (Buf, sizeof (Buf), "$%02X", Val);
|
||||
X = NewCodeEntry (OP65_LDX, AM65_IMM, Buf, 0, XorEntry->LI);
|
||||
const char* Arg = MakeHexArg (PushEntry->RI->In.RegX ^ XorEntry->RI->In.RegX);
|
||||
X = NewCodeEntry (OP65_LDX, AM65_IMM, Arg, 0, XorEntry->LI);
|
||||
CS_InsertEntry (S, X, Xor+2);
|
||||
} else if (PushEntry->RI->In.RegX != 0) {
|
||||
/* High byte is unknown */
|
||||
|
Loading…
Reference in New Issue
Block a user