Shifting left in MIPS

2020-03-31 07:54发布

问题:

In my method one, I have the number that I want to shift by stored inside $a0 (e.g. 5 bits), and I want to shift $t9 by 5 bits, but I'm running into a bit of trouble. Does anyone know why?

MethodOne:

sw $a0, ($t8)
sll $t9, $t9, $t8

回答1:

To shift left by a variable amount, use sllv:

sllv $t9, $t9, $a0

sll only takes an immediate shift amount. There is no need for sw or $t8.