the compiler tries to compare '@r15' against zero which is correct.
previous add instruction sets Z flag and mov insn does not affect it,
therefore 'cmp #0, 0(r15)' may be ommited.
To be honest -- mov @r15, r15 is redudant here and a result of no
optimization.
cheers,
~d
On Wednesday 15 October 2003 00:25, Pedro Zorzenon Neto wrote:
> Hi Folks,
>
> It seems mspgcc is generating bad code. Please see attached file.c and
> file.s
>
> I compiled with the following command line:
>
> msp430-gcc -mmcu=msp430x149 -Wall -S file.c -o file.s
>
> In the assembler, there is no "cmp" after "mov", and msp user guide
> tells that "mov" opcode does not affect Z flag.
>
> Code generated by mspgcc:
>
> .L3:
> mov &menu_i, r15
> rla r15
> rla r15
> add #menu_stack+2, r15
> add #llo(12), @r15
> mov @r15, r15
> jne .L3
>
> Code that I think is correct:
>
> .L3:
> mov &menu_i, r15
> rla r15
> rla r15
> add #menu_stack+2, r15
> add #llo(12), @r15
> mov @r15, r15
> cmp #0, r15 ; <- this is missing
> jne .L3
>
> The C line related with this code is:
> while (* (int *) (++menu_stack[menu_i].item));
> I already tried:
> while ((* (int *) (++menu_stack[menu_i].item)) != NULL);
> And it generated the same code.
>
> Could you help me to fix this?
>
> In many places in my complete program, when I want to see if a pointer
> is null or not, this error occours.
>
> Thanks,
> Pedro
--
/*****************************************************************
("`-''-/").___..--''"`-._ (\ Dimmy the Wild UA1ACZ
`6_ 6 ) `-. ( ).`-.__.`) State Polytechnical Univ.
(_Y_.)' ._ ) `._ `. ``-..-' Radio-Physics Departament
_..`--'_..-_/ /--'_.' ,' Saint Petersburg, Russia
(il),-'' (li),' ((!.-' +7 (812) 5403923, 5585314
*****************************************************************/