Address of variables

Post Reply
Osta
Posts: 27
http://meble-kuchenne.info.pl
Joined: Thu Dec 10, 2020 1:12 pm
Has thanked: 1 time
Been thanked: 1 time

Address of variables

Post by Osta »

Hey!
Tell me how to find out the address of the declared variables?
Thanks!

mnfisher
Valued Contributor
Posts: 251
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 30 times
Been thanked: 133 times

Re: Address of variables

Post by mnfisher »

Hi Osta,

You need to use a little bit of C. Since FC doesn't have an address type - use an int large enough to hold the address (so 16bit or 32 bit)

In a C block

Code: Select all

FCL_ADDR = &FCV_VARNAME;
Where addr is defined as a local variable - and varname a global - note that FC capitalises the variable name and adds FCL (local) or FCV (global).

Note that to read or write to the address you'll also need to use some C:

Martin

Osta
Posts: 27
Joined: Thu Dec 10, 2020 1:12 pm
Has thanked: 1 time
Been thanked: 1 time

Re: Address of variables

Post by Osta »

Thanks Martin!
Got it.
Regards Osta.

medelec35
Matrix Staff
Posts: 494
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 154 times
Been thanked: 184 times

Re: Address of variables

Post by medelec35 »

There is an alternative method.
When you compile there are various files created.
For PIC if you look in the .sym file and search (using ctrl F) for your variable, the stored address is shown in hex
The format is _FCV_YOURVARIABLE (for global) or _FCL_YOURVARIABLE (For local).
Stored address.png
Stored address.png (11.9 KiB) Viewed 261 times
Depending on the side of the variable using more than one address could be used.
Both the above are bytes so only one location each is used.
with integers, it will be two, etc.
I'm not sure about AVR.
Martin

Osta
Posts: 27
Joined: Thu Dec 10, 2020 1:12 pm
Has thanked: 1 time
Been thanked: 1 time

Re: Address of variables

Post by Osta »

Thank you so much!!!!

Post Reply