Volatile pointer

Guest #75515
I am using mmio to access an external unit from my at90s8515. To access
this device easily I have an pointer that points to the start of the
mmio area. The interesting parts og the code looks like this:

volatile char *mmio =(char *)0x8300;

...
{
...
  mmio[a] = val1;
  mmio[b] = val1 >> 8;
  mmio[c] = val2;
...
}

this is compiled with:
avr-gcc -g -wall -O2 -mmcu=at90s8515 -Wl ...

the disassembled output becommes like this:

  mmio[a] = val1;
  e0:  e0 91 60 00   lds  r30, 0x0060
  e4:  f0 91 61 00   lds  r31, 0x0061
  e8:  42 87         std  Z+10, r20  ; 0x0a
  mmio[b] = val1 >> 8;
  ea:  e0 91 60 00   lds  r30, 0x0060
  ee:  f0 91 61 00   lds  r31, 0x0061
  f2:  85 2f         mov  r24, r21
  f4:  99 27         eor  r25, r25
  f6:  83 87         std  Z+11, r24  ; 0x0b
  mmio[c] = val2;
  f8:  e0 91 60 00   lds  r30, 0x0060
  fc:  f0 91 61 00   lds  r31, 0x0061
 100:  60 87         std  Z+8, r22  ; 0x08

My problem is all these lds r30/r31. That makes me believe that the
compiler treates the pointer as a volatile pointer not a pointer to a
volatile area. Does anyone have any ideas how to optimize this?

Reply

A question of your own? This thread is over 22 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.