From 38ff6818fca9b290373ee8aaeff0a23a5e2865bf Mon Sep 17 00:00:00 2001 From: uz Date: Fri, 4 Sep 2009 20:57:23 +0000 Subject: [PATCH] Fixed wrong code generation in g_leasp. git-svn-id: svn://svn.cc65.org/cc65/trunk@4118 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/codegen.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cc65/codegen.c b/src/cc65/codegen.c index 2f67a07fc..76077ab30 100644 --- a/src/cc65/codegen.c +++ b/src/cc65/codegen.c @@ -929,13 +929,15 @@ void g_getind (unsigned Flags, unsigned Offs) void g_leasp (int Offs) /* Fetch the address of the specified symbol into the primary register */ { - /* Get low and high byte */ - unsigned char Lo = (unsigned char) Offs; - unsigned char Hi = (unsigned char) (Offs >> 8); + unsigned char Lo, Hi; /* Calculate the offset relative to sp */ Offs -= StackPtr; + /* Get low and high byte */ + Lo = (unsigned char) Offs; + Hi = (unsigned char) (Offs >> 8); + /* Generate code */ if (Lo == 0) { if (Hi <= 3) { @@ -977,10 +979,10 @@ void g_leasp (int Offs) /* Full 16 bit offset inlined */ AddCodeLine ("lda sp"); AddCodeLine ("clc"); - AddCodeLine ("adc #$%02X", (unsigned char) Offs); + AddCodeLine ("adc #$%02X", Lo); AddCodeLine ("pha"); AddCodeLine ("lda sp+1"); - AddCodeLine ("adc #$%02X", (unsigned char) (Offs >> 8)); + AddCodeLine ("adc #$%02X", Hi); AddCodeLine ("tax"); AddCodeLine ("pla"); } -- 2.39.5