NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Assemble resistor notation

April 30, 2010
by Ralphxyz
Ralphxyz's Avatar

I see in Assemble code samples (which I do not know the language by the way) that registers are referenced as r16 or the like.

Can registers be addressed in C as r16 or the like?

Is there a listing of the registers with their reference numbers somewhere?

Ralph

April 30, 2010
by bretm
bretm's Avatar

The datasheet explains the registers in the section called "General Purpose Register File". There are 32 registers named r0 through r31.

The easiest way to use them from C is to pretend they don't exist and let the compiler take care of it for you. The compiler turns C instructions into assembler instructions and makes its own decisions about which registers to use for a given purpose. So even if you could use them directly from C you wouldn't want to because you might conflict with the compiler's use of the registers.

But if you really want to play with them you can take advantage of the fact that they're mapped to memory addresses 0 to 31. I haven't tried it, but you should be able to do something along the lines of

#define R0 _MMIO_BYTE(0)
#define R1 _MMIO_BYTE(1)
// etc.

But this is almost guaranteed to fail in many cases, especially if used in complex expressions for which the compiler might utilitize many registers to keep track of intermediate values.

April 30, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Ralph,

Like bretm said if you are writing in C you pretty much never want to explicitly put things into registers, as the complier is going to handle that for you. There is a register keyword that you can add to a variable declaration:

register uint8_t my_variable;

this will suggest to the compiler that it keep a variable in a register instead of holding it on the stack. However it is only a suggestion, and the compiler was probably already doing the right thing anyway.

Humberto

May 01, 2010
by Ralphxyz
Ralphxyz's Avatar

Great answers, thank you so much. Ralph

Post a Reply

Please log in to post a reply.

Did you know that an analog comparator can tell when one voltage input crosses another? Learn more...