What is the correct syntax of MIPS instruction sll?

4.9k views Asked by At

Should the shift amount be an immediate value, or a value stored in a register? Does both work?

I've had different websites tell me different things and am confused.

Based on my research the sll (shift left logical) instruction should be used like this:

  sll $d, $t, h

Which makes $d = $t shifted left h times.

I've been told that h should be a immediate value, but I was wondering if a register could be used as the third argument, and the value inside that register used as the shift amount. Would that also work?

2

There are 2 answers

1
dimm On BEST ANSWER

You are correct.

sll is specific in that it is a R-format instruction where only two registers are used, rd and rs (destination and source), and the shamt field is a immediate value (a constant).

There is another instruction sllv which uses a third register where you specify shift by variable (the register).

0
Nauman Rehmat On

Let me clear the point Shift left logical in MIPS 32 bit has following syntax:

SLL destination, Target, Shift amount(Should be immediate value)

Where as in 8086 if we want shift amount more than 1 we have to use a register to store the value of shift amount!