I am attempting to build an array of integers to represent edges (index of source | index of destination | weight) in an implementation of Dijkstra’s Algorithm using MIPS.
On running with rsim, I am getting an “unaligned word memory reference” error. I think I may be misunderstanding what memory alignment refers to. My .data is below
.data
.align 4
enterNode: .asciiz "Enter the number of nodes: "
enterEdges: .asciiz "Enter the number of edges: "
enterSource: .asciiz "Enter source: "
enterDestination: .asciiz "Enter destination: "
enterWeight: .asciiz "Enter weight: "
newLine: .asciiz "\n"
min_nodes: .word 1
max_nodes: .word 20
error1: .asciiz "Invalid number of nodes. Must be between 1 and 20.\n"
error2: .asciiz "Invalid number of edges. Must be between 0 and 400.\n"
edgeArr: .space 4800
# source | destination | weight
input: .space 5
In the .text, I am looping for the number of edges to input the data into the array, but it seems the way I am referring to or calculating the address is incorrect.
addi $t0, $zero, 0 # Edge counter
la $t1, edgeArr
addi $t2, $zero, 0
loop:
# Source
addi $v0, $zero, PRINT_STRING # Print user prompt
la $a0, enterSource
syscall
addi $v0, $zero, READ_INT # Take user input
syscall
add $t3, $t2, $t2 # Calculate address in array
add $t3, $t3, $t3
add $t3, $t1, $t3
sw $v0, ($t3)
addi $t2, $t2, 1
# ...destination and weight are effectively identical to source...
# Loop condition
addi $t0, $t0, 1
slt $t4, $t0, $s1
bne $t4, $zero, loop
I’ve looked at several similar questions but they don’t seem to quite address the portion I’m misunderstanding, and I could really benefit from a fresh pair of eyes looking at this.