I am new to assembly and microcontrollers and am trying to figure out how they work.
Now, I have read a lot how in assembly
data segments are for storing program code and initial data for it.
Everywhere people say[1,2,3] (if they say something)
data segment stores values preinitialized for the program.
But in AVR, as I understand,
And to have it initialized you need to instruct your microcontroller to put some actual values there.
Only having instructions under
.dseg somewhere in your code does not magically put values into
SRAM. The microcontroller has to reach the initializing instructions by its pace, following the program as usual: starts at
0x0 of the
program segment, which is
flash in AVR, and follows the instructions.
For instance, in this question the guy examines the code, produced by
C, and finds the routines initializing
flash, i.e. the
program segment of the code.
If it is so, then what is the purpose of having
Maybe it is for different assemlers or other tools (like
avr-gcc in the referenced question, or avrstudio in the link 1), which would add necessary initialization instructions when processing the code with
But if you work with "bare bones" the microcontroller starts from
0x0 (or somewhere else, according to the datasheet), this is where your program starts and there is nothing more to it, is there? (Of course, you put a vector table there for the interupts, if you want to handle them. And
0x0 is the address where
RESET brings the microcontroller to. But it is not essential.)
cseg could imply different address spaces: when you write an address in
.dseg it is for
.cseg -- for
But it seams addressing depends solely on instruction definition:
ADD a1, a2 --
a# are registers,
RJMP a --
SRAM is accessed indirectly via registers --
LDS R1, 0x0060.
Here again, can it be so, that the code under
.dseg label like in 1:
.DSEG ; Start data segment var1: .BYTE 1 ; reserve 1 byte to var1
substitutes the indirect access to
SRAM via registers?
Probably this information should be searched within the documentation for the particular assembler at hand? Again, "bare bone" AVR instruction set doesn't provide any of such?