我在6502中遇到了另一个问题....
我试图添加两个n字节整数来产生n字节结果。我不完全确定我是否对这个项目能够理解6502芯片,所以对我当前代码的任何反馈都会非常有帮助。
我知道我应该使用INX(递增x寄存器)和DEY(递减y寄存器)但我不确定操作码的位置。
描述: 使用绝对索引寻址添加两个n字节整数
Adding two n-byte integers using absolute indexed addressing
The addends start at memory locations $xxxx, $yyyy, answer is at $zzzz
Byte length of the integers is at $AAAA (¢—>256)
START = $0500
CLC
____
loop LDA $0400, x
ADC $0410, x
STA $0412, x
____
BNE loop
BRK
LDA,ADC和STA在循环之外(第一次在汇编中使用循环)
编辑:
Variables
A1 = $0600
B1 = $0700
B2 = $0800
Z1 = $0900
[START] = $0500
CLC 18
LDX AE
LDY A1 AC
loop: LDA B1, x BD
ADC B2, x 7D
STA Z1, x 9D
INX E8
DEY 88
BNE loop D0
答案 0 :(得分:3)
;Adding two n-byte integers using absolute indexed addressing
;The addends start at memory locations $xxxx, $yyyy, answer is at $zzzz
;Byte length of the integers is at $AAAA (¢—>256)
CLC
LDX #0 ; start at the beginning
LDY $AAAA ; load length into Y
loop: LDA $xxxx, X ; load first operand
ADC $yyyy, x ; add second operand
STA $zzzz, x ; store result
INX ; go on to next byte
DEY ; count how many are left
BNE loop ; if more, do more