Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: Looking to buy compiler

2005-11-08 by rtstofer

All,

I have been trying to follow the issue of the code generation for 
the typedef.  So, I tried it for setting 3 of the bits; the two 
least significant and the most significant, ignoring the padding:

  27:main.c        **** 	T0MCRbits.MR0I = 1;
  26 000c 0E32A0E3 		mov	r3, #-536870912
  27 0010 013983E2 		add	r3, r3, #16384
  28 0014 143083E2 		add	r3, r3, #20
  29 0018 0020D3E5 		ldrb	r2, [r3, #0]
  30 001c 012082E3 		orr	r2, r2, #1
  31 0020 0020C3E5 		strb	r2, [r3, #0]

  28:main.c        **** 	T0MCRbits.MR0R = 1;
  32              		.loc 1 28 0
  33 0024 0E32A0E3 		mov	r3, #-536870912
  34 0028 013983E2 		add	r3, r3, #16384
  35 002c 143083E2 		add	r3, r3, #20
  36 0030 0020D3E5 		ldrb	r2, [r3, #0]
  37 0034 022082E3 		orr	r2, r2, #2
  38 0038 0020C3E5 		strb	r2, [r3, #0]

  29:main.c        **** 	T0MCRbits.MR3S = 1;
  39              		.loc 1 29 0
  40 003c 0E32A0E3 		mov	r3, #-536870912
  41 0040 013983E2 		add	r3, r3, #16384
  42 0044 143083E2 		add	r3, r3, #20
  43 0048 0120D3E5 		ldrb	r2, [r3, #1]
  44 004c 082082E3 		orr	r2, r2, #8
  45 0050 0120C3E5 		strb	r2, [r3, #1]

Since the typedef describes only 16 bits, setting MR3S results in 
setting the 4th bit of the second byte.  Seems right to me.  It 
doesn't appear, to me anyway, that packing comes into play here.

OK, I think I understand: the problem is that you can't use byte 
access to a 32 bit hardware register even if it is memory mapped.  
But, the compiler can't KNOW that a given address must be handled as 
a 32 bit access, it has to be told.  I suppose if the compiler were 
SPECIFIC to a given piece of hardware it would be possible to impart 
that knowledge but it isn't.

The thing I don't understand is the address calculation.  I am 
using -O0 so I understand it won't do much optimizing but, to me, 
the 3 instructions used to load a register with a constant value 
seems excessive.  It gets a little better with -O3 but still, the 
address is a constant, why calculate it?

Now, since the compiler writers are very bright folks and I am just 
a user who has never read the standard (how come I have to pay for 
it?), I assume they do this calculation for a reason.  Does anyone 
know why?

Thanks
Richard

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.