错误#5:未对齐的字存储器引用

时间:2017-11-25 02:26:46

标签: assembly mips mips32

我试图在使用MIPS的Dijkstra算法的实现中构建一个整数数组来表示边缘(目标|索引的索引|权重)。

在运行rsim时,我收到“未对齐的字存储器引用”错误。我想我可能误解了内存对齐所指的内容。我的.data在

之下
.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

在.text中,我循环获取将数据输入数组的边数,但似乎我所指的方式或计算地址不正确。

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

我看了几个类似的问题,但它们似乎并没有完全解决我误解的部分,而且我真的可以从看到这个的新眼睛中受益。

0 个答案:

没有答案