You have to do the index calculation yourself. An array, no matter whether single or multi-dimensional still 'physically' exists as a flat list in memory. For example, an int typically needs two bytes in an 8-bit PIC so each int you store needs two memory locations. Your array of 10 ints needs 20 memory locations and each indexed number will be at (2 * index) + address of the array. So to do it in your code, substitute your variable for the index number and do the calculation to find the address the variable is stored. It will occupy that address and the one after it.
As others have said, you need to understand the instruction set of the PIC you are using. The assembler can do the arithmetic for '_numbers + 2' for you and generate the correct binary code. However it can't do the "_numbers + index" as the instruction set simply does not have a suitable single instruction.
Write the code in C, compile it and look at the assembler that it generates and then use that.
(Of course this begs the question why not just do this in C.)
Susan
In another post you suggested I do this in C. As I stated then "I have written this program in MicroC and MicroBasic while teaching my grandson about coding."
I have most of it working in assembly but am stuck at this point.
I looked around my folder and read what I could on line but can't figure out how to find the assembly code created by the assembler.
All you have to do is add 'index' and the _numbers together with assembler instructions. Looking at the listing from a high level language should help but might for operational reasons include other code that you don't need.
The bottom line is that as already explained, there is no single instruction that fetches two values from different memory addresses and adds them together, you have to break it into single steps.
movf index,w
addwf _numbers,f
will leave _numbers holding the total of the two. In your example that should work but be careful if the result exceeds 0xFF, as you will exceed 8-bits as the result and have to 'carry' to the next address.
If assembler, then the instruction set is your - and your grandson´s - reference.
In assembler each assembler_instruction exactly refers to one machine_instruction.
So you can only use instruction that the microcontroller understands.
Assembler depends on the microcontroller you use, every microcontroller provides different assmbler (machine) instructions. If you write an assembler code for one microcontroller you usually can not use the same code for a different microcontroller.
In opposite at C:
Each C instruction becomes compiled, resulting in multiple machine instructions.
C is a machine_independent language. Thus (ideally) you may use the same C code for different microcontrollers.
But the C code needs to be compiled for the according microcontroller, resulting in different code for different microcontrollers.
Because of this, I recommend to start teaching your grandson with one language only, either C or ASM.
It´s too much confusing, because they are different coding concepts.
Combine them later - when necessary.
eadboard,
A little reading of indirect addressing for a pic18 led me to the solution.
Using FSR and INDF it's just pointer math.
LFSR 0, _numbers // Set FSR0 pointing to the top of _numbers
movf INDF0,0,0 // get the first value from _numbers
To get the next value all I have to do is:
incr FSRO,1,0 // using the arguments avoids a compiler warning
incr FSRO,1,0 // using the arguments avoids a compiler warning
movf INDF0,0,0 // get the next value from _numbers
Thanks for all the replies.
I'm sure I'll be back with more questions.
jerryd