我想添加两个已存储的值 x 和 y,但我只想使用 1 寻址模式。
以下是示例:
lda x
sta x
// store the final result in x
lda y
sta y
// store the final result in y
//now I want to add x and y like x+y. Is the following pattern correct? whats wrong?
lda x
lda y
add x
sta x
最佳答案
Is the following pattern correct? whats wrong?
没有。
- 加法始终通过累加器完成。
- 没有
ADD
指令,只有ADC
带进位相加 - 您需要管理进位标志。
如果您有两个内存位置 x 和 y,并且希望将结果存储在 x 中,则规范的方法是:
; x = x + y
LDA x ; Load one operand into the accumulator.
CLC ; Clear the carry flag so it does not get added into the result
ADC y ; Add the other operand
STA x ; Store the operand back to x
您可以对 y 使用任何地址模式,对 x 使用除立即数之外的任何地址模式。
如果 x 和 y 是 16 位值的地址,则 16 位加法将如下所示:
LDA x ; Load one operand into the accumulator.
CLC ; Clear the carry flag so it does not get added into the result
ADC y ; Add the other operand
STA x ; Store the operand back to x
LDA x+1 ; Now do the high byte
ADC y+1 ; Note we do not clear the carry this time.
STA x+1
关于assembly - 如何使用 1 寻址模式通过在汇编中加载来添加两个存储值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47208154/