So I am busy writing a MIPS program that will take an input string, and then print all possible UNIQUE permutations of that string. (AKA if the word is LoOp, LoOp and LOop are the same).
In order to do this, I know I need to NOT have a newline character on the end of my input string, but I don’t know to make sure it’s not added. Here is what I have so far:
.data
newLine:
.asciiz "\n"
promptUser:
.asciiz "Enter a 20 letter or less word:\n"
word:
.space 21
.text
main:
la $a0, promptUser
li $v0, 4 # Ask User for Input
syscall
la $a0, word
li $a1,21 # Max number of characters 20
li $v0,8
syscall # Prompting User
la $a0,newLine # Newline
li $v0, 4
syscall
la $a0, word # Printing Word
li $v0, 4
syscall
The only time a ‘\n’ isn’t included is when the number of letters entered is exactly 20. Any suggestions??
FIX:
This works:
li $s0,0 # Set index to 0
remove:
lb $a3,word($s0) # Load character at index
addi $s0,$s0,1 # Increment index
bnez $a3,remove # Loop until the end of string is reached
beq $a1,$s0,skip # Do not remove \n when string = maxlength
subiu $s0,$s0,2 # If above not true, Backtrack index to '\n'
sb $0, word($s0) # Add the terminating character in its place
skip:
You can parse the string upon returning from syscall 8 to remove the character:
Also note that you didn’t reserve enough space for the word. You should reserve 21 bytes with