| | capitalize.s 10/24/95 Jeff Ondich | | This program prompts the user to type a character, | capitalizes the character if it is a lower-case letter, | and prints the character back out. Wheeee! | | This program demonstrates some of the simplest | 680x0 assembly language instructions, I/O, | and program structure. It also demonstrates the | degree to which I want your code commented. | .data prompt: .asciz "Please type a character: " newline: .byte 012 .text .align 1 | | Main program: prompt user, get character, | capitalize character, and put character + newline. | The end. | .globl _main _main: movl #prompt, a0 jsr putstring jsr _getchar jsr capitalize jsr putchar movb newline, d0 jsr putchar rts | | Subroutine: putchar (different from the library function | "_putchar") | | Precondition: The character to be printed is | stored in d0 (more precisely, in the lowest order | byte of d0. | | Postcondition: the character has been written to | standard output by the library function _putchar. | putchar: movl d0, sp@- jsr _putchar addl #4, sp rts | | Subroutine: putstring | | Precondition: a0 contains the address of a null-terminated | string. | | Postconditions: The null-terminated string has been printed | to standard output, and a0 now points to the null character | at the end of the string. | putstring: movb a0@+, d0 tstb d0 beq ps_end movl a0, sp@- jsr putchar movl sp@+, a0 bra putstring ps_end: rts | | Subroutine: capitalize | | Precondition: The low order byte of d0 contains a character. | | Postcondition: If the character was a lower-case letter (ASCII), | then the low order byte of d0 contains the upper-case version | of the same letter. Otherwise, d0 is unchanged. | capitalize: cmpb #97, d0 blt cap_end cmpb #122, d0 bgt cap_end subb #32, d0 cap_end: rts