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
--
.''`. Pedro Zorzenon Neto <[email protected]>
: :' : Debian GNU/Linux | GNU/Hurd: <http://www.debian.org>
`. `'` Debian BR: <http://debian-br.cipsga.org.br>
`- Be Happy! Be FREE!
#include <sys/types.h> /* for uint16_t */
struct MenuItem {
void (* display)(void); /* display routine */
struct MenuItem * inner; /* pointer to an inner menu (submenu) */
void (* enter)(void); /* function to execute if option is selected */
void (* incdec)(int); /* function to execute in case of inc/dec */
/* keys (parm -> 0 to dec and 1 to inc) */
void (* activate)(void); /* function to execute if activate is pressed */
uint16_t flag; /* flag to show/hide option -> */
/* if (~menu_flag & flag != 0) hide; */
};
/* Control structure for nested menus */
struct MenuControl {
struct MenuItem * menu; /* menu */
struct MenuItem * item; /* saved item pointer */
};
struct MenuControl menu_stack [4];
/* first level index menu */
int menu_i = 0;
/* goes to the previous menu item */
void menu_item_up(void) {
if (menu_stack[menu_i].item == menu_stack[menu_i].menu) {
/* if menu item is the first, find last menu */
while (* (int *) (++menu_stack[menu_i].item));
}
menu_stack[menu_i].item--;
}
.file "file.c"
.arch msp430x149
/* Hardware multiplier registers: */
__MPY=0x130
__MPYS=0x132
__MAC=0x134
__MACS=0x136
__OP2=0x138
__RESLO=0x13a
__RESHI=0x13c
__SUMEXT=0x13e
.global menu_i
.data
.p2align 1,0
.type menu_i,@object
.size menu_i,2
menu_i:
.short 0
.text
.p2align 1,0
.global menu_item_up
.type menu_item_up,@function
/***********************
* Function `menu_item_up'
***********************/
menu_item_up:
/* prologue: frame size = 0 */
.L__FrameSize_menu_item_up=0x0
.L__FrameOffset_menu_item_up=0x4
push r5
push r4
/* prologue end (size=2) */
mov &menu_i, r15
rla r15
rla r15
mov r15, r14
add #menu_stack+2, r14
mov &menu_i, r15
rla r15
rla r15
add #menu_stack, r15
cmp @r14, @r15
jne .L2
.L3:
mov &menu_i, r15
rla r15
rla r15
add #menu_stack+2, r15
add #llo(12), @r15
mov @r15, r15
jne .L3
.L2:
mov &menu_i, r15
rla r15
rla r15
add #menu_stack+2, r15
add #llo(-12), @r15
/* epilogue: frame size=0 */
pop r4
pop r5
ret
/* epilogue end (size=3) */
/* function menu_item_up size 41 (36) */
.Lfe1:
.size menu_item_up,.Lfe1-menu_item_up
/********* End of function ******/
.comm menu_stack,16,2
/*********************************************************************
* File file.c: code size: 41 words (0x29)
* incl. words in prologues: 2, epilogues: 3
*********************************************************************/