Help with understanding M68HC11 arrays

Thread Starter

bluesilver89

Joined Mar 28, 2010
1
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!

Rich (BB code):
RAM       EQU       0
EEPROM  EQU       $F800                        
array      FCB       7, 24, 9, -12, 63, 87     * array of 6 constants
asize      EQU       6                    * space reserved for array
total      RMB       1                    * total variable for 3rd loop
 
            ORG       RAM
dst        RMB       asize               * space for destination array
 
            ORG       EEPROM
src        FCC       array
            FCB       0                     * terminate array with null
 
start       LDAB     #asize              * load asize in accumulator B
            LDX       #src                 * load EEPROM in x register
            LDY       #dst                * load RAM in y register
loop       LDAA      0,x                  * load first element of array in x
            STAA     0,y                  * store that element in destination
            BEQ       loop2               * if null, loop to 2nd loop
            INX                              * increment x
            INY                              * increment y
 
            DECB                            * decrement 1 from B
            BNE       loop                 * if asize != 0, branch to loop
 
* 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. 
 
loop2      LDAA     array[1]
            LDAB     array[0]
            SBA 
            STAA    array[1]
loop3      LDAA    array[0]
            LDAB     array[1]
            ABA 
            STAA    total
 
done
 
JMP      END      JMP
 

RiJoRI

Joined Aug 15, 2007
536
Consider using pointers in loop2 as you did in loop1. Or even one pointer:
Rich (BB code):
  ldaa   ,x
  inx
  adda  ,x
  staa   ,x
  inx
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:
Rich (BB code):
  ldx  #00
loop:
  ldaa  array,x
  inx
  adda  array,x
  staa   array,x
  inx
  cpx    DST
  bne    loop
Question: Did the teacher mention what to do when you have an overflow/underflow? E.g., $80 + $82 = $02 (with the Carry bit set). If not, don't worry about it. You'll get to it pretty soon.

--Rich
 
Top