如果这个问题看起来“太基本”,我很抱歉。我是一个68K的ASM编码器,但是一个朋友让我看一眼6502的代码。我们有一个指向数据字符串的指针:
my_ptr ds 2这个指针是用以下代码设置的:
ldx sound_channel_busy
bne .abc_set_score1 ; at bottom of code
sta my_ptr ; fill the pointer读取数据的操作已完成
lda (my_ptr),y ; my_ptr + offset但正如我在6502文档中看到的,y是一个字节。因此,使用超过255字节的数据字符串是不可能的(我们希望读取10.000字节或更多的字符串。我建议我的朋友这样做:
1)将一个指针设置为"base“,并设置一个临时指针,我们将在读取时将其合并
my_ptr ds 2
my_ptr_tmp ds 22)初始化:
ldx sound_channel_busy
bne .abc_set_score1
sta my_ptr
sta my_ptr_tmp ; Duplicate3)然后使用:
lda (my_ptr_tmp) ; Read to acumulator
inc my_ptr_tmp ; One more on adress pointer但是它不工作,因为我的朋友是一个C开发人员,我们没有调试器……这可不容易。在68K中,这似乎是合理的,但在6502中呢?
非常感谢你的帮助
发布于 2017-10-11 20:52:57
6502是相当有限的。
(zp),y和(zp,x),其中zp是一个零页地址。前者将地址计算为contentOf(zp + (zp + 1) << 8) +y
并使用其中的字节作为操作数。后者将地址计算为
contentOf ( zp +x+( zp +x+ 1) << 8) (zp+x+(zp+x+1)zp+x+1)
Y形式用于访问零页指针所指向的数组的元素,x形式用于访问零页存储器中的矢量表。
要设置指针,请执行以下操作:
lda #<pointer ; The low byte of the 16 bit address pointer is loaded into A
sta my_ptr
lda #>pointer ; the high byte of the pointer
sta my_ptr+1
ldy #0 ; zero the y register访问指针
loopStart:
lda (my_ptr),y假设C样式的字符串带有空终止符
beq loopExit ; previous LDA sets the S and Z flags.递增指针
iny ; Increment y
bne loopStart
inc my_ptr+1
jmp loopStart您也可以保持Y为0并递增低字节和两个零页位置,但是INC my_ptr比INY慢得多,需要5个周期而不是2个周期。
编辑
如果你有一个长度,而不是一个以null结尾的字符串,你需要稍微修改一下。一种方法是计算你做了多少字节,并与长度进行比较。对于上面的算法,Y是计数,如果长度< 256,那么我们可以做的是将计数的高字节存储在
; first set up my_ptr, same as before.
;
lda #<pointer ; The low byte of the 16 bit address pointer is loaded into A
sta my_ptr
lda #>pointer ; the high byte of the pointer
sta my_ptr+1
;
; Set up the counter
;
ldx #0 ; set up x for the count
ldy #0 ; Set up y for the count/loop
;
; A common trick with compiling while loops is to put the test at the end of the loop and jump to it immediately.
; This means you don't have to reverse the logic of the loop condition.
;
jmp loopTest ; Omit this if you definitely need to go round the loop at least once
loopStart:
lda (my_ptr),y ; Get the byte
;
; Do what you need to do here
;
; Increment the counter
;
iny ; Increment y
bne loopTest
inx
inc my_ptr+1
loopTest:
cpy length ; Compare the low byte of length to the count
bne loopStart
cpx length+1 ; Compare the high byte of length to the count
bne loopStart发布于 2017-10-11 08:52:08
6502是8位数据,16位地址,所以你的指针需要是2个字节,通常在第0页。
lda #<addr ;low byte
sta my_ptr
sta my_ptr_tmp
lda #>addr ;high byte
sta my_ptr+1
sta my_ptr_tmp+1Inc.还需要为16位:
inc my_ptr_tmp
bne :skip
inc my_ptr_tmp+1 ;only inc high byte if low byte is zero
:skip此外,请注意,不带X或Y的lda (zp)仅在65C02上可用。
https://stackoverflow.com/questions/46673778
复制相似问题