这里有一个问题,因为寄存器只有8位,所以我不能存储一个16位地址,所以我必须将它分成两个字节:
%4300将被划分为小终端
高字节: 43
低字节: 00
问题是,我不能增加地址的高字节,而只能使用简单的INC指令增加低字节。
例如:
LDA $4300
ADC #01
STA %4300编辑:
我想增加$4300的内存地址,但是我只想增加前两个字节,所以高字节,我不想为这个地址写一个值
示例:
LDA #$4300
ADC #1
; the result i want should be $4400 and so on..我该怎么解决呢?
谢谢!
发布于 2018-10-30 20:52:45
如果您想要增加或更改地址或任何数据的值,那么您需要知道该地址的地址。
乍一看,这听起来可能有点混乱,但请记住,CPU正在处理的所有内容要么在内存空间中,要么在寄存器中。
这包括编译器输出的每条指令和值。因此,要增加地址的高字节($4300),您必须知道数据的实际位置。
还有一件事要知道,6502是“小端”,所以指令首先读取低字节,然后读取高字节。因此,在内存中,您的地址$4300实际上是一个$00,后面是一个$43。
现在,有许多不同的方法来完成您的目标,但是下面是一个简单的例子:
cool_address: .res 2 ; We reserve 2 bytes somewhere in RAM
; and give it the label cool_address
; so we can easily access it.
...
LDA #$00 ; Put $00 into the Accumulator
STA cool_address ; Store the Accumulator in the 1st byte of address
LDA #$43 ; Put $43 into the Accumulator
STA cool_address+1 ; Store the Accumulator in the 2nd byte of address
; At this point, the 2 bytes at cool_address are
; 00 43
INC cool_address+1 ; Increment 2nd byte of address
; At this point, the 2 bytes at cool_address are
; 00 44标签cool_address现在可以提供给任何接受地址的指令,指令将在address $4400上操作。
https://stackoverflow.com/questions/53026711
复制相似问题