I would like to do some byte manipulation using MIPS instruction set.
$S0
which has 0x8C2E5F1E
and register $S1
which has 0x10AC32BB
. $S0
, 5F
, into the third byte of $S1
, AC
.My logic would be to store the byte of register $S0
into another register, shift it to the desired byte. Then I would and register $S1
with 0xFF00FFFF
. Finally, I would just or the two registers.
How does that sound? Is it correct? Any better way?
Any suggestions or solution would be appreciated.
For Release 2 and later, MIPS includes an Insert Bit Field instruction which takes bits starting at the least significant from one register and placing them into the specified range in a second register. Thus your byte insertion could be performed by the following:
// rotating right one byte rather than shift to preserve data
// without using an additional register
ROTR $S0, $S0, 8;
// insert LSbits from $S0 into $S1 starting at bit 16
// with size of 8 bits
INS $S1, $S0, 16, 8;