From 57ab9239ce98a7fb435743c9bf7d0b43249cb517 Mon Sep 17 00:00:00 2001 From: kvigor Date: Thu, 9 Mar 2000 06:57:21 +0000 Subject: [PATCH] 10 bit stack mode: almost working... git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@181 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/mcs51/gen.c | 78 ++++++++++++++++++++++++--------------------- src/mcs51/main.c | 5 ++- src/mcs51/peeph.def | 18 ++++++++++- 3 files changed, 62 insertions(+), 39 deletions(-) diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 2121e19c..37f9a78e 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -232,6 +232,20 @@ static asmop *newAsmop (short type) return aop; } +static void genSetDPTR(int n) +{ + if (!n) + { + emitcode(";", "Select standard DPTR"); + emitcode("mov", "dps, #0x00"); + } + else + { + emitcode(";", "Select alternate DPTR"); + emitcode("mov", "dps, #0x01"); + } +} + /*-----------------------------------------------------------------*/ /* pointerCode - returns the code for a pointer type */ /*-----------------------------------------------------------------*/ @@ -329,29 +343,16 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result) ((char)(sym->stack - _G.nRegsSaved )) : ((char)sym->stack)) & 0xff); - if (/* result */ 1) - { - emitcode (";", "#switchDPTR(2)"); - } - emitcode ("mov","dpx,#0x40"); - emitcode ("mov","dph,#0x00"); - emitcode ("mov", "dpl, a"); - if (/* result */ 1) - { - emitcode (";", "#switchDPTR(1)"); - } + genSetDPTR(1); + emitcode ("mov","dpx1,#0x40"); + emitcode ("mov","dph1,#0x00"); + emitcode ("mov","dpl1, a"); + genSetDPTR(0); if ( _G.accInUse ) emitcode("pop","acc"); - if (/* !result */ 0) - { - sym->aop = aop = newAsmop(AOP_DPTR); - } - else - { - sym->aop = aop = newAsmop(AOP_DPTR2); - } + sym->aop = aop = newAsmop(AOP_DPTR2); aop->size = getSize(sym->type); return aop; } @@ -772,10 +773,10 @@ static char *aopGet (asmop *aop, int offset, bool bit16, bool dname) case AOP_DPTR: case AOP_DPTR2: - if (aop->type == AOP_DPTR2) - { - emitcode (";", "#switchDPTR(2)"); - } + if (aop->type == AOP_DPTR2) + { + genSetDPTR(1); + } while (offset > aop->coff) { emitcode ("inc","dptr"); @@ -792,13 +793,14 @@ static char *aopGet (asmop *aop, int offset, bool bit16, bool dname) emitcode("clr","a"); emitcode("movc","a,@a+dptr"); } - else + else { emitcode("movx","a,@dptr"); + } - if (aop->type == AOP_DPTR2) - { - emitcode (";", "#switchDPTR(1)"); - } + if (aop->type == AOP_DPTR2) + { + genSetDPTR(0); + } return (dname ? "acc" : "a"); @@ -915,10 +917,10 @@ static void aopPut (asmop *aop, char *s, int offset) case AOP_DPTR: case AOP_DPTR2: - if (aop->type == AOP_DPTR2) - { - emitcode (";", "#switchDPTR(2)"); - } + if (aop->type == AOP_DPTR2) + { + genSetDPTR(1); + } if (aop->code) { werror(E_INTERNAL_ERROR,__FILE__,__LINE__, @@ -944,9 +946,9 @@ static void aopPut (asmop *aop, char *s, int offset) emitcode ("movx","@dptr,a"); if (aop->type == AOP_DPTR2) - { - emitcode (";", "#switchDPTR(1)"); - } + { + genSetDPTR(0); + } break; case AOP_R0: @@ -1095,14 +1097,16 @@ static void reAdjustPreg (asmop *aop) case AOP_DPTR2: if (aop->type == AOP_DPTR2) { - emitcode (";", "#switchDPTR(2)"); + genSetDPTR(1); } while (size--) + { emitcode("lcall","__decdptr"); + } if (aop->type == AOP_DPTR2) { - emitcode (";", "#switchDPTR(1)"); + genSetDPTR(0); } break; diff --git a/src/mcs51/main.c b/src/mcs51/main.c index 7d0a5a1f..80280ccb 100644 --- a/src/mcs51/main.c +++ b/src/mcs51/main.c @@ -118,7 +118,10 @@ static void _mcs51_genAssemblerPreamble(FILE *of) { fputs(".flat24 on\t\t; 24 bit flat addressing\n", of); fputs("dpx = 0x93\t\t; dpx register unknown to assembler\n", of); - + fputs("dps = 0x86\t\t; dps register unknown to assembler\n", of); + fputs("dpl1 = 0x84\t\t; dpl1 register unknown to assembler\n", of); + fputs("dph1 = 0x85\t\t; dph1 register unknown to assembler\n", of); + fputs("dpx1 = 0x95\t\t; dpx1 register unknown to assembler\n", of); } } diff --git a/src/mcs51/peeph.def b/src/mcs51/peeph.def index 3065ce6e..315c72f8 100644 --- a/src/mcs51/peeph.def +++ b/src/mcs51/peeph.def @@ -1758,4 +1758,20 @@ replace { movx @dptr,a mov dptr,%2 movx @dptr,a -} \ No newline at end of file +} + +replace { + mov dps, #0x00 + mov dps, #0x01 +} by { + ; Peephole 220a removed bogus DPS set + mov dps, #0x01 +} + +replace { + mov dps, #0x01 + mov dps, #0x00 +} by { + ; Peephole 220b removed bogus DPS set + mov dps, #0x00 +} -- 2.47.2