I haven't been able to find any references to this error among recent posts on this list. My apologies, if this turns out to be an old issue ;-)


When any optimization is active (i.e. -Ox for any x>0) msp430-gcc emits illegal assembly code for calls to memset with length=2 and a pointer which points to an odd address (i.e. not a word boundary).

The optimizer stage seems to recognize the call to memset and generates a single word-move instruction even if the address is unknown--or when it is known to be an odd address. However, according to the MSP430 user's guide (SLAU049E) §1.4.5: "When using word instructions, only even addresses may be used."


Steps to reproduce (using msp430-gcc version 3.2.3):

Compile the following c code to assembly using some optimization, e.g.

  msp430-gcc -O -S test.c



/* test.c start */

#include<string.h>

int array[2];

int main() {
  array[0] = 0x5555;
  array[1] = 0x5555;
  memset(((char*)&array)+1,0,2);
}

/* test.c end */


Inspecting the output, we get (ignoring boilerplate):

    mov     #llo(21845), &array
    mov     #llo(21845), &array+2
    mov     #llo(0), &array+1

The last line is *ILLEGAL* and the contents of array will be 0x00005555 rather than 0x55000055, which is what we expect--and what we will get if we do not use optimization.

Best regards
/Jacob Andersen



--
Jacob Andersen, Ph.d. student
Department of Computer Science, Aarhus University
Address: Åbogade 34, 8200 Århus N, Denmark
Office:  Ada-229
http://ereception.katrinebjerg.net/ereception/browser.jsp?s=jac...@cs
Email:   [email protected]
Phone:   +45 8942 5747
Mobile:  +45 6170 4305
Web:     http://www.cs.au.dk/~jacand

Reply via email to