* * HW6 * * Purpose: converts a string up to MAXLN to all upper case letters * * Author: Heather D. Pfeiffer * *** Useful Global Names RAM equ $0000 STACK equ $00ff EEPROM equ $f800 CONSTS equ $f900 RESET equ $fffe MAXLN equ 5 * This is the maximum number of chars including 0 LTEA equ $61 * 'a character value in hex LTEZ equ $7a * 'z character value in hex CONVAL equ $20 * Value to add to get upper 'A - 'a *** Save space for temp buffer and 3 converted strings; *** leave a blank space between each string org RAM tmpbf rmb MAXLN+1 fstr1 rmb MAXLN+1 fstr2 rmb MAXLN+1 fstr3 rmb MAXLN+1 org EEPROM *** * Procedure storstr * - this procedure stores the input string to a temporary buffer * for processing * * Inputs: * string: string to stored (by reference) *** storstr tsy ldx 2,y * get the string location from the stack ldy #tmpbf * get the buffer location for storage ldaa 0,x ldab #0 sloop cmpb #MAXLN * while ((length(string) < MAXLN) beq send * || tsta * (string[i] != 0)) { beq szsor staa 0,y * save in temporary buffer inx iny ldaa 0,x incb bra sloop * } szsor staa 0,y * store the final 0 bit send rts *** * Procedure upper * - this procedure converts all the lower case letters * from 'a to 'z to upper case; any other characters * are not changed. Value 0 indicates that string is done. * Maximum length of string is MAXLN (including 0). *** upper ldx #tmpbf * get the buffer location ldaa 0,x ldab #0 uloop cmpb #MAXLN * while ((length(string) < MAXLN) beq uend * || tsta * (string[i] != 0)) { beq uend cmpa #LTEA * if ((string[i] >= 'a) blo cont * || cmpa #LTEZ * (string[i] <= 'z)) { bhi cont ldab #CONVAL sba * string[i] += CONVAL staa 0,x * } cont inx ldaa 0,x incb bra uloop * } uend rts *** * Procedure savebuf * - this procedure stores the temporary buffer to the final string * location * * Inputs: * floc: final string location (by reference) *** savebuf tsy ldx 2,y * get the final storage location from stack ldy #tmpbf * get the buffer location for storage ldaa 0,y ldab #MAXLN bloop beq bend * while (i != MAXLN) staa 0,x * save in final storage from temporary buffer clra * clear temporary buffer staa 0,y inx iny ldaa 0,y decb bra bloop * } bend rts *** * Procedure process * - this procedure sends one string at a time through the whole process * * Global Inputs: * floc: final string location (in register Y) * string: string to convert to upper (in register X) *** process pshy pshx jsr storstr * store the string in the buffer ins * remove input parameter ins jsr upper * convert to upper jsr savebuf * save converted string in memory ins * remove input parameter ins rts *** * Main Testing Program * - test that the toupper string function converts the * string correctly and places back in its new memory * location for all 3 test strings *** main lds #STACK ldx #str1 ldy #fstr1 jsr process ldx #str2 ldy #fstr2 jsr process ldx #str3 ldy #fstr3 jsr process endloop bra endloop * dead loop *** Test strings org CONSTS str1 fcc "AaZz" fcb 0 str2 fcc "abc" fcb 0 str3 fcc "abcdef" fcb 0 *** Setup reset vector org RESET fdb main