A Shift Left Logical instruction in MIPS assembly is used for shifting the bits to the left. The amount of shift depends on the value we give it. When we perform a shift left logical instruction the low bits at right most is replaced by zeros and the high right most bit is discarded. (Number of discarded bits depend on the amount of shift)
To understand the full logic see the below picture:
In the picture, you can see that performing sll one time on an 8-bit pattern causes the whole pattern shift by one bit.[thrive_highlight highlight=’default’ text=’light’]Shift logical left by one causes the number multiplied by 2.[/thrive_highlight]
It’s general form is as follows: sll destination, target, shift_amount
Shift Left Logical-MIPS Program
Q: Write a program in MIPS, that take an integer from the user, perform SLL and Print the output.
.data msg1: .asciiz "Enter the number to perform SLL: " msg2: .asciiz "\nThe result of SLL is: " .text li $v0,4 la $a0,msg1 syscall li $v0,5 syscall sll $a0,$v0,1 li $v0,4 la $a0,msg2 syscall li $v0,1 syscall li $v0,10 syscall
Enter the number to perform SLL: 2 The result of SLL is: 4
That was all about MIPS SLL, questions in the comment box will be appreciated!