Memory Array Pointer to Long
sobakava
Posts: 34
I've tables located in the memory and it is defined like this:
I am accesing this data in this way:
but I want to use another table instead of the first one. I thought I can use a pointer (long) and use it like this:
But it seems this approach does not work. I read incorrect data from memory.
What is the most convenient way to do this? I don't want to replicate blabla calculations using if conditions for each table because it requires a lot of memory space.
Thanks!
my_table1 byte $10 , $15
byte $12 , $20
.
.
my_table2 byte $17 , $11
byte $13 , $22
.
.
I am accesing this data in this way:
blabla := my_table1[ 4 ] * my_table1[ 5 ]
but I want to use another table instead of the first one. I thought I can use a pointer (long) and use it like this:
long my_table_pointer
.
.
.
.
if ( table_nr == 1 )
my_table_pointer := my_table1
if ( table_nr == 2 )
my_table_pointer := my_table2
.
.
[code]blabla := my_table_pointer[ 4 ] * my_table_pointer[ 5 ]
But it seems this approach does not work. I read incorrect data from memory.
What is the most convenient way to do this? I don't want to replicate blabla calculations using if conditions for each table because it requires a lot of memory space.
Thanks!
Comments
Will not work.
Are all the tables the same lenght, say 32 bytes?
If so put them after each other.
blabla := my_table1[ 4 + table_nr *32] * my_table1[ 5 + table_nr *32]
Note that when fetching values this way you need to be explicit as to the size of the elements in your table, hence byte[][] was used.
idx1 and idx2 would have values of 0 or 1. The addresses stored in my_table are object offsets, so you need to use the @@ operator to get the absolute address. The object offsets could be converted to absolute address at the beginning of the program so you would not have to use the @@ operator later on. That would look something like this: