From 99cbaddb0806a4c5ff2a7e43873957e0c3414b45 Mon Sep 17 00:00:00 2001 From: kvigor Date: Thu, 3 May 2001 22:55:21 +0000 Subject: [PATCH] clean up genDjnz for far data case; include same fix for mcs51 port. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@769 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/ds390/gen.c | 18 +++++++++++++++--- src/mcs51/gen.c | 25 ++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/ds390/gen.c b/src/ds390/gen.c index 184f8838..880b2e74 100644 --- a/src/ds390/gen.c +++ b/src/ds390/gen.c @@ -9242,9 +9242,21 @@ genDjnz (iCode * ic, iCode * ifx) * the accumulator, we must explicitly write * it back after the decrement. */ - emitcode ("dec", "%s", - aopGet(AOP(IC_RESULT(ic)), 0, FALSE, FALSE, FALSE)); - aopPut(AOP(IC_RESULT(ic)), "acc", 0); + char *rByte = aopGet(AOP(IC_RESULT(ic)), 0, FALSE, FALSE, TRUE); + + if (strcmp(rByte, "a")) + { + /* Something is hopelessly wrong */ + fprintf(stderr, "*** warning: internal error at %s:%d\n", + __FILE__, __LINE__); + /* We can just give up; the generated code will be inefficient, + * but what the hey. + */ + freeAsmop (IC_RESULT (ic), NULL, ic, TRUE); + return 0; + } + emitcode ("dec", "%s", rByte); + aopPut(AOP(IC_RESULT(ic)), rByte, 0); emitcode ("jnz", "%05d$", lbl->key + 100); } else if (IS_AOP_PREG (IC_RESULT (ic))) diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 1fc1c778..77b4ff5a 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -8123,7 +8123,30 @@ genDjnz (iCode * ic, iCode * ifx) aopOp (IC_RESULT (ic), ic, FALSE); - if (IS_AOP_PREG (IC_RESULT (ic))) + if (AOP_NEEDSACC(IC_RESULT(ic))) + { + /* If the result is accessed indirectly via + * the accumulator, we must explicitly write + * it back after the decrement. + */ + char *rByte = aopGet(AOP(IC_RESULT(ic)), 0, FALSE, FALSE); + + if (strcmp(rByte, "a")) + { + /* Something is hopelessly wrong */ + fprintf(stderr, "*** warning: internal error at %s:%d\n", + __FILE__, __LINE__); + /* We can just give up; the generated code will be inefficient, + * but what the hey. + */ + freeAsmop (IC_RESULT (ic), NULL, ic, TRUE); + return 0; + } + emitcode ("dec", "%s", rByte); + aopPut(AOP(IC_RESULT(ic)), rByte, 0); + emitcode ("jnz", "%05d$", lbl->key + 100); + } + else if (IS_AOP_PREG (IC_RESULT (ic))) { emitcode ("dec", "%s", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE)); -- 2.47.2