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.

Homework Answers

Answer #1

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

3. Add it to itself

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

addi $s1, $zero, 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

add $s1, $s1, $s1

#print $s1 value

li $v0,1

move $a0, $s1

syscall

#end program

li $v0, 10

syscall

#screenshot of the code with output

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write an assembly program to count the binary ones in register R1.   
Write an assembly program to count the binary ones in register R1.   
Write a program in microassembly to check if a number in register r2 is a perfect...
Write a program in microassembly to check if a number in register r2 is a perfect square.Save the Boolean result in register, r0.
Write a possible assembly language instruction or set of instructions to accomplish the following: Compare the...
Write a possible assembly language instruction or set of instructions to accomplish the following: Compare the byte stored at the memory location pointed to by register R4 to the upper (higher) byte stored in register R5 b) Branch to instruction at label ‘ZERO’ if the lower byte of register R6 is zero c) Jump to the instruction at label ‘EVEN’ if the value in register R7 is an even number
_____ codes are two-digit codes that give the number of services provided. Value Revenue Occurrence Service
_____ codes are two-digit codes that give the number of services provided. Value Revenue Occurrence Service
2.     Explain each line of the following MIPS assembly language code segment. Write the corresponding C...
2.     Explain each line of the following MIPS assembly language code segment. Write the corresponding C language code and indicate the content of each register with the corresponding variable in C-code. muli $t2, $s1, 4    add $t2, $t4, $t2    lw $t15, 0($t2)    lw $t16, 4($t2)    sw $t16, 0($t2)    sw $t15, 4($t2)
Complete this AVR assembly language fragment so that it adds the unsigned 16-bit value in register...
Complete this AVR assembly language fragment so that it adds the unsigned 16-bit value in register pair r9:r6 to the unsigned 16-bit value in r7:r8. (Registers 9 and 7 are the most signficant bytes in these 16-bit quantities. The result ends up in r7:r8.) addadcadiwr6r7r8r9  addadcadiwr6r7r8r9 ,  addadcadiwr6r7r8r9 addadcadiwr6r7r8r9  addadcadiwr6r7r8r9 ,  addadcadiwr6r7r8r9
/* data is an array of doubles. len is the number of elements in the array....
/* data is an array of doubles. len is the number of elements in the array. The return value should be the Average of the doubles in the data array. The Average is defined as the average value from among the elements, e.g.    if the data array was { 6.0, 3.0, 2.5, 20.7 }, the function should return    the value 2.5. */ double average(double data[], int len) { double min_val = data[0]; /* TODO: Write the code that...
Write a mips assembly language program that asks the user to enter and integer number and...
Write a mips assembly language program that asks the user to enter and integer number and read it. Then ask him to enter a bit position (between 0 and 31) and display the value of that bit.
Write a piece of assembly code in SimpleRisc to find out if a number is a...
Write a piece of assembly code in SimpleRisc to find out if a number is a Factorian number or Dudeney number. Save 1 in r1 if it is a Factorian number; otherwise, save 0. Save 1 in r2 if it is a Dudeney number; otherwise, save 0. You have to write a single program to test both these conditions.
Write an assembly language program that reverses all the bits of a 32-bit number. (Without using...
Write an assembly language program that reverses all the bits of a 32-bit number. (Without using RBIT instruction) Write an assembly language program that checks whether an unsigned number is perfect square or not.