Question

# Write assembly codes to make the number in register \$s1 doubles its original value.

Write assembly codes to make the number in register \$s1 doubles its original value.

Greetings!

We can double the value of register \$s1 by one of the following methods:

1. Multiplying it by 2

2. Bitwise logically shift its content by 1 place

Note:

Refer following assembly code in MIPS for more clarity:

#typed MIPS Assembly Code

.data

message1: .asciiz "initial value of register \$s1 = "

message2: .asciiz "\nvalue of register \$s1 after multiplying by 2= "

message3: .asciiz "\nvalue of register \$s1 after shifting logically left 1 place= "

message4: .asciiz "\nvalue of register \$s1 after adding it to itself= "

.text

.globl main

main:

#print message1

li \$v0, 4

la \$a0, message1

syscall

#\$s1 will contain 5, \$s1= 0+5 =5

#print \$s1 value

li \$v0,1

move \$a0, \$s1

syscall

#print message2

li \$v0, 4

la \$a0, message2

syscall

# \$s1 = \$s1*2 = 5*2 =10

mul \$s1, \$s1, 2

#print \$s1 value

li \$v0,1

move \$a0, \$s1

syscall

#print message3

li \$v0, 4

la \$a0, message3

syscall

# bitwise shift \$s1 content towards left 1 position

# i.e. \$s1 = 10 = 01010 after shifting left \$s1 = 10100 = 20

sll \$s1, \$s1, 1

#print \$s1 value

li \$v0,1

move \$a0, \$s1

syscall

#print message4

li \$v0, 4

la \$a0, message4

syscall

#\$s1= \$s1 + \$s1 i.e \$s1 = 20+20 =40

#print \$s1 value

li \$v0,1

move \$a0, \$s1

syscall

#end program

li \$v0, 10

syscall

#screenshot of the code with output