a2 a1 a0 b1 b0 + c1 c0 -------- r2 r1 r0 2 clc 3 lda a0 3 adc b0 2 tax;a0+b0 3 lda a1 3 adc b1 2 tay;a1+b1 3 adc a2 3 sta r2 2 txa ;no clc as there's never a carry from r2, in a mult 3 adc c0 3 sta r0 2 tya 3 adc c1 3 sta r1 3 bcc s1;3/7 avg 5 5 inc r2 s1 rts
clc lda n1 adc n2 bcc s1 inx s1 adc n3 bcc s2 inx s2 sta low stx high;or add the next column (the high bytes of n1-n3) with txa:ldx #0
s2 stx high sec sbc high sta low;remove the carries which were added by NOT using CLC
s2 adc #0 stx high sec sbc high sta low
Then I noticed this didn't work in every case, because the first carry doesn't offset the running total, only the 2nd carries forward.
s2 stx hi sbc hi ; this adds 255-x to the current value of A+C sta low ; will now contain <(n1+n2+n3+0xff) lda hi adc#0 sta hi ; will now contain >(n1+n2+n3+0xff)