A C X r1 r0 ldx #0 00 sec 1 lda #ff ff adc #2 02 1 bcc s1 inx 01 adc #ff 02 1 bcc s2 inx 02 stx r1 02 sbc r1 00 1 sta r0 00 txa 02 sbc #0 02 1 sta r1 02 A C X r1 r0 ldx #0 00 sec 1 lda #ff ff adc #1 01 1 bcc s1 inx 01 adc #ff 01 1 bcc s2 inx 02 stx r1 02 sbc r1 ff 0 sta r0 ff txa 02 sbc #0 01 1 sta r1 01
s2 sbc id,x sta r0 ;column 2 txa sbc #0;correction to high byte ldx #0 adc n1h;add high bytes
stx r1 sbc r1 with sbc id,x
ldx #0 a) sec ; initialise T to 1 lda n1 ; now T is A+C+255*X = n1+1+255*0 = n1+1 adc n2 bcc *+3 inx ; now T is 1+n1+n2, cf proof in comment about the adc:bcc:inx sequence earlier in this thread adc n3 bcc *+3 inx ; now T is 1+n1+n2+n3 ; so all that's required now is adding A+C+255*X-1 and storing them b) sbc id,x ; now sbc nn is the same as adc $ff-nn, so here we are adding $ff and subtracting X sta r0 txa c) sbc #0 ; again, equivalent to adc $ff-0, so here we are adding x, $ff, and any carry from the low byte sta r1 ; ie, adding 256*X and $ff00 to the total in r1:r0
lax eorval+1 ldy #$00 val1: axs #$00 val2: axs #$00 bcs val3 iny val3: axs #$00 bcs val4 iny val4: axs #$00 bcs storehi iny storehi: sty r1 txa eorval: eor #$ff sta r0