I need to create an array after my code.
For example my code is
LDA $EF
then I would need to have an array there that contains let's say 2 hex code.
E4 20
However, I have 2 problems:
1-) I would need to be able to give a label to this table so I can use it.
For example:
LDA $EF
array1:
E4 20
LDA array1,Y
2-) The other problem is that the array would need to be after it is used, like this
LDA array1,1
array1:
E4 20
Is there a way to do this?
How to create an array with ASM6?
Moderator: Moderators
Re: How to create an array with ASM6?
In ASM, an array is just an alias to the address of its first element, just like any other variable, so you have to be careful to not declare any other variables before the end of the array, or the overlap will result in buggy code.
To access arrays of length 256 or less, you can use one of the index registers:
If the index is known at assembly time, you can avoid using the index register and add the constant offset to the base address at assembly time:
To access arrays of length 256 or less, you can use one of the index registers:
Code: Select all
;load the third byte of the array
ldx #$02
lda MyArray, x
Code: Select all
;load the 5th element of the array
lda MyArray+4
Re: How to create an array with ASM6?
Arrays larger than 256 elements have to be accessed with indirect addressing. This means that the address of the array is stored in RAM (in Zero Page, to be precise), and can be manipulated to point any other part of the array, not just the beginning.
Code: Select all
;declare array in RAM
MyArray = $0400
;declare pointer in ZP
ArrayPointer = $007B
;initialize the pointer
lda #<MyArray
sta ArrayPointer+0
lda #>MyArray
sta ArrayPointer+1
;fill 768 bytes (256 *3) with 0
lda #$00
ldx #$03
ldy #$00
Loop:
sta (ArrayPointer), y
iny
bne Loop
inc ArrayPointer+1 ;after 256 bytes, move the pointer 256 positions ahead
dex
bne Loop
Re: How to create an array with ASM6?
thanks again!!