问题
I used 'compiler explorer' to convert c++ to MIPS but it doesn't work well in the MARS because of %hi and %lo
I know I should change the part, but I don't know how to change...
Please help
$L5:
lui $2,%hi($LC1)
lwc1 $f0,%lo($LC1+4)($2)
lwc1 $f1,%lo($LC1)($2)
b $L3
$LC1:
.word 1100470148
.word 0
$L17:
lw $2,16($fp)
addiu $3,$2,1
sw $3,16($fp)
lui $4,%hi(savepath)
sll $3,$2,2
addiu $2,$4,%lo(savepath)
addu $2,$3,$2
li $3,1 # 0x1
sw $3,0($2)
move $sp,$fp
lw $fp,36($sp)
addiu $sp,$sp,40
j $31
回答1:
AFAIK, there is no way in Mars to have something like the gas %lo(label) or %hi(label) feature.
A simple workaround is to use the standard macro la
that loads a label in a register with a pair or lui
/ori
instructions.
The first part of your code can be rewritten like that:
$L5:
la $2, $LC1
lwc1 $f0,4($2)
lwc1 $f1,0($2)
b $L3
$LC1:
.word 1100470148
.word 0
As the la
macro is expanded to two instructions,that is an extra instruction compared to the use of %hi/%lo
but it works.
来源:https://stackoverflow.com/questions/56124161/how-to-change-the-assembly-code-hi-and-lo-to-run-in-mars