# Help with understanding M68HC11 arrays

Discussion in 'Homework Help' started by bluesilver89, Mar 28, 2010.

1. ### bluesilver89 Thread Starter New Member

Mar 28, 2010
1
0
Hello! I'm new here, but I was hoping to get some help understanding how to use arrays in the 68HC11 programming language. I have already completed a beginners Java course, so I understand the concept of an array. However, I do not understand how to manipulate them in an HC11 program.

My homework assignment is to write an HC11 program that will initialize and manipulate an array, then write a series of 3 loop. The 1st copies an array of constants from EEPROM to RAM (which I attempted in the example below), the 2nd loop involves subtracting the first array element from the second, and then storing the result in the second (a[1] = a[1] - a[0]), and repeat for all the elements except for the assignments themselves (so no a[2] = a[2] - a[1], because a[1] is already being used as an assignment). It is assumed that the array contains an even number of elements. The 3rd loop sums the entire array into a single total and stores it into a variable. Each loop should be within the same program, but seperate from each other.

I was able to somewhat figure out the first loop, but I am unsure how to manipulate the array from there. I learn best from seeing examples, so would it be possible for someone to show me a basic HC11 program that does something with an array (it doesn't have to be based on my homework, I just need to see an example on how to use arrays). Also, if anyone notices any problems with my posted program, can you point them out to me please? I would definately appreciate any help! Thank you for your time!

Code ( (Unknown Language)):
1.
2. RAM       EQU       0
3. EEPROM  EQU       \$F800
4. array      FCB       7, 24, 9, -12, 63, 87     * array of 6 constants
5. asize      EQU       6                    * space reserved for array
6. total      RMB       1                    * total variable for 3rd loop
7.
8.             ORG       RAM
9. dst        RMB       asize               * space for destination array
10.
11.             ORG       EEPROM
12. src        FCC       array
13.             FCB       0                     * terminate array with null
14.
15. start       LDAB     #asize              * load asize in accumulator B
16.             LDX       #src                 * load EEPROM in x register
17.             LDY       #dst                * load RAM in y register
18. loop       LDAA      0,x                  * load first element of array in x
19.             STAA     0,y                  * store that element in destination
20.             BEQ       loop2               * if null, loop to 2nd loop
21.             INX                              * increment x
22.             INY                              * increment y
23.
24.             DECB                            * decrement 1 from B
25.             BNE       loop                 * if asize != 0, branch to loop
26.
27. * all this below is my incomplete attempt to manipulate the array for the 2nd and 3rd loops but I don't think I'm doing it correctly. I think I might have to use the 0,x, 1,x etc, but I'm not sure.
28.
29. loop2      LDAA     array[1]
30.             LDAB     array[0]
31.             SBA
32.             STAA    array[1]
33. loop3      LDAA    array[0]
34.             LDAB     array[1]
35.             ABA
36.             STAA    total
37.
38. done
39.
40. JMP      END      JMP
41.
42.
43.

2. ### RiJoRI Well-Known Member

Aug 15, 2007
536
26
Consider using pointers in loop2 as you did in loop1. Or even one pointer:
Code ( (Unknown Language)):
1.
2.   ldaa   ,x
3.   inx
5.   staa   ,x
6.   inx
7.
Please note that I am familiar with the 6809, not the 6811. There may be features the '09 had that the '11 doesn't, and vice-versa.

Another method:
Code ( (Unknown Language)):
1.
2.   ldx  #00
3. loop:
4.   ldaa  array,x
5.   inx