registers of atmega

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

a very basic question
wen i use certain variables in my c code for atmega,
will the first 32 variable values get stored in the general purpose registers?
Or is there any special way to declare a variable ,so that it gets stored in register?

Quote:
As shown in Figure 4, each register is also assigned a data memory address, mapping them
directly into the first 32 locations of the user Data Space. Although not being physically implemented
as SRAM locations, this memory organization provides great flexibility in access of the
registers, as the X-, Y-, and Z-pointer Registers can be set to index any register in the file.

i got this from the datasheet for mega16.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can use the 'register' keyword to suggest that the compiler keep the variable in a register, but it will ignore you if it wants.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You didn't tell us which compiler you use. If it is avr-gcc, read the avr-libc FAQ. Especially http://www.nongnu.org/avr-libc/u...

Stealing Proteus doesn't make you an engineer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
will the first 32 variable values get stored in the general purpose registers?
Or is there any special way to declare a variable ,so that it gets stored in register?

Any particular reason that you are concerned about this? The whole point of C is to remove the need to know such things. Let the compiler do the work.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also note that if you want certain variables to reside in registers, only a small subset are actually available for this, you certainly cannot use all 32. The C compiler requires a certain subset of the variables to create the environment that allows your program to operate.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thank you guys.i was thinking that i should put the loop counters in the register. :o

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Vicky, you don't need to put the loop counters in a register. C compilers are quite good at doing this themselves and in fact sometimes produce more efficient code than would be generated by forcing the compiler to put the loop countere in a register.