你好,在将 C 代码转换为 MIPS 时,无论如何要避免使用 %hi 和 %lo,我所有的 addiu 函数都会出错
这是我的一些代码:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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
已经为$ lc1
已经产生了完整%lo($ LC1)到该指针。MIPS compilers, assemblers and linkers use multiple instruction and
%hi
withlui
and%lo
withaddiu
.MARS does not support the
%hi
or%lo
address manipulation functions — instead it offers a pseudo instructionla
that loads the whole 32-bit address of the label into the register. (This instruction expands into two machine code instructions that involvelui
and another likeori
.)So, collapse the two instructions using
%hi
&%lo
into onela
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
, andsw $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 doglobal_var++
for example, that should require only onelui
, onelw
and onesw
but in MARSlw $, label
followed bysw $, label
will involve twolui
instructions.The following doesn't make sense for MARS:
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.