0

Is there anyway to shift a register value to the right but instead of adding 0's (like srl does), make it add 1's. If that's not possible, any other suggestions to accomplish the same goal would be appreciated.

ion3023
  • 151
  • 1
  • 1
  • 4

1 Answers1

2

You can do it by first ensuring that the most significative bit of the register to be shifted is 1 and then doing a shift right arithmetic (which sign extends the result).

For example, suppose you want to shift four bits right register $t0, so you would do:

  lui $at, 0x8000   # Set leftmost bit of $at to 1 and the others to 0
  or $t0, $t0, $at  # OR into register to be shifter
  sra $t0, $t0, 4   # do an arithmetic shift right
gusbro
  • 22,357
  • 35
  • 46