[cc65] Strange behaviour of a simple code

From: Carlos <shangri-la1teleline.es>
Date: 2010-08-09 10:51:56
In these last days i'm really puzzled with a strange behaviour with a cc65 simple program, don't know if is some kind of bug or a bad code from my part but can't find where the problem can be.

The result of the main code is not right:

1.  FROM:  17600
1.  TO:  30719
3.  FROM:  17473
3.  TO:  30209

but if uncomment the two commented printf lines then the result is the expected:

1.  FROM:  17600
1.  TO:  30719
2.  FROM:  17600
2.  TO:  30336
3.  FROM:  17728
3.  TO:  30464


why is the behaviour changed only for the printf lines? Any ideas?


test.c
------

#include <stdio.h>

void inc_test(void);

unsigned int from, to;


// MAIN
void main(void)
{
 from = 17600;
 to = 30719;
 
 printf("1. FROM: %u\n", from);
 printf("1. TO: %u\n", to);
 
 if (to >= 0x7740)   // 30528
 {
  to = 0x7680;  // 30336
 }
 else
 {
  to = 0x7740;
 }
 
 //printf("2. FROM: %u\n", from);
 //printf("2. TO: %u\n", to);
 
 inc_test();
 ++from;
 ++to;
 
 inc_test();
 ++from;
 ++to;

 printf("3. FROM: %u\n", from);
 printf("3. TO: %u\n", to);
}



inctest.s
---------

.export _inc_test

.import _from
.import _to


.CODE

; ---------------------------------------------------------------
; _inc_test
; ---------------------------------------------------------------
_inc_test:

 ldx #$15

@LGO: 

 lda _from
 adc #$03
 sta _from
 lda _to
 adc #$03
 sta _to

 dex
 bne @LGO

 rts



- - - AVISO  - - -
Este correo electrónico contiene información privada y confidencial. Si usted no es el destinatario del mensaje no está autorizado a leerlo, copiarlo o difundirlo. Si lo ha recibido por error, por favor contacte con el remitente y destruya su contenido. Cualquier uso adicional de este correo está estrictamente prohibido.

- - - NOTICE - - -
Privileged/confidential information may be contained in this e-mail. Any reading, copying o dissemination of this communication by persons or entities other than its intended recipient is prohibited. If you received this in error, please contact the sender and delete it. Any further use of this e-mail by you is strictly prohibited.

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Mon Aug 9 10:52:40 2010

This archive was generated by hypermail 2.1.8 : 2010-08-09 10:52:44 CEST