implement taking address of array var with variable index

This commit is contained in:
Irmen de Jong 2023-10-14 07:57:36 +02:00
parent 9ea69c07b8
commit 203ec5fa46
3 changed files with 45 additions and 12 deletions

View File

@ -2210,7 +2210,26 @@ internal class AssignmentAsmGen(private val program: PtProgram,
program.memsizer.memorySize(arrayDt!!, constIndex) // add arrayIndexExpr * elementsize to the address of the array variable.
} else {
val eltSize = program.memsizer.memorySize(ArrayToElementTypes.getValue(arrayDt!!))
TODO("address-of array element $sourceName size $eltSize with non-const index at ${target.position}")
assignExpressionToVariable(arrayIndexExpr, "P8ZP_SCRATCH_W1", DataType.UWORD)
when(eltSize) {
1 -> {}
2 -> {
if(arrayDt !in SplitWordArrayTypes)
asmgen.out(" asl P8ZP_SCRATCH_W1 | rol P8ZP_SCRATCH_W1+1")
}
else -> TODO("address-of array element $sourceName size $eltSize with non-const index at ${target.position}")
}
asmgen.out("""
lda #<$sourceName
clc
adc P8ZP_SCRATCH_W1
tax
lda #>$sourceName
adc P8ZP_SCRATCH_W1+1
tay
txa""")
assignRegisterpairWord(target, RegisterOrPair.AY)
return
}
} else 0
@ -2286,9 +2305,9 @@ internal class AssignmentAsmGen(private val program: PtProgram,
if(sourceDt==DataType.UBYTE) {
asmgen.out(" lda $sourceName | sta ${target.asmVarname}")
if(asmgen.isTargetCpu(CpuType.CPU65c02))
asmgen.out(" stz ${target.asmVarname}")
asmgen.out(" stz ${target.asmVarname}+1")
else
asmgen.out(" lda #0 | sta ${target.asmVarname}")
asmgen.out(" lda #0 | sta ${target.asmVarname}+1")
}
else
asmgen.out("""

View File

@ -1,9 +1,8 @@
TODO
====
- fix TODO "address-of array element" in assignAddressOf()
- gfx2: use vera auto in/decrement in the flood fill routine
- add an option to inject an actual instruction (STP on 65c02, BRK on 6502) for breakpoints, instead of only listing them in the vice symbol file.
- [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 ....
- [on branch: ir-less-branch-opcodes] IR: reduce the number of branch instructions such as BEQ, BEQR, etc (gradually), replace with CMP(I) + status branch instruction

View File

@ -3,6 +3,7 @@
main {
sub start() {
ubyte[] b_array = [11,22,33,44]
uword[] w_array = [1111,2222,3333,4444]
uword[] @split split_array = [1111,2222,3333,4444]
ubyte index = 2
@ -13,21 +14,35 @@ main {
uword pstep = w_array[index]
uword psteps = split_array[index]
;; uword @zp ptr = &w_array[index]
txt.print_uw(pstep)
txt.nl()
txt.print_uw(psteps)
txt.nl()
; txt.print_uw(peekw(ptr))
; txt.nl()
w_array[index] += 10
split_array[index] += 10
txt.print_uw(w_array[index])
uword @zp ptr = &w_array[index]
txt.print_uw(peekw(ptr))
txt.nl()
txt.print_uw(split_array[index])
txt.print_uwhex(&w_array, true)
txt.spc()
txt.print_uwhex(ptr, true)
txt.nl()
ptr = &split_array
txt.print_uw(peekw(ptr))
txt.nl()
txt.print_uwhex(&w_array, true)
txt.spc()
txt.print_uwhex(ptr, true)
txt.nl()
ptr = &b_array[index]
txt.print_ub(peek(ptr))
txt.nl()
txt.print_uwhex(&b_array, true)
txt.spc()
txt.print_uwhex(ptr, true)
txt.nl()
}
}