MIPS-将int(32bits)分成2个带符号的短裤(16bits)

问题描述 投票:0回答:1

是否有任何简单的方法可以将32位寄存器的值分成2个带符号的短裤(16位)。我想到了:

#t0 holds the 32bit value containing the 2 signed shorts

sra  $v0, $t0, 16  #extract the 1st signed short and put it in v0
li   $t1, 0xffff   #create a mask
and  $v1, $t0, $t1 #extract the 2nd signed short and put it in v1   

但是那会破坏第二个值的符号,对吗?是否有一种简单的方法,不涉及在另一个寄存器中屏蔽2值的符号并将其移到v1之后?

mips mips32
1个回答
0
投票

要对低位进行符号扩展,需要先向左再向右移动

sll $v1, $t0, 16
sra $v1, $v1, 16

compiler explorer上的演示

© www.soinside.com 2019 - 2024. All rights reserved.