; test parameters are ; A (00..ff) ; C (00..01) ; X (00..ff) ; K (X..ff) ; routine requires that X+(0xff-K)<= 0xff, ie X<=K ; ; result should be A+C+K+255*X ;----------------------------- ; calculate reference value ;----------------------------- lda tC lsr lda tA adc tK sta ref+0 lda tX adc#0 sta ref+1 ; ref is now A+C+K+256*X sec lda ref+0 sbc tX sta ref+0 lda ref+1 sbc#0 sta ref+1 ; ref is now A+C+K+255*X ;----------------------------- ; prepare registers for test ;----------------------------- lda tK eor#$ff sta rn+1 lda tC lsr lda tA ldx tX ;----------------------------- ; run test code ;----------------------------- rn sbc id+$3f,x sta res+0 txa adc#0 sta res+1 ;----------------------------- ; compare result to reference value ;----------------------------- lda res+0 cmp ref+0 bne fail lda res+1 cmp ref+1 bne fail
adc #V bcc *+3 inx
C'=0 X'=X A'=A+V+C =(T-C-255*X)+V+C =T+V-255*X T'=A'+C'+255*X' =(T+V-255*X)+0+255*X =T+V
C'=1 X'=X+1 # as the increment happens A'=A+V+C-256 # as the add has overflowed into C =(T-C-255*X)+V+C-256 =T+V-255*X-256 T'=A'+C'+255*X' =(T+V-255*X-256)+1+255*(X+1) = T+V-255*X-255+255*X+255 = T+V
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