1

The syntax for sll and srl is:

sll $s0,$s1,n (n is an integer, for example sll $s0,$s1,3)

srl $s0,$s1,n (n is an integer, for example srl $s0,$s1,3)

I wonder if I can substitute $n$ for a register.

For instance:

sll $s0,$s1,$s2

I'm sorry, I'm a newbie to MIPS.

Tjh Thon
  • 85
  • 7

1 Answers1

1

The instructions you're looking for are sllv/srlv et al. For example, sllv $s0,$s1,$s2

And as always when having questions regarding the MIPS instruction set, consult MIPS32™ Architecture For Programmers Volume II: The MIPS32™ Instruction Set.

Michael
  • 57,169
  • 9
  • 80
  • 125
  • Does it mean that there's no way for the register to replace the integer? – Tjh Thon Sep 17 '18 at 16:19
  • I think you misread my answer. _"The instructions you're looking for are sllv/srlv et al."_ So yes, you can shift by a register-specified amount. – Michael Sep 17 '18 at 16:21
  • 1
    To clarify: `sllv`, `srlv` are different instructions than `sll`, `srl`. – markgz Sep 17 '18 at 17:11