I am new to IAR and Embedded Programming. I was debugging the following C code, and found that R0
gets to hold the address of counter1
through ??main_0
, while R1
gets to hold address of counter2
through [PC,#0x20]
. This is completely understandable, but I cannot get why it was assigned to R0
to use LDR Rd, -label
while R1
used LDR Rd, [PC+Offset]
and what is the difference between the two approaches?
I only knew about literal pools after searching but It didn't answer my question. In addition, where did ??main_0
get defined in the first place?
int counter1=1;
int counter2=1;
int main()
{
int *ptr;
int *ptr2;
ptr=&counter1;
ptr2=&counter2;
++(*ptr);
++(*ptr2);
++counter2;
return 0;
}