Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

MIPS question

Name: Anonymous 2010-03-18 23:17

I'm having trouble writing a method that removes all characters from a string that aren't letters or integers.  What happens is that as soon as a character designated to be set to null is encountered, all characters that follow are set to null too.
Any help would be appreciated.       

.data
Buffer:    .asciiz "                                                                                "    # 80 bytes in Buffer
intro:    .asciiz "Hello, please enter a string of up to 80 characters.  I will then tell you if that string was a palindrome!"
        .text
main:
    li    $v0, 4        # print_string call number
    la    $a0, intro    # pointer to string in memory
    syscall
    li    $v0, 8        #syscall code for reading string
    la    $a0, Buffer    #save read string into buffer
    li    $a1, 80        #string is 80 bytes long
    syscall
    li    $s0, 0        #i = 0
    li    $t0, 80        #max for i to reach
    la    $a0, Buffer
    jal stripNonAlpha
    li    $v0, 4        # print_string call number
    la    $a0, Buffer    # pointer to string in memory
    syscall
   
#################################
#    stripNonAlpha method    #
#################################
stripNonAlpha:
    beq    $s0, $t0, stripEnd    #if i = 80 end
    add    $t4, $s0, $a0        #address of Buffer[i] in $t4
    lb    $s1, 0($t4)        #load value of Buffer[i]
    slti    $t1, $s1, 48        #if ascii code is less than 48
    bne    $t1, $zero, strip    #remove ascii character
    slti    $t1, $s1, 58        #if ascii code is greater than 57
                    #and
    slti    $t2, $s1, 65        #if ascii code is less than 65
    slt    $t3, $t1, $t2       
    bne    $t3, $zero, strip    #remove ascii character
    slti    $t1, $s1, 91        #if ascii code is greater than 90
                    #and
    slti    $t2, $s1, 97        #if ascii code is less than 97
    slt    $t3, $t1, $t2
    bne    $t3, $zero, strip    #remove ascii character
    slti    $t1, $s1, 123        #if ascii character is greater than 122
    beq    $t1, $zero, strip    #remove ascii character
    addi    $s0, $s0, 1        #i = i + 1
    j    stripNonAlpha        #go to stripNonAlpha
strip:
    add    $t5, $s0, $a0        #address of Buffer[i] in $t5
    sb    $0, 0($t5)        #Buffer[i] = 0
    addi    $s0, $s0, 1        #i = i + 1
    j    stripNonAlpha        #go to stripNonAlpha
stripEnd:
    la    $a0, Buffer        #save modified string into buffer
    jr    $ra            #return

Name: Anonymous 2010-03-19 18:35

I appreciate the help, I'm a total noon at both /prog/ and MIPS so anything helps

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List