Counting, incrementing, decrementing ==================================== This will count up from any value and end at zero: CMP #1 :\ Carry set if A>0 ADC #0 :\ If A>0, A=A+1; if A=0, A=A+0 This code will count down from any value and ends at &FF: CMP #&FF :\ Carry set if A=&FF SBC #0 :\ If A<&FF, A=A-1; if A=&FF, A=A-0 Comparing various values ======================== ORA #0 :\ Sets EQ if A=0, the usual test for zero CMP #0 :\ Sets EQ if A=0, also sets CS CMP #1 :\ Sets CC if A=0, sets CS if A<>0 Sign extension ============== AND #&80 :\ A become &00 or &80 BPL P%+4 :\ Skip past keeping &00 LDA #&FF :\ Change &80 to &FF Extends bit 7 of the A register to a full byte so an 8-bit byte can be sign- extended to a 16-bit word, ie &80-&FF, &00-&7F becomes &FF80-&FFFF, &0000-&007F.