[英]I've never had a need to use the ($nn,x) addressing mode. What's an example of something it's useful for?
I've used ($nn),y
plenty of times, it's pretty much the 6502's bread-and-butter method of iterating through arrays.我已经多次使用
($nn),y
,这几乎是 6502 的基本方法,即迭代 arrays。 But I've never found a use for ($nn,x)
.但我从来没有发现
($nn,x)
的用途。 The only time I've ever thought about using it is when x = 0
.我唯一考虑过使用它的时间是
x = 0
。 It seems like any problem that can be solved with STA ($nn,x)
can just as easily be done with hardcoded pointers like in this example with writing to the Konami VRC6 sound hardware:似乎可以使用
STA ($nn,x)
解决的任何问题都可以使用硬编码指针轻松完成,例如在此示例中写入 Konami VRC6 声音硬件:
LDX #2
loop:
LDA (musicptr),y
STA $9000,x ;pulse 1 channel regs
STA $A000,x ;pulse 2 channel regs
STA $B000,x ;sawtooth channel regs
DEX
BNE loop
Versus:相对:
LDA #$00
STA $10
STA $12
STA $14
LDA #$90
STA $11
LDA #$A0
STA $13
LDA #$B0
STA $15
LDX #$00
loop:
LDA (musicptr),y
STA ($10,x) ;first pass: STA $9000. second pass: STA $A000. third pass: STA $B000
INX
INX
CPX #6
BNE loop
I know that not every tool needs to be used, but I just can't think of a purpose for this addressing mode at all.我知道不是每个工具都需要使用,但我根本想不出这种寻址模式的用途。
Checking out some well-known source code of the era, from a system where the 6502 was used to build an actual OS with hardware abstraction, the BBC MOS uses ($nn,x)
in only two instances:从一个使用 6502 构建具有硬件抽象的实际操作系统的系统中查看一些著名的源代码,BBC MOS 仅在两个实例中使用
($nn,x)
:
So:所以:
Despite your assertion as a comment above:尽管您在上面的评论中断言:
($nn),y
because it has fixed locations; ($nn),y
索引的字节表,因为它有固定的位置; and($nn),y
because it has fixed locations.($nn),y
索引的字节表,因为它有固定的位置。 Since there is no indirect mode without indexing in the original 6502, one use is to set x
to 0 to emulate such a mode.由于在原始 6502 中没有不带索引的间接模式,因此一种用途是将
x
设置为 0 以模拟这种模式。
ldx #0
lda ($zp,x)
Yes you can do it with the y
register and lda ($zp),y
, but maybe y
has got a value in it that you want to keep.是的,您可以使用
y
寄存器和lda ($zp),y
来做到这一点,但也许y
有一个您想要保留的值。
Other than that, I've got nothing.除此之外,我一无所有。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.