Re: compiler bug?

Date view Thread view Subject view

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 1999-07-09 19:42:24


On Fri, 09 Jul 1999, you wrote:
>I think something's broken in cc65 -- x[y>>n] doesn't seem to work the
>way it should.

You are right. When addressing local arrays, the code generator omits a "clc"
instruction when calculating the effective address on the stack so the wrong
slot is accessed if the carry is set at that time. The problem is not in the
shift operation, but in the stack access. Maybe the shift operation gives a
high probability for the bug being triggered, since it often returns with
carry set.

Here's a patch for the compiler:

*** codegen.c~	Sat May 15 14:28:26 1999
--- codegen.c	Fri Jul  9 19:39:49 1999
***************
*** 1674,1681 ****
      if (offs != 0) {
  	/* We cannot address more then 256 bytes of locals anyway */
  	CheckLocalOffs (offs);
! 	out ("\tadc\t#$%02X\n"
! 	     "\tbcc\t*+3\n"
  	     "\tinx\n",
  	     offs & 0xFF);
  	/* Invalidate X */
--- 1674,1682 ----
      if (offs != 0) {
  	/* We cannot address more then 256 bytes of locals anyway */
  	CheckLocalOffs (offs);
! 	out ("\tclc\n"
! 	     "\tadc\t#$%02X\n"
! 	     "\tbcc\t*+4\n"	/* Do also skip the CLC insn below */
  	     "\tinx\n",
  	     offs & 0xFF);
  	/* Invalidate X */


Thanks for pointing out this problem!

Regards


	Uz


--
Ullrich von Bassewitz                                  uz_at_musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2001-12-14 22:05:44 CET