avr (2560) port names vs. addresses

Hello! I have gotten so confused...maybe too much reading during one day :-) AtMega 2560 datasheet says for example: 0x04 (0x24) DDRBm, address of DDRB. if I want to set DDRB so that bits 5-6 are output and the rest are inputs, I can write for example: DDRB = 0b01100000, using port manipulation, and I know this works. But, using assembly, I can also write: ld r18,0b01100000 ld DDRB,r18 What I want to know, is: Are both ways correct, or should I use DDRB-0x20 in assebly version for register addresses 00-3f (hex)? ButActually the question is: What are the "real addresses" for avr registers? The datasheet says: 0x3F (0x5F) SREG 0x3E (0x5E) SPH

0x3D (0x5D)

--

-- 0x04 (0x24) DDRB 0x03 (0x23) PINB 0x02 (0x22) PORTA 0x01 (0x21) DDRA 0x00 (0x20) PINA

But how are the Port names defined in avr for those addresses 00-3F / (20-5F), which are the "right" values?

Are both ways correct,

Yes. Though why you want to resort to assembler to assign a value to a register is beyond me.

ButActually the question is: What are the “real addresses” for avr registers?

I’m not sure that the question is relevant. You have name for the resister. Why do you care what the address is for that name?

What is the address of i in this:

   for(byte i=0; i<15; i++)

Does it matter?

PaulS:

Are both ways correct,

Yes. Though why you want to resort to assembler to assign a value to a register is beyond me.

ButActually the question is: What are the “real addresses” for avr registers?

I’m not sure that the question is relevant. You have name for the resister. Why do you care what the address is for that name?

What is the address of i in this:

   for(byte i=0; i<15; i++)

Does it matter?

The address of i in your for (next) doesn’t matter at all.
I need too to use assembler, not necessarily programming my arduino with it, but because I have some code written in assembler and I may need to write it in c port minipulation style. To do that I need to know the real addresses behind the i/o and other register names/definitions. Is there a .h file where theses are defined?, I haven’t found such a file in my arduino directories.

The address of i in your for (next) doesn’t matter at all.

It most certainly does. It doesn’t matter to me, and it doesn’t matter to you, but the compiler needs to know the address in order to generate the proper code to increment and test the value at that address. To do this, the compiler creates a table of name/address pairs. i is one of the names in the table, just like DDRB is.

I don’t need to know that exact address of i any more than you need to know the exact address of DDRB. Use the name, just like I do.

My reply tp my question:
The I/O port and other register names are defined as follows:

0x20 PINA
0x21 DDRA
0x22 PORTA
0x23 PINB
0x24 DDRB


0x5E SPH
0x5E SPH
etc.

When dedicated I/O instructions IN and OUT are used, one needs to subtract 0x20 from those above. With these instructions only values 0x00-0x3F (PINA-0x20 - SPH -0x20) can be used.
Same applies with instructions SBI, CBI, SBIS and SBIC, except that only addresses 0x00-0x1F can be used.