I want to achieve multiple word support.
E.g. abc AAAA cbAAaa => 000 4444 222222
For now all the program does is first word conversion.
As from debugger in Mars simulator it seems that it's doing all the loops correctly. Same for values of registers. (Maybe I'm missing something) I assume that words need to be shorter than 10 chars.
If anyone can spot a mistake I would be grateful. Also if you have any tips to debugging this or code improvements, feel free to say.
My code:
.data
prompt: .asciiz "Enter a string: "
msgout: .asciiz "Output string: "
input: .space 256
output: .space 256
.text
.globl main
main:
li $v0, 4 # Print enter a string prompt
la $a0, prompt
syscall
li $v0, 8 # Ask the user for the string they want to reverse
la $a0, input # We'll store it in 'input'
li $a1, 256 # Only 256 chars/bytes allowed
syscall
la $t2, ($a0) # t2 - input string
word:
li $t1, 0 # Normal counter
li $t5, 0 # Uppercase counter
li $t6, 0 # First letter of word
j word_countUppercase
word_precountUppercase:
addi $t1, $t1, 1 # Add 1 to index to avoid space in next word
la $t6, ($t1) # Set t6 to the first index of t2 (start of word)
la $t5, 0 # $t5 - 0
word_countUppercase:
#addi $t1, $t1, $t7
add $t3, $t2, $t1 # $t2 is the base address for our 'input' array, add loop index
lb $t4, 0($t3) # load a byte at a time according to counter
beq $t4, ' ', word_prereplace # We found end of word
bltu $t4, ' ', word_prereplace # We found end of string
addi $t1, $t1, 1 # Advance our counter (i++)
bltu $t4, 'A', word_countUppercase
bgtu $t4, 'Z', word_countUppercase
addi $t5, $t5, 1 # Advance our counter (i++)
j word_countUppercase
word_prereplace:
la $t2, ($a0) # t2 - input string
la $t1, ($t6) # Normal counter
addi $t5, $t5, '0'
word_replace:
add $t3, $t2, $t1 # $t2 is the base address for our 'input' array, add loop index
lb $t4, 0($t3) # load a byte at a time according to counter
beq $t4, ' ', word_replaceExit # end of the word
bltu $t4, ' ', exit # We found end of string
sb $t5, output($t1) # Overwrite this byte address in memory
addi $t1, $t1, 1 # Advance our counter (i++)
j word_replace
word_replaceExit:
j word_precountUppercase
exit:
li $v0, 4 # Print msgout
la $a0, msgout
syscall
li $v0, 4 # Print the output string!
la $a0, output
syscall
li $v0, 10 # exit()
syscall