Register addresses?

Not trying to accomplish anything in particular. Just learning here. Satisfying curiosity.

So I wrote this:

union myUnion 
{
  volatile uint8_t* ptr;
  int num;
};

myUnion tcca = {&TCCR0A};
myUnion tccb = {&TCCR0B};
myUnion pind = {&PIND};
myUnion ddrd = {&DDRD};


void setup()
{
  Serial.begin(9600);
  Serial.println(tcca.num);
  Serial.println(tccb.num);
  Serial.println(pind.num);
  Serial.println(ddrd.num);
}

void loop()
{
}

And it gave me:

68
69
41
42

So can I access those registers with those numbers? Something like this (which obviously doesn't compile but you see what I want to be able to do)

uint8_t pind_val = *(41);

If I can access things like that, then is there a list of the addresses of the registers on the atmega? It would be neat to be able to write a serial command handler on Arduino and have a Python GUI on my computer asking for register values by address instead of having to hard code a pointer on Arduino for each one.

Doing it this way compiles OK.

Will it do what I expect and set pind_val to the value sitting in the PIND register?

uint8_t pind_val = *((volatile uint8_t*)41);

Delta_G: Doing it this way compiles OK.

Will it do what I expect and set pind_val to the value sitting in the PIND register?

uint8_t pind_val = *((volatile uint8_t*)41);

Yes. If you just run the C preprocessor on your code, it'll come out to that.

Not quite - IO registers are declared as volatile so the compiler doesn't cache the value. From various avr include files:

#define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr))
...
#define _SFR_IO8(io_addr) _MMIO_BYTE((io_addr) + __SFR_OFFSET)
...
#define PIND _SFR_IO8(0x09)

Note that _SFR_OFFSET is 32 for the 328 chip, 32 + 9 = 41 which is the address seen in your code. "SFR" stands for special function register.