Why shift a bit using sll and such in MIPs Assembly?

Carson

So I understand somewhat what the command sll is doing, as I read this and its pretty much just shifting all the bits left by 1. I'm just wondering why would I do this?

I have an assignment from class with an example of it... Where $s6 and $s7 is the base address for an array and $s1/$s2 are just some variables.

sll $t0, $s0, 2
add $t0, $s6, $t0
sll $t1, $s1, 2
add $t1, $s7, $t1
...

Why shift a bit? What is it doing in simple terms? My first thought it has something to do with indexing the variables in the array...but I'm not sure.

Michael

its pretty much just shifting all the bits left by 1

The example they showed was a shift by 1 bit. The sll instruction isn't limited to just shifting by 1 bit; you can specify a shift amount in the range 0..31 (a shift by 0 might seem useless, but SLL $zero, $zero, 0 is used to encode a NOP on MIPS).

A logical left shift by N bits can be used as a fast means of multiplying by 2^N (2 to the power of N). So the instruction sll $t0, $s0, 2 is multiplying $s0 by 4 (2^2) and writing back to $t0. This is useful e.g. when scaling offsets to be used when accessing a word array.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Multiplication using Logical shifts in MIPS assembly

From Dev

sorting array in mips (assembly)

From Dev

How can I do a bit shift for a large sequence of bytes in NASM Assembly?

From Dev

string length for mips assembly

From Dev

MIPS Assembly Labels

From Dev

Operator Precedence in Java (bit shift operator) : why is the following output true?

From Dev

VHDL shift or rotate: difference between concatenation and builtin functions (sll, sra,...)

From Dev

MIPS shift left/shift right

From Dev

MIPS assembly string array

From Dev

Tribonacci in Mips Assembly

From Dev

How to perform 64-bit addition and subtraction using MIPS?

From Dev

Error using bit shift operator

From Dev

bit shift for unsigned int, why negative?

From Dev

Why do we use .globl main in MIPS assembly language?

From Dev

Recursive function using MIPS assembly

From Dev

BNE branch in MIPS assembly

From Dev

Adding two 16 bit numbers using 8 bit registers (Assembly)

From Dev

C to MIPS Assembly

From Dev

bit shift multiplication in c not using powers of 2

From Dev

string length for mips assembly

From Dev

MIPS shift left/shift right

From Dev

MIPS assembly string array

From Dev

Error using bit shift operator

From Dev

understanding MIPS assembly with pipelining

From Dev

C to MIPS Assembly

From Dev

Assembly MIPS: Printing a character five times using loops

From Dev

Mips Assembly Language using bit manipulation to check if int is less than 32 & displays 0 if so, otherwise (32 or higher) displays 1

From Dev

MIPS Assembly, matrix multiplication

From Dev

MIPS Assembly - if condition with substraction