Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#2251 STM8: Compare long with 0 give bad result

closed-fixed
None
STM8
7
2014-02-09
2014-02-07
Pascal S
No

I think that I have found a bug in the STM8 port.

Please, see that function:

char compare_with_zero(long x)
{
   if(x==NULL ||
x==0)
   {
      return 1;
   }
   else
   {
       return 0;
   }
}

This function can return 1 event if *x is different from 0.

The assembly generated code is :

_compare_with_zero:
; test_comp.c: 8: if(x==NULL || *x==0)
ldw x, (0x03, sp)
jreq 00101$
ldw x, (0x03, sp)
ld a, (0x3, x)
ld yh, a
ld a, (0x2, x)
ld yl, a
ldw x, (x)
tnzw x
jrne 00102$
tnzw x
jrne 00102$
00101$:
; test_comp.c: 10: return 1;
ld a, #0x01
jra 00105$
00102$:
; test_comp.c: 14: return 0;
clr a
00105$:
ret

I think that the two "tnzw x" should be replaced by "tnzw y".

The code is compiled "sdcc -mstm8 test_comp.c". I use sdcc-snapshot-i586-mingw32msvc-20140203-8940.

Thank you for your help.

Pascal

1 Attachments

Discussion

    • assigned_to: Philipp Klaus Krause
    • Priority: 5 --> 7
     
  • I see that exactly one of the two tnzw x should be tnzw y. Looks like an i should be i + 1 in line 5774 of stm8/gen.c.

    Philipp

     
  • Pascal S
    Pascal S
    2014-02-09

    I've tested the revision 8941. It's OK now.
    The ticket can be closed

    Thank you

     
    Last edit: Pascal S 2014-02-09
    • status: open --> closed-fixed