【发布时间】:2014-03-01 08:53:43
【问题描述】:
我现在开始使用 6502 程序集,但在处理需要处理大于 8 位数字的循环时遇到了问题。
具体来说,我想遍历一些内存位置。在伪 c 代码中,我想这样做:
// Address is a pointer to memory
int* address = 0x44AD;
for(x = 0; x < 21; x++){
// Move pointer forward 40 bytes
address += 0x28;
// Set memory location to 0x01
&address = 0x01;
}
所以从地址$44AD开始,我想将$01写入ram,然后向前跳转$28,写入$01,然后再次向前跳转$28,直到我完成了20次(最后写的地址是$47A5)。
我目前的方法是循环展开,这写起来很乏味(尽管我猜汇编器可以让它变得更简单):
ldy #$01
// Start from $44AD for the first row,
// then increase by $28 (40 dec) for the next 20
sty $44AD
sty $44D5
sty $44FD
[...snipped..]
sty $477D
sty $47A5
我知道绝对寻址(使用累加器而不是 Y 寄存器 - sta $44AD, x),但这只能给我一个 0 到 255 之间的数字。我真正想要的是这样的:
lda #$01
ldx #$14 // 20 Dec
loop: sta $44AD, x * $28
dex
bne loop
基本上,从最高地址开始,然后向下循环。问题是 $14 * $28 = $320 或 800 dec,这比我在 8 位 X 寄存器中实际存储的要多。
有没有优雅的方法来做到这一点?
【问题讨论】: