How to get the pointer of the next word in MIPS assembly? - Stack Overflow

admin2025-04-26  2

This function should return the pointer to the first letter character in the next word of the string and if there is no next word, it should return 0. The input is a pointer to a string that isn't null. So if the input were to be the pointer to "fat; !1guys []rock", then the output should be the pointer to "guys []rock".

I have a function already called isletter that returns 1 if the input is a letter and 0 if it is not.

I am mainly having trouble with using lb when loading the value of $t0 into $t1, and getting an address out of range error with it.

nextword:
    move $t0, $a0
    j find_letters
find_letters:
    lb $t1, ($t0)
    beqz $t1, no_next_word
    jal isletter
    bnez $v0, skip_letter
    addi $t0, $t0, 1
    j skip_non_letters
skip_letter:
    addi $t0, $t0, 1
    j find_letters
skip_non_letters:
    lb $t1, ($t0)
    beqz $t1, no_next_word
    jal isletter
    beqz $v0, skip_non_letter
    addi $t0, $t0, 1
    j next_word_found
skip_non_letter:
    addi $t0, $t0, 1
    j skip_non_letters
next_word_found:
    move $v0, $t0
    jr $ra
no_next_word:
    li $v0, 0
    jr $ra

This is what I have so far.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745630346a310976.html

最新回复(0)