[cc65] Problem with 16/32-bit variables and conditions

From: Carlos Sánchez de La Lama <csanchez1sidsa.es>
Date: 2005-03-11 13:04:36
Hello,

I have a problem with this piece of code, I think the compiler is 
generating wrong assembler.

-------- code begin --------

int
test(unsigned long a)
{
    if (a)
    {
        return 1;
    }
    return 0;
}

-------- code end --------

the generates assembler is:

-------- code begin --------

.proc   _test: near

.segment        "CODE"

;
; if (a)
;
        .dbg    line, "test.c", 4
        jsr     ldeax0sp
        beq     L0003            <-- problem
;
; return 1;
;
        .dbg    line, "test.c", 6
        ldx     #$00
        lda     #$01
        jmp     incsp4
;
; return 0;
;
        .dbg    line, "test.c", 9
L0003:  ldx     #$00
        txa
;
; }
;
        .dbg    line, "test.c", 10
        jmp     incsp4
        .dbg    line

.endproc

-------- code end --------

As long as I understand, this will only test the last byte of "a" for a 
zero value, because the Zero flag will be set in the last (8-bit) load 
instruction in the ldeax0sp subroutine. If I call the test function with 
a=0xff00 the condition would be (incorrectly) found to be false.

Am I right?

Thank you in advance and best regards,

--
Carlos Sánchez de La Lama <csanchez@sidsa.es>

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Fri Mar 11 13:05:12 2005

This archive was generated by hypermail 2.1.8 : 2005-03-11 13:05:19 CET