//---------------------------------------------------------------- // toupper.s // // This program tests a procedure for converting ascii // character-codes found in an array of specified size // from lowercase to their uppercase equivalents. // // programmer: ALLAN CRUSE // written on: 10 SEP 2003 //---------------------------------------------------------------- .text #----------------------------------------------------------------- use_uppercase: # # Expects: %ebx = base-address of the array # %ecx = number of bytes in array # # Any lowercase letters found will be converted into uppercase. # pushl %ebx # preserve array-address nxch: cmpb $'a', (%ebx) # ascii-code below 'a'? jb isok # yes, not lowercase cmpb $'z', (%ebx) # ascii-code after 'z'? ja isok # yes, not lowercase # here the ascii-code must represent a lowercase letter andb $0xDF, (%ebx) # convert it to uppercase isok: incl %ebx # advance array-address loop nxch # process the next item popl %ebx # recover array-address ret # return to the caller #----------------------------------------------------------------- main: call obtain_input call process_data call print_output ret #----------------------------------------------------------------- # manifest constants .equ STDOUT, 1 # device-number (output) .equ STDIN, 0 # device-number (input) .equ MAXIN, 80 # maximum length of input .data #----------------------------------------------------------------- prompt: .ascii "Please type in a short message, " .asciz "then press the -key: \n" msglen: .int . - prompt # length of prompt string buffer: .space MAXIN # buffer holds user input icount: .int 0 # counts the keys pressed #----------------------------------------------------------------- .text #----------------------------------------------------------------- obtain_input: pushl msglen # argument #3 pushl $prompt # argument #2 pushl $STDOUT # argument #1 call write # call C runtime library addl $12, %esp # discard three arguments pushl $MAXIN # argument #3 pushl $buffer # argument #2 pushl $STDIN # argument #1 call read # call C runtime library addl $12, %esp # discard three arguments movl %eax, icount # actual length of input ret #----------------------------------------------------------------- process_data: movl $buffer, %ebx movl icount, %ecx call use_uppercase ret #----------------------------------------------------------------- print_output: pushl icount # argument #3 pushl $buffer # argument #2 pushl $STDOUT # argument #1 call write # call C runtime library addl $12, %esp # discard three arguments ret #----------------------------------------------------------------- .globl main