Address of variables

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

Address of variables

Post by Osta »

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

mnfisher
Valued Contributor
Posts: 375
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 40 times
Been thanked: 206 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: 52
Joined: Thu Dec 10, 2020 1:12 pm
Has thanked: 1 time
Been thanked: 3 times

Re: Address of variables

Post by Osta »

Thanks Martin!
Got it.
Regards Osta.

medelec35
Matrix Staff
Posts: 682
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 229 times
Been thanked: 241 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 742 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: 52
Joined: Thu Dec 10, 2020 1:12 pm
Has thanked: 1 time
Been thanked: 3 times

Re: Address of variables

Post by Osta »

Thank you so much!!!!

Post Reply