I am beginning to write a MIPS program that takes an input string from the data segment, encodes it using a character map which is also a string loaded in the data section, and then write the encoded string into an output string which must also be held in memory so that the input string is not overwritten. All letters are encoded to uppercase, all spaces, punctuation etc. is removed during encoding, and all strings must be delimited by a newline character.
Here is the start of my program so far:
.data
DataIn: .ascii "Test String\n"
SubMap: .ascii "PHQGIUMEAYLNOFDXJKRCVSTZWB\n"
DataOut: .ascii ""
.text
.globl main
main:
la $a0, DataIn #a0 = &DataIn[0]
la $a1, DataOut #a1 = &DataOut[0]
la $a2, SubMap #a2 = &SubMap[0]
jal subCipher
syscall
subCipher:
lw $t0, 0($a0) #t0 = DataIn[0] (first char of input)
lw $t1, 0($a1) #t1 = DataOut[0] (first char of output)
When executed, I am getting an error at the last line: lw $t1, 0($a1)
. The error thrown is
Runtime exception at 0x00400024: fetch address not aligned on word boundary 0x10010027
I am guessing it is due to something along the lines of memory addresses clashing because the SubMap
string is so long and is stored before the DataOut
string. How can I resolve this?
On a second note, how can I store the encoded string in memory as it is created so that the input string is not overwritten. Currently, I am just loading an empty string into the data segment, but I do not think this will work.
I am guessing it is due to something along the lines of memory addresses clashing because the string is so long.
No, it's because you're trying to load a word (4 bytes) from a non word-aligned address (0x10010027).
lw
and sw
are the wrong instructions to use here, since your characters are bytes, not words. So you should be usding lb
(or lbu
) and sb
.