[英]How to multiply with add and shift algorithm in 6502 when the multiplicand is in the accumulator?
So I'm trying to multiply by using add and shift.所以我试图通过使用 add 和 shift 来进行乘法运算。 I want to store the multiplicand in the accumulator and the multiplicand in the X-register.
我想将被乘数存储在累加器中,将被乘数存储在 X 寄存器中。 I genuinely don't know why my code isn't working but I suspect its because of the multiplicand being in the accumulator and putting the product in a separate register.
我真的不知道为什么我的代码不起作用,但我怀疑这是因为被乘数在累加器中并将产品放在单独的寄存器中。
Here is my code so far:到目前为止,这是我的代码:
LDA #49
LDX #8
LDY #$8
STA $700
STX $704
loop: ; if 1
BCC loop2 ; if 0, go to loop2
CLC ; clear carry for adc
ADC $700 ; adc
loop2: ; if 0
ROL $700 ; left shift
CLC
ROR $704
DEY
BNE loop ; if not 0, go to loop
STA $700 ; store A in product register
Thank you for your help谢谢您的帮助
This is the corrected version.这是修正版。 Check double semicolon for the changes.
检查双分号以了解更改。 Biggest mistake was to forget resetting accumulator and carry flag before the first loop.
最大的错误是在第一次循环之前忘记重置累加器和进位标志。
LDA #49
LDX #8
LDY #9 ;; you need to increase your loop by 1
STA $700
STX $704
LDA #$00 ;; you need to reset acc
CLC ;; and clear carry
loop: ; if 1
BCC loop2 ; if 0, go to loop2
CLC ; clear carry for adc
ADC $700 ; adc
loop2: ; if 0
;ROL $700 ;; these three lines
;CLC ;; are replaced with
;ROR $704 ;; the two lines below
ROR ;; this is
ROR $704 ;; faster
DEY
BNE loop ; if not 0, go to loop
STA $700 ; store A in product register
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.