Re: [cc65] is the following safe, i think not

From: Joseph Rose <rose.joseph121yahoo.com>
Date: 2011-11-24 01:37:07
Try checking to see if the function is __fastcall__.  That happened to me a few times.  :(  If it is, remove the jsr popa: the data is already in .A.
BTW, I've seen some 6502 assembler programmers use "JMP <routine>" rather than "JSR <routine> | RTS."  It saves one byte and 12 cycles.
 
----- Original Message -----
From: Egan Ford <egan@sense.net>
To: cc65@musoftware.de
Cc: 
Sent: Wednesday, November 23, 2011 12:53 PM
Subject: [cc65] is the following safe, i think not

.export         _putchar
.import         popa

ECHO    =       $FFEF           ; print character from A

_putchar:
        jsr     popa
        ORA     $80
        JSR     ECHO
        RTS

The code works, but when used in a C function, the value passed gets
clobbered, e.g.:

function foo(char bar) {

putchar(blah[bar]);  //works
putchar(blah[bar]); //fails

If do this I can work around the problem:

function foo(char bar) {
char tmp=bar;

putchar(blah[tmp]);  //works
putchar(blah[tmp]); //works too


So I know that my _putchar code is the problem, but what is the fix?

Thanks.
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Thu Nov 24 01:37:16 2011

This archive was generated by hypermail 2.1.8 : 2011-11-24 01:37:19 CET