/****************************************************************************** Example #14 -- SPARC Repetitive Control Constructs The program reads zero or more characters from standard input. When the end of the input stream is found, the program displays the character count. ******************************************************************************/ .global main .section ".text" .align 4 main: save %sp, -96, %sp clr %r16 ! Initialize character count loop: call getchar ! Read one character (returned in %r8) nop cmp %r8, -1 ! Compare return value to EOF be endloop ! If EOF found, exit loop nop inc %r16 ! Increment character count ba loop ! Jump to top of loop nop endloop: set fmt, %r8 ! First arg -- address of format string mov %r16, %r9 ! Second arg -- character count call printf ! Print the number of characters nop ret restore fmt: .asciz "\nCharacters = %d\n" .align 4