-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all!
Bodo Rzany schrieb: > Am Wed, 28 Jun 2006 19:59:27 +0000 (UTC) schrieb Grant Edwards: >> Can anybody explain the code generated for this function? >> >> #include <io.h> >> >> unsigned two; >> >> void foo(void) >> { >> two = P6IN + P6IN; >> } >> >> 21 foo: >> >> 26 0000 5F42 3400 mov.b &0x0034, r15 >> 27 0004 4E4F mov.b r15, r14 >> 28 0006 5F42 3400 mov.b &0x0034, r15 >> 29 000a 7FF3 and.b #-1,r15 >> 30 000c 0E5F add r15, r14 >> 31 000e 824E 0000 mov r14, &two >> 32 0012 3041 ret >> >> Why the extra mov.b? > > Which extra mov.b? There are two extra mov.b (see below). > >> Why the and.b? > > Too less optimizing within the compiler? > >> Why isn't this correct? >> >> mov.b &0x0034, r15 >> mov.b &0x0034, r14 >> add r15, r14 >> mov r14, &two >> ret > > This *is* correct. But if you really want to deal with assembler > (which I do prefer on the msp430), you could code as follows: > > mov.b &0x0034, r15 > add r15, r15 > mov r15, &two > ret Hmmm... I thought about that version too but it is wrong according to the original C code. P6IN is defined "volatile". That means an extra reading of the input port (debouncing purpose for example). For that part the generated code and Grants version is correct in reading the port twice. Your code should be generated, if the original C code is something like the following examples: two = 2 * P6IN; two = P6IN << 1; Hopefully the implicit casts will work on that. If not, then additional casts to (unsigned) should be added. Always a good idea if you use Lint or QAC. Robert Dominicus-Schleutermann - -- Robert Dominicus-Schleutermann Telefon : +49 36203 96314 Software+Systeme Erfurt GmbH Telefon : +49 36203 96301 Fichtenweg 8 Fax : +49 36203 96333 D-99198 Erfurt-Kerspleben eMail: mailto:robert.dominicus-schleuterm...@sse-erfurt.de -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEpOs87kPn7znKZuYRAlXFAKDqK14pQmU7OhxMYXxj6BiPp52w+wCfe4gy tljPJakq5hx0NafeqDOgXzQ= =chMJ -----END PGP SIGNATURE-----