I have two arrays and I want to copy the contents of one array into the other.
The destination array is bigger than the source array.
The copy process has finished if the value $FF is found in the source array.
We declare a separate variable to save how many useful values are in the destination array now.
This is my code so far:
Alright, so far, so good.
Now my problem:
This code uses three global variables. But what do I have to do, so that the function works with any arrays and any length variable?
I.e. how can I pass "parameters" to the function, so that the function works like this:
The destination array is bigger than the source array.
The copy process has finished if the value $FF is found in the source array.
We declare a separate variable to save how many useful values are in the destination array now.
This is my code so far:
Code:
.segment "BSS"
SourceArray: .res 10
DestinationArray: .res 20
DestinationArrayLength: .res 1
.segment "CODE"
CopyArray:
; Array index counter
LDX #$00
@loop:
; Load next value
LDA SourceArray, X
; Stop if value is $FF
CMP #$FF
BEQ @end
; Otherwise, copy the value
STA DestinationArray, X
; Increment counter and repeat loop
INX
JMP @loop
@end:
; Save counter as new length variable
STX DestinationArrayLength
RTS
SourceArray: .res 10
DestinationArray: .res 20
DestinationArrayLength: .res 1
.segment "CODE"
CopyArray:
; Array index counter
LDX #$00
@loop:
; Load next value
LDA SourceArray, X
; Stop if value is $FF
CMP #$FF
BEQ @end
; Otherwise, copy the value
STA DestinationArray, X
; Increment counter and repeat loop
INX
JMP @loop
@end:
; Save counter as new length variable
STX DestinationArrayLength
RTS
Alright, so far, so good.
Now my problem:
This code uses three global variables. But what do I have to do, so that the function works with any arrays and any length variable?
I.e. how can I pass "parameters" to the function, so that the function works like this:
Code:
void CopyArray(unsigned char *sourceArray, unsigned char *destinationArray, unsigned char &destinationArrayLength);