你好,在将 C 代码转换为 MIPS 时,无论如何要避免使用 %hi 和 %lo,我所有的 addiu 函数都会出错

发布于 2025-01-20 18:15:25 字数 1091 浏览 3 评论 0原文

这是我的一些代码:

    la     $t2, $LC1
    la      $t9,($t2)
    addiu   $t3,$t2,%lo($LC1)
    lw      $t8,4($t3)
    addiu   $t3,$t2,%lo($LC1)
    lw      $t7,8($t3)
    addiu   $t3,$t2,%lo($LC1)
    lw      $t6,12($t3)
    addiu   $t3,$t2,%lo($LC1)
    lw      $t5,16($t3)
    addiu   $t3,$t2,%lo($LC1)
    lw      $t4,20($t3)
    addiu   $t3,$t2,%lo($LC1)

以下是错误:

Error in /Applications/mips7.asm line 101 column 9: "addiu": Too many or incorrectly formatted operands. Expected: addiu $t1,$t2,-100
Error in /Applications/mips7.asm line 103 column 9: "addiu": Too many or incorrectly formatted operands. Expected: addiu $t1,$t2,-100
Error in /Applications/mips7.asm line 105 column 9: "addiu": Too many or incorrectly formatted operands. Expected: addiu $t1,$t2,-100
Error in /Applications/mips7.asm line 107 column 9: "addiu": Too many or incorrectly formatted operands. Expected: addiu $t1,$t2,-100
Error in /Applications/mips7.asm line 109 column 9: "addiu": Too many or incorrectly formatted operands. Expected: addiu $t1,$t2,-100

Here is some of my Code:

    la     $t2, $LC1
    la      $t9,($t2)
    addiu   $t3,$t2,%lo($LC1)
    lw      $t8,4($t3)
    addiu   $t3,$t2,%lo($LC1)
    lw      $t7,8($t3)
    addiu   $t3,$t2,%lo($LC1)
    lw      $t6,12($t3)
    addiu   $t3,$t2,%lo($LC1)
    lw      $t5,16($t3)
    addiu   $t3,$t2,%lo($LC1)
    lw      $t4,20($t3)
    addiu   $t3,$t2,%lo($LC1)

Here are the errors:

Error in /Applications/mips7.asm line 101 column 9: "addiu": Too many or incorrectly formatted operands. Expected: addiu $t1,$t2,-100
Error in /Applications/mips7.asm line 103 column 9: "addiu": Too many or incorrectly formatted operands. Expected: addiu $t1,$t2,-100
Error in /Applications/mips7.asm line 105 column 9: "addiu": Too many or incorrectly formatted operands. Expected: addiu $t1,$t2,-100
Error in /Applications/mips7.asm line 107 column 9: "addiu": Too many or incorrectly formatted operands. Expected: addiu $t1,$t2,-100
Error in /Applications/mips7.asm line 109 column 9: "addiu": Too many or incorrectly formatted operands. Expected: addiu $t1,$t2,-100

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆流 2025-01-27 18:15:25

MIPS编译器,汇编器和链接器使用多个指令和%HI,带有LUI%lo aiddiu 。

火星不支持%hi%lo地址操纵功能 - 相反,它提供了伪指令la加载整个32位地址标签到寄存器中。  (此指令将其扩展到两个机器代码指令中,涉及lui,另一项类似于ori。)

因此,使用%hi& %lo进入火星的一个la,然后使用该地址来完成预期的效果:加载地址或加载或存储到全局数据标签。

如果预期的效果是从全局/静态数据标签中加载或存储,则火星还支持lw $ t0,标签sw $ t0,标签 pseudo指令表格。

一般而言,火星伪指示隐藏了基础机器代码的详细信息,包括当可以消除或共享lui指令之一时,隐藏了手动优化的机会。 例如,如果我们做global_var ++ lw $,标签后跟sw $,标签将涉及两个lui指令。


以下对于火星没有意义:

la     $t2, $LC1
addiu   $t3,$t2,%lo($LC1)

因为la已经为$ lc1 已经产生了完整%lo($ LC1)到该指针。

MIPS compilers, assemblers and linkers use multiple instruction and %hi with lui and %lo with addiu.

MARS does not support the %hi or %lo address manipulation functions — instead it offers a pseudo instruction la that loads the whole 32-bit address of the label into the register.  (This instruction expands into two machine code instructions that involve lui and another like ori.)

So, collapse the two instructions using %hi & %lo into one la for MARS, and then use that address to accomplish the intended effect: load an address, or load or store to global data label.

If the intended effect is to load or store from a global/static data label, MARS also supports lw $t0, label, and sw $t0, label pseudo instruction forms.

Generally speaking, MARS pseudo instructions hide underlying machine code details, including hiding opportunities for manual optimization when one of the lui instructions could have been eliminated or shared.  If we do global_var++ for example, that should require only one lui, one lw and one sw but in MARS lw $, label followed by sw $, label will involve two lui instructions.


The following doesn't make sense for MARS:

la     $t2, $LC1
addiu   $t3,$t2,%lo($LC1)

Because the la has already produced the full 32-bit address for $LC1, there's no point in adding an offset %lo($LC1) to that pointer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文