ATtiny13 registers for general use

I'm looking into ATtiny13 register summary, and I've googled quite a bit but failed to learn which registers can I use for passing values etc. For example - is PORTB register, with address 0x18 also called R24?

Looking into compiled code, I see that R24 is used by C++ compiler for passing argument to a function, so I wouldn't say so.

But then, how do you guys know which Rxx to use? How are these rnn mapped to real register addresses? Do they represent only "Reserved" registers? ATtiny13 has 31 of those.

No, they are not the same. All of the registers with names other than rxx are I/O registers, and they should not be used for passing values because they tell the peripherals to do things.

See chapter 5 of the datasheet - it is explained there.

If you're mixing c and assembly, there's a section of the avr-libc docs that has some good information written plainly on which registers you have to treat specially.

In ATtiny13A datasheet, page 10, Figure 4-2 shows that R0 address is 0x00, R1 address is 0x01, R2 address is 0x02 etc. I am still totally confused about which are general purpose registers in ATtiny13. There is no table with each register nicely named R1...R31, PORTB, SPL, DDRB, etc. along with addresses, so I can see which register I can freely use and I want to use it by address, not like Rxx.

Here they say that R24 equals 0x18, could someone please reveal this mystery to me, what are exact addresses of general purpose registers in ATtiny13 I can use for variables? I've edited this image from tiny13 datasheet, is this correct?

What are you trying to do?

This has all the hallmarks of an XY problem

...R

losmi:
Here they say that R24 equals 0x18...

Nope. Whatever that red garbage is it has nothing to do with the ATtiny13A processor.

This is the full datasheet from Microchip...
http://ww1.microchip.com/downloads/en/DeviceDoc/doc8126.pdf

The Register Summary is on page 158 / section 20.

...what are exact addresses of general purpose registers...

The "General Purpose Register File" aka "Register File" starts at SRAM location 0x00.

The "I/O memory" (the image in your post) starts just past the "General Purpose Register File" at SRAM location 0x20.

5.2 SRAM Data Memory on page 15 has more details.

Robin2:
What are you trying to do?

This has all the hallmarks of an XY problem

...R

I am trying to learn which registers I can freely use for passing variables etc. But not that Rxx thing, just simply 0xnn addresses of these registers.

losmi:
I am trying to learn which registers I can freely use for passing variables etc.

That does not tell us anything extra.

WHY do you need to know that? What will the eventual project be?

...R

I want to know because I want to write some sketches in assembly in order to save any space I possibly can save, to fit it into 1024 bytes. I want to call registers by their address, not by some arbitrary names like Rxx. I want to know which registers I am using.

Sorry, I meant on this link they say that R24 == 0x18

Thanx, I know, this exact table is the one I used to insert the red garbage for the purpose of putting it here to ask about Rxx exact addresses.

I already went through section 5, but I still don't know what are addresses of registers R0-R31? How exactly R24 does not equal PORTB?

Sorry for the hassle, but I must be missing something here.

I thought that question is fairly simple: what are addresses of registers R0-R31 in ATtiny13?

Hi,
R24 is decimal of 0x18, 0x18 is a hex value. that is what the x means.

Tom... :slight_smile:

TomGeorge:
Hi,
R24 is decimal of 0x18, 0x18 is a hex value. that is what the x means.

Tom... :slight_smile:

Yeah, I know that, and 0x18 happens to be PORTB register, and DrAzzy upthere said that they are not the same so I am confused. I've found AVR binary opcodes here: Using as: AVR Opcodes and I took a look into my compiled code and found a few random PUSH instructions, to determine register addresses, and this is what I found:


So, the xx number from Rxx really IS register's address, only it is in DEC instead of HEX.

losmi:
... write some sketches in assembly in order to save any space ... call registers by their address ...

Registers are not "called". They are "accessed".

losmi:
I already went through section 5, but I still don't know what are addresses of registers R0-R31?

Told you. Read my post again.

losmi:
How exactly R24 does not equal PORTB?

Told you. Read my post again.

Sorry for the hassle, but I must be missing something here.

Yup. Accessing the general purpose registers through their memory address produces more code. The exact opposite of your stated goal.

I have read your post again.

Image is conspicously titled "Register summary", and addresses start with 0x00 and end with 0x3F.

Now I am confused even more! How does "ldi 0x03, 0x10" produce more code than "ldi r3, 0x10"?

I've come here seeking some help. Namely, what is address of register r0? What is address of register r1? What is address of register r10? What is address of register r20, etc?

Thank you in advance.

losmi:
Now I am confused even more! How does "ldi 0x03, 0x10" produce more code than "ldi r3, 0x10"?

Does the AVR include a move-constant-to-memory instruction?

losmi:
...addresses start with 0x00 and end with 0x3F...

I/O addresses. For which there are I/O machine instructions. Instructions that operate exclusively in the I/O address space.

I/O addresses are mapped to SRAM addresses. Which allow those some locations to be accessed using SRAM machine instructions. But the I/O addresses are not the same as SRAM addresses.

Which is also true for the general purpose registers.

Dude, in AVR registers are addressed just like memory, so it is "move constant to register"

In which case you have everything you need.

I am affraid I'm not following you, I need to try to find some nice tutorial, sorry.