【问题标题】:MIPS fetch address not aligned on word boundaryMIPS 获取地址未在字边界上对齐
【发布时间】:2016-08-24 05:43:24
【问题描述】:

为什么会出现此错误:

ine 101:0x00400138 处的运行时异常:获取地址未对齐 字边界 0x10010005

代码如下:

    .data
     array: .word 3.1, 3.2, 20.0
     .text
     la   $s1, array
     li $t0, 0
       li $s5, 1
li $t1,0
          sortloop: slti $s0, $t0, 3           #Checking if the counter is less than 20
                    beq  $s0, $zero, exitout       #if it's greater or equal to 20 exit the loop
                    sll  $t4, $t0, 2             # i*4
                    add  $t4, $t4, $s1           # adding the base register to $t4
                    l.s  $f11, 0($t4)            # loading from memory the element of the array that holds a float value
                    add  $s5, $s5, $t0
          innloop:  slti $s0, $s5, 3           #Checking if the counter is less than 20
                    beq  $s0, $zero, exitinn       #if it's greater or equal to 20 exit the loop
                    sll  $t1, $s5, 2             # i*4
                    add  $t1, $t1, $s1           # adding the base register to $t7
                    l.s  $f19, 0($t1)            //this is line 101
                    c.le.s $f19, $f11
                    bc1f, addcounter
                    add.s $f20, $f14, $f19       
                    l.s  $f11, 0($t1)
                    l.s  $f20, 0($t4)
                    add  $s1, $s1,1
         j innloop
                   addcounter:
                   add  $s1, $s1,1
                   j innloop
                   exitinn:
                   add $t0, $t0,1
                   j sortloop
exitout:

【问题讨论】:

  • add $s1, $s1,1 看起来很可疑。

标签: assembly mips mars-simulator


【解决方案1】:

在 MIPS 上,您无法从未对齐的地址加载浮点数,因此当您尝试这样做时会出错。

您正在将浮点数读入$f19。您正确地将 i 乘以 4,但在内部循环中,您只在每个循环上将一个添加到 $s1 并且不要将其乘以任何地方。您必须添加 4 才能到达数组中的下一个浮点数才能获得正确的值。

【讨论】:

    猜你喜欢
    • 2017-06-25
    • 2014-05-27
    • 2012-03-05
    • 2016-08-06
    • 2013-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多