The Impossible Squish
The Impossible Squish

Reputation: 325

What is the correct syntax of MIPS instruction sll?

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?

Upvotes: 1

Views: 5402

Answers (2)

Nauman Rehmat
Nauman Rehmat

Reputation: 1

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!

Upvotes: 0

dimm
dimm

Reputation: 1798

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).

Upvotes: 4

Related Questions