tab equ $09 sp equ $20 cr equ $0D lf equ $0A org $1000 char_cnt rmb 1 word_cnt rmb 1 string_x fcc "this is a strange test string to count chars and words." fcb 0 org $1500 ldx #string_x clr char_cnt clr word_cnt string_lp ldab 1,x+ ; get one character and move string pointer lbeq done ; is this the end of the string? inc char_cnt ; the following 8 instructions skip white space characters between words cmpb #sp beq string_lp cmpb #tab beq string_lp cmpb #cr beq string_lp cmpb #lf beq string_lp ; a non-white character is the start of a new word inc word_cnt wd_loop ldab 1,x+ ; get one character and move pointer beq done inc char_cnt ; the following 8 instructions check the end of a word cmpb #sp lbeq string_lp cmpb #tab lbeq string_lp cmpb #cr lbeq string_lp cmpb #lf lbeq string_lp bra wd_loop done swi end