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

From: MagerValp <MagerValp1cling.gu.se>
Date: 2005-03-11 13:27:07
>>>>> "CSdLL" == Carlos Sánchez de La Lama <csanchez@sidsa.es> writes:

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

CSdLL> Am I right?

Looks like it:

  #include <stdio.h>

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

  int main (void) {
    printf("test(0) == %s\n", test(0) ? "true" : "false");
    printf("test(1) == %s\n", test(1) ? "true" : "false");
    printf("test(0xff00) == %s\n", test(0xff00) ? "true" : "false");
    return(0);
  }

gives:

  test(0) == false
  test(1) == true
  test(0xff00) == false

-- 
    ___          .     .  .         .       . +  .         .      o   
  _|___|_   +   .  +     .     +         .  Per Olofsson, arkadspelare
    o-o    .      .     .   o         +          MagerValp@cling.gu.se
     -       +            +    .     http://www.cling.gu.se/~cl3polof/
----------------------------------------------------------------------
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:27:10 2005

This archive was generated by hypermail 2.1.8 : 2005-03-11 13:27:16 CET