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!
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