Indirect adressing

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Indirect adressing

#1 Post by Patou » 14 Mar 2021, 21:19

Hello,
I should like to include in the rules the possibility of indirect adressing. This should be used to read a small table for example 10 values stored in var#1 to var#10
The index could be stored in var#11 and the result in var#12 with following formula : Let,12,[var#[var#11]]

Code: Select all

// Table
On system#boot do
Let,1,16
Let,2,20
let,3,46
let,4,64
let,5,88
... 
endon

// Var#11 is the index of the table
// Var#12 is the output of the table value 

Let,12,[var#[var#11]]
It seems that actually the rules cannot handle this
Is it a big work to include this possibility ?
Patou

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Indirect adressing

#2 Post by Ath » 14 Mar 2021, 21:54

Have you tried to use Let,12,[var#%v11%] ?
/Ton (PayPal.me)

Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Re: Indirect adressing

#3 Post by Patou » 15 Mar 2021, 10:24

Hello Ath,
Thanks for your reply
On the latest firmware ESP_Easy_mega_20210223_normal_ESP8266_4M1M
This is working Thanks
Can you please explain what is the difference between [var#1] and %v1% ?
It should be nice to have in the doc an example of indirect adressing
Have a nice day
Patou

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Indirect adressing

#4 Post by TD-er » 15 Mar 2021, 10:28

The %-notation is replaced first when parsing a rules line.
So this makes indirect addressing possible since lines are not parsed over-and-over again until nothing is left to replace (or nothing changes)

Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Re: Indirect adressing

#5 Post by Patou » 15 Mar 2021, 10:36

Thanks I can continue my project on this base

Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Re: Indirect adressing

#6 Post by Patou » 15 Mar 2021, 12:43

Sorry .. one more question what is really the limit of the number of variables ?
Can I make a table with 20 lines ( 20 variables) an still have 10 variables free = 30 in total ?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Indirect adressing

#7 Post by TD-er » 15 Mar 2021, 12:45

In recent builds the limit has been removed. (max index = 2^32 - 1, index 0 is also not allowed)
Just keep in mind that each variable does take roughly 16 bytes of memory, so you will eventually run into memory issues if you start using 100's of variables :)

Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Re: Indirect adressing

#8 Post by Patou » 15 Mar 2021, 13:13

ok thanks so 30 varaibles should not go to the memory limit

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Indirect adressing

#9 Post by TD-er » 15 Mar 2021, 13:16

nope, that's ok

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 28 guests