I am creating a program to read a list of strings from a text file, and store them in an array (in memory, but formatted like an array of strings). I am on Windows running MIPS on MARS. The text file is formatted so that each word is on a new line. I can successfully open and read the file into an input buffer. However, this is where the problem arises. There are no null terminating characters separating the strings, so when I go to print an individual string it prints that string and every string that follows.
.data
dictionary: .asciiz "dictionary.txt"
inputBuffer: .space 14976 # 2496 * 6 bytes needed, 4 letter words + null character, 1 byte = 1 char
.text
openDictionary:
la $a0, dictionary # load address of file
addi $a1, $zero, 0
addi $a2, $zero, 0
li $v0, 13 # syscall to open file
syscall
move $t0, $v0 #t0 now holds file descriptor
# read from file
li $v0, 14 # load read file service
move $a0, $t0 # load file descriptor a0
la $a1, inputBuffer # set a1 to address of inputBuffer
addi $a2, $zero, 14946 # set a2 to max number of chars to read, 2496 different words * 4 bytes ( 4 letter words )
syscall
li, $v0, 4
la $a0, inputBuffer
syscall
jr $ra
The output is a list of words but should only be one word.
abed
abet
able
ably
abut
acai
aced
aces
ache
achy
acid
acme
acne
acre
acts
adds
adit
adze
aeon
afar
afro
agar
aged
ages
agog
ague
ahem
aide
aids
ails
aims
airs