I am wondering is there any difference when you use different register such as the code below:
Here the correct answer uses register $v0
all the way:
get_status:
lui $t0,0xabab
ori $t0, $t0, 0x0020
lw $v0,0($t0)
andi $v0,$v0,0x4
srl $v0,$v0,2
jr $ra
I used $t1
instead of $v0
above, notice I have a extra sw
:
get_status:
lui $t0,0xabab
ori $t0, $t0, 0x0020
lw $t1,0($t0)
andi $t1,$t1,0x4
srl $t1,$t1,2
sw $t1, 0($t0)
jr $ra
I think both code works the same, what you guys think?
$v0
and $t1
are both call-clobbered general-purpose integer registers. They're not "different types".
But in the standard MIPS calling convention, $v0
(and sometimes $v1
) is where callers expect to find integer return values. That's why get_status
calculates a result in $v0
.
I think both code works the same, what you guys think?
Your code modifies the static storage that it loaded from!!! It's not a get_status
anymore.
It's either void update_status(void)
or int update_status(void)
with a non-standard calling convention (returning in $t1
).
This is inefficient:
lui ...
ori $t0, $t0, 0x0020
lw $v0,0($t0)
Use the immediate offset space of lw
to hold the low 16 bits of the static address. (It's sign extended, vs. ori
zero-extending its immediate, but in this case you don't need to adjust the lui
because the offset is signed positive.)
lui ...
lw $v0, 0x0020($t0)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.