I am attempting to write a program that simply counts the number of characters and words in a string and I'm about to end it all.
This is what I have so far:
For whatever reason, stepping through showed me that it's not loading anything into $t2 (lb $t2, ($t1) does nothing), and then it does the beqz comparison and since there's nothing loaded, it exist the loop. Maybe someone can see an issue I'm missing here but I'm literally pulling my hair out over this.
This is what I have so far:
Code
.data
inputPromptString: .asciiz "Enter some text"
.align 2
userInputString: .asciiz ""
.align 2
words: .word 0
characters: .word 0
.text
main:
la $a0, inputPromptString #load the address of the inputpromptstring into a0
la $a1, userInputString #load address of the string the user inputs
li $v0, 54 #prompt for user input
syscall
la $s0, userInputString #save the user input into $s0
la $t1, userInputString
jal count
sw $v0, characters #store variable into characters
sw $v1, words #store variable into words
exit:
li $v0, 10
syscall
count:
li $v0, 0
li $v1, 0
loop:
lb $t2, ($t1)
beqz $t2, exitLoop
addi $v0, $v0, 1
addi $t1, $t1, 1
beq $t2, 32, addWord
j loop
addWord:
addi $v1, $v1, 1
j loop
exitLoop:
addi $v1, $v1, 1
jr $raFor whatever reason, stepping through showed me that it's not loading anything into $t2 (lb $t2, ($t1) does nothing), and then it does the beqz comparison and since there's nothing loaded, it exist the loop. Maybe someone can see an issue I'm missing here but I'm literally pulling my hair out over this.

