##################################################################### # Program #1: Convert to Uppercase # Programmer: Chris Brakebill # Due Date: Oct. 27, 2009 Course: ECE 355 # Last Modified: Oct. 25, 2009 # ##################################################################### # Functional Description: # Converts lowercase characters in a string to uppercase, # ignoring all non-alphabetical characters # Input: Requests a string from the keyboard. # Output: Outputs the string in uppercase, minus non-alphabetical # characters. # ##################################################################### # Pseudocode: # Prompt for input string of maximum 30 characters # Read input as string # Initialize two pointers to first character # Begin loop to look at each character in string # If character is null, go to End # If character's hex value is less than 'A', skip it # If character's hex value is less than 'Z', put in output string # If character's hex value is less than 'a', skip it # If character's hex value is greater than 'z', skip it # Convert character to uppercase # Go to Begin loop # End # Print string # Exit ###################################################################### # Register Usage: # $t0 - points to character in string being processed # $t1 - points to place where next character will be stored # $t2 - holds a character for processing # $t3 - holds hex value for character a # $t4 - holds hex value for character z # $t5 - holds hex value for character A # $t6 - holds hex value for character Z # #################### Data segment #################################### .data string_prompt: .asciiz "Please type a string: \n" out_msg: .asciiz "Your string in all capitals is: " in_string: .space 31 one: .word 1 ################### Code segment ##################### .text .globl main main: la $a0,string_prompt # prompt user for input li $v0,4 syscall la $a0,in_string # read user input string li $a1,31 li $v0,8 syscall la $a0,out_msg # write output message li $v0,4 syscall la $t0,in_string # pointer 1 la $t1,in_string #### pointer 2 li $t3,0x61 # minimum lowercase letter (a) li $t4,0x7a # maximum lowercase letter (z) li $t5,0x41 #### minimum uppercase letter (A) li $t6,0x5a #### maximum uppercase letter (Z) loop: lb $t2,0($t0) #### loads the next character for processing beqz $t2,exit_loop # if NULL, we are done blt $t2,$t5,skip #### if character is not a letter, skip (hex value < 'A') ble $t2,$t6,no_change #### it character is an uppercase, store it and move to next blt $t2,$t3,skip #### if character is not a letter, skip (hex value between 'Z' and 'a') bgt $t2,$t4,skip #### if character is not a letter, skip (hex value > 'z') addu $t2,$t2,-32 # convert to uppercase (’A’-’a’ = -32) no_change: sb $t2,0($t1) addu $t0,$t0,1 #### increment read pointer addu $t1,$t1,1 #### increment storage pointer j loop skip: addu $t0,$t0,1 #### increment read pointer j loop exit_loop: sb $0,0($t1) #### due to skipped values, store NULL value so string printing stops la $a0,in_string # print string with all caps li $v0,4 syscall li $v0,10 # exit syscall