// SCANTEXT          Text Analyzer

// This program will count the number of characters
// (including punctuation but not spaces) in a sentence
// and find how many words it contained.
        SPACE   = 0x20            // ASCII code for 
        .data                     // Declare storage
        .align  8                 // Desired alignment
QUADS:  .skip   2*8               // Space for results
TEXT:   stringz "The faster I run the behinder I get."
        .text                     // Section for code
        .align  32                // Desired alignment
        .global main              // These three lines
        .proc   main              //  mark the mandatory
main:                             //   'main' program entry
        .body                     // Now we really begin...
first:  mov     r20 = 0           // Gr20 = character count
        mov     r21 = 0           // Gr21 = word count
        addl	r14 = @gprel(TEXT),gp    // Gr14 --> TEXT
        addl	r15 = @gprel(QUADS),gp;; // Gr15 --> QUADS
next:   ld1     r22 = [r14],1;;   // Get a character; bump
        cmp.eq  p6,p7 = r0,r22    // Null code marks end
   (p6) br.cond.spnt.few nomore;; //  of our work
        cmp.eq  p6,p7 = SPACE,r22;; // End of word?
   (p7) add     r20 = 0x1,r20     // No: count a character
   (p6) add     r21 = 0x1,r21     // Yes: count a word
        br.cond.sptk.few next;;   // Go back for more
nomore: add     r21 = 0x1,r21;;   // The last word
        st8     [r15] = r20,8;;   // Number of characters
        st8     [r15] = r21       // Number of words
done:   mov     r8 = 0            // Signal all is normal
        br.ret.sptk.many b0;;     // Back to command line
        .endp   main              // Mark end of procedure