Sample code in Z80,6502 and its equivalent from 68K:
I need help with 68K indexed (indirect) addressing.
Could someone help how to better / otherwise execute the code from the Z80 / 6502 but that it would work identically in 68K (as an example).
It is impossible to perform MOVE.W (A0, D0), D1, i.e. to read the address indexed by D0 to D1 in this way.
Code: Select all
variable0 = $C000
variable1 = $C001
variable2 = $C002
variable3 = $C003
variable4 = $C004
variable5 = $C005
variable6 = $C006
variable7 = $C007
Code: Select all
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 6502:
ldx $07
stx variable_index
-------------
ldx variable_index ; $07
lda variable0,x ; load the value of variable0 into the accumulator indexed by the value x (i.e. variable7 will be read into A).
ora %10000000 ; do an ora on bit7.
sta variable0,x ; write the result to variable0 indexed by x (i.e. again to variable7)
Code: Select all
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Z80:
ld a,$07
ld (variable_index),a
---------------
ld hl,variable0 ; load the address at which the variable0 is located in the memory.
ld d,0
ld a,(variable_index)
ld e,a
add hl,de ; add the contents of the index to the address.
ld a,(hl) ; read the content from the address written in HL
or %10000000 ; do an ora on bit7.
ld (hl),a ; write the contents of D0 to the address stored in HL.
Code: Select all
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 68K:
move.w $07,variable_index
move.w variable_index,d0
---------------
lea variable0,a0 ; load the address at which the variable0 is located in the memory.
add.w d0,a0 ; add the contents of the index to the address.
move.b (a0),d0 ; read the content from the address written in A0.
ori.b %10000000,d0 ; do an ora on bit7.
move.b d0,(a0) ; write the contents of D0 to the address stored in A0.
or..
lea variable0,a0 ; load the address at which the variable0 is located in the memory.
add.w d0,a0 ; add the contents of the index to the address.
ori.b %10000000,(a0) ; do an ora on bit7 at contents of A0.