【问题标题】:Fetch address not aligned on word boundary (MIPS)获取地址未在字边界上对齐 (MIPS)
【发布时间】:2012-03-05 13:27:51
【问题描述】:

知道为什么我会遇到对齐错误吗?执行la $t0, mainF 时会发生错误,即使类似的行la $t0, mainB 执行得很好。这是我第一次在 MIPS 中编码,所以我做了一些研究并对地址对齐的含义有一个模糊的概念,但是编译器甚至没有到达我添加 4 的部分,然后才抛出这个运行时异常。

.data

mainF:
    .byte   1
mainB:
    .byte   1

mainN:
   (has '.word's, generic tests for the program itself)

newline:
    .asciiz "\n"
textFw:
    .asciiz "The integers in order:\n"
textBw:
    .asciiz "The integers in backwards order:\n"        

.text        

main:
    # Function prologue 
    addiu   $sp, $sp, -24        # allocate stack space -- default of 24 here
    sw      $fp, 0($sp)          # save caller's frame pointer
    sw      $ra, 4($sp)          # save return address
    addiu   $fp, $sp, 20         # setup main's frame pointer

    # Put mainF into $s0
    la      $t0, mainF
    lw      $s0, 0($t0)

    # Put mainB into $s1
    la      $t0, mainB
    lw      $s1, 0($t0)

         ...

【问题讨论】:

  • 握住你的马,我没有意识到它没有显示行号。我指出来了。更好的?即使解释为什么它可能会让我犯这个错误也会有所帮助。 (这就是我犹豫使用帮助论坛的原因。没有人愿意提供帮助。)
  • 好的,我重写了你的问题,以演示如何编写它以使其易于回答。

标签: assembly alignment mips runtime-error


【解决方案1】:

您有以下声明:

mainF:
    .byte   1
mainB:
    .byte   1

假设mainF 被分配地址0mainB 将被分配地址1。由于地址 1 显然不是字对齐的(即 1 不是 4 的倍数),因此尝试加载它会导致异常。

【讨论】:

  • 在 MIPS 中,单词是 4 大小(4 的倍数)
  • 哦。呆呆呆!加载字节,而不是加载字。那会很有意义。谢谢!
猜你喜欢
  • 2016-08-24
  • 2017-06-25
  • 2014-05-27
  • 2016-08-06
  • 2013-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多