Re: [Mspgcc-users] Code generation question

2006-07-03 Thread David Brown
- Original Message - From: "Roberto Padovani" To: "GCC for MSP430 - http://mspgcc.sf.net"; Sent: Monday, July 03, 2006 5:31 PM Subject: Re: [Mspgcc-users] Code generation question > I'll be brief because it's beer time here. > It's important t

Re: [Mspgcc-users] Code generation question

2006-07-03 Thread Grant Edwards
On 2006-07-03, Lichen Wang wrote: > P1IN is a hardware read-only 8-bit Special Function Register > (SFR). Every time you read it, it gives a potentially > different result. In addition, it may result in some side > effect in the hardware. > > Suppose I want to read P1IN twice and I

Re: [Mspgcc-users] Code generation question

2006-07-03 Thread Grant Edwards
On 2006-07-03, Roberto Padovani wrote: > Here's what is dangerous with irq enabled: > > two = P6IN + P6IN;// or any other way in which you write directly to "two" > > beacuse you inevitably get 2 instructions that sequentially write at > the memory address of "two": If you only want "two" wr

Re: [Mspgcc-users] Code generation question

2006-07-03 Thread Lichen Wang
Grant Edwards wrote:... I'd like to point out that 1) I didn't write that code originally, I ran across that example in a thread in the yahoo msp430 list. 2) The example isn't supposed to do anything useful, it's just a simple test-case that demonstrates a bug in the compiler. ... I didn'

Re: [Mspgcc-users] Code generation question

2006-07-03 Thread Roberto Padovani
quot; To: "GCC for MSP430 - http://mspgcc.sf.net"; Sent: Monday, July 03, 2006 3:35 PM Subject: Re: [Mspgcc-users] Code generation question > >> if you really want that single instruction as a function by itself and > >> you want it to write directly in the global var

Re: [Mspgcc-users] Code generation question

2006-07-03 Thread Grant Edwards
On 2006-07-03, David Brown wrote: >> but in this case, reading the C source code, I honestly can't >> understand for sure what it meantif I were to translate >> manually that code into asm, I would have asked a >> clarification to the programmer: did you want to sample twice >> the port and t

Re: [Mspgcc-users] Code generation question

2006-07-03 Thread Grant Edwards
On 2006-07-03, Roberto Padovani wrote: > but in this case, reading the C source code, I honestly can't > understand for sure what it meant What it "meant" is irrelevent. There are rules that state quite specifically how C source code is to be translated into machine operations. For one of

Re: [Mspgcc-users] Code generation question

2006-07-03 Thread David Brown
- Original Message - From: "Roberto Padovani" To: "GCC for MSP430 - http://mspgcc.sf.net"; Sent: Monday, July 03, 2006 3:35 PM Subject: Re: [Mspgcc-users] Code generation question > >> if you really want that single instruction as a function by itself

Re: [Mspgcc-users] Code generation question

2006-07-03 Thread Roberto Padovani
if you really want that single instruction as a function by itself and you want it to write directly in the global variable, then you should at least declare it naked. Perhaps this is a case where we have misunderstood each other - as far as I can tell, you said that Grant's code should be spli

Re: [Mspgcc-users] Code generation question

2006-07-03 Thread David Brown
- Original Message - From: "John Pote" To: "GCC for MSP430 - http://mspgcc.sf.net"; Sent: Monday, July 03, 2006 1:11 PM Subject: Re: [Mspgcc-users] Code generation question > Hi everone, > > My thought on the following snippet from the prev mail:- >

Re: [Mspgcc-users] Code generation question

2006-07-03 Thread David Brown
- Original Message - From: "Roberto Padovani" To: "GCC for MSP430 - http://mspgcc.sf.net"; Sent: Monday, July 03, 2006 11:57 AM Subject: Re: [Mspgcc-users] Code generation question > Hi David, > > criticism is fineI'll explain my view. > >

Re: [Mspgcc-users] Code generation question

2006-07-03 Thread John Pote
Hi everone, My thought on the following snippet from the prev mail:- > By the way, I think it's also better to change your initial example: > > unsigned two; > void foo(void) > { > two = P6IN + P6IN; > } > > into: > > unsigned two; > > void foo(void) > unsigned int tmp; > { > tmp = P6IN + P6I

Re: [Mspgcc-users] Code generation question

2006-07-03 Thread Roberto Padovani
Hi David, criticism is fineI'll explain my view. 2006/7/3, David Brown : I don't mean to sound patronising, but I don't think you are aware of what compilers do, how they work, how "volatile" works, or how to write good C code for embedded systems. I'm afraid your post is almost completely

Re: [Mspgcc-users] Code generation question

2006-07-03 Thread David Brown
ive critisism to aid your better understanding. Thinking about these things is good, and discussing them will refine that thinking. - Original Message - From: "Roberto Padovani" To: "GCC for MSP430 - http://mspgcc.sf.net"; Sent: Monday, July 03, 2006 9:16 AM Subject

Re: [Mspgcc-users] Code generation question

2006-07-03 Thread Roberto Padovani
knowing how a compiler works in the most unusual situations is always interesting...and this discussion is no different. however, a compiler is just a machine with a lot of rules, so you cannot expect it to be "clever" anytime, even if correct code is a necessity and efficiency is only a plus; but

Re: [Mspgcc-users] Code generation question

2006-06-30 Thread Grant Edwards
On 2006-06-30, Chris Liechti wrote: Just for fun, I tried compiling the code with "two" changed to an unsigned char. My mps430 compiler (3.2.3) then gives mov.b &P6IN, r15 rla.b r15 mov.b r15, &two ret In other words, it makes the same mistak

Re: [Mspgcc-users] Code generation question

2006-06-30 Thread Chris Liechti
Grant Edwards schrieb: On 2006-06-30, Grant Edwards wrote: On 2006-06-30, David Brown wrote: Just for fun, I tried compiling the code with "two" changed to an unsigned char. My mps430 compiler (3.2.3) then gives mov.b &P6IN, r15 rla.b r15 mov.b r15, &two ret In other words,

Re: [Mspgcc-users] Code generation question

2006-06-30 Thread Grant Edwards
On 2006-06-30, Grant Edwards wrote: > On 2006-06-30, David Brown wrote: > >> Just for fun, I tried compiling the code with "two" changed to an unsigned >> char. My mps430 compiler (3.2.3) then gives >> >> mov.b &P6IN, r15 >> rla.b r15 >> mov.b r15, &two >> ret >> >> In other word

Re: [Mspgcc-users] Code generation question

2006-06-30 Thread Lichen Wang
Hi, I experimented with IAR c-compiler for MSP430 (that came with eZ430-F2013). Here is my source code: #include "msp430x20x3.h" int main(void) { signed char sc; unsigned char uc; signed int si; unsigned int ui; sc=P1IN+P1IN; uc=P1IN+P1IN; si=P1IN+P1IN; ui=P1IN+P1I

Re: [Mspgcc-users] Code generation question

2006-06-30 Thread Grant Edwards
On 2006-06-30, David Brown wrote: > Just for fun, I tried compiling the code with "two" changed to an unsigned > char. My mps430 compiler (3.2.3) then gives > > mov.b &P6IN, r15 > rla.b r15 > mov.b r15, &two > ret > > In other words, it makes the same mistake you did and > disreg

Re: [Mspgcc-users] Code generation question

2006-06-30 Thread Grant Edwards
On 2006-06-30, Bodo Rzany wrote: > Am Wed, 28 Jun 2006 19:59:27 + (UTC) schrieb Grant Edwards: >> Can anybody explain the code generated for this function? >> >> #include >> >> unsigned two; >> >> void foo(void) >> { >> two = P6IN + P6IN; >> } >> >> 21 foo: >> >> 26

Re: [Mspgcc-users] Code generation question

2006-06-30 Thread David Brown
> Am Fri, 30 Jun 2006 11:20:03 +0200 schrieb David Brown: > >> > >> mov.b &0x0034, r15 > >> add r15, r15 > >> mov r15, &two > >> ret > > > > That would be wrong. PINB is declared volatile - the C code says it should > > be read twice, so it should be read twice by the generated assembly. T

Re: [Mspgcc-users] Code generation question

2006-06-30 Thread Bodo Rzany
Am Fri, 30 Jun 2006 11:13:32 +0200 schrieb Robert Dominicus-Schleutermann: > Bodo Rzany schrieb: >> Am Wed, 28 Jun 2006 19:59:27 + (UTC) schrieb Grant Edwards: >> >>> Why isn't this correct? >>> >>> mov.b &0x0034, r15 >>> mov.b &0x0034, r14 >>> add r15, r14 >>> mov

Re: [Mspgcc-users] Code generation question

2006-06-30 Thread Bodo Rzany
Am Fri, 30 Jun 2006 11:20:03 +0200 schrieb David Brown: >> >> mov.b &0x0034, r15 >> add r15, r15 >> mov r15, &two >> ret > > That would be wrong. PINB is declared volatile - the C code says it should > be read twice, so it should be read twice by the generated assembly. Thus > better code

Re: [Mspgcc-users] Code generation question

2006-06-30 Thread David Brown
- Original Message - From: "Bodo Rzany" To: Sent: Friday, June 30, 2006 10:57 AM Subject: Re: [Mspgcc-users] Code generation question > Am Wed, 28 Jun 2006 19:59:27 + (UTC) schrieb Grant Edwards: > > Can anybody explain the code generated for this functio

Re: [Mspgcc-users] Code generation question

2006-06-30 Thread Robert Dominicus-Schleutermann
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello all! Bodo Rzany schrieb: > Am Wed, 28 Jun 2006 19:59:27 + (UTC) schrieb Grant Edwards: >> Can anybody explain the code generated for this function? >> >> #include >> >> unsigned two; >> >> void foo(void) >> { >> two = P6IN + P6IN; >> } >>

Re: [Mspgcc-users] Code generation question

2006-06-30 Thread Bodo Rzany
Am Wed, 28 Jun 2006 19:59:27 + (UTC) schrieb Grant Edwards: > Can anybody explain the code generated for this function? > > #include > > unsigned two; > > void foo(void) > { > two = P6IN + P6IN; > } > > 21 foo: > > 26 5F42 3400 mov.b &0x0034, r15 > 27

[Mspgcc-users] Code generation question

2006-06-28 Thread Grant Edwards
Can anybody explain the code generated for this function? #include unsigned two; void foo(void) { two = P6IN + P6IN; } 21foo: 26 5F42 3400 mov.b &0x0034, r15 27 0004 4E4F mov.b r15, r14 28 0006 5F42 3400 mov.b