将32位整数拆分为2个带符号的16位短裤

是否有任何简单的方法可以将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,$t1 #extract the 2nd signed short and put it in v1   

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

zhangkun863 回答:将32位整数拆分为2个带符号的16位短裤

要对低位进行符号扩展,您需要先左移然后右移

names

compiler explorer上的演示

本文链接:https://www.f2er.com/3063628.html

大家都在问