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
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.
Write an Assembly program that will produce all divisors for a 1-digit decimal number. For example,...
Write an Assembly program that will produce all divisors for a 1-digit decimal number. For example, if the number is 6, then the outputs will be 1,2,3,6 which are the divisors of 6. ASSEMBLY program
VII. After execution of the following instructions what value will be in register r2? Trace the...
VII. After execution of the following instructions what value will be in register r2? Trace the program and write the value of the registers at each line to receive full credit. LDR r12, =0xA4000000 LDR r0, =0x2D STR r0, [r12, #-4]! LDR r0, =0x5E STR r0, [r12, #-4]! LDR r0, =0xD5 STR r0, [r12, #-4]! LDMIA r12!, {r0-r2} SUB r2, #0x68 VIII. Write a simple ARM assembly program to divide a 32 bit positive number stored in r0 by a...
Write a program that finds the largest number among two numbers and store the result in...
Write a program that finds the largest number among two numbers and store the result in any register. Value1: 0x18345678 (hexidecimal) Value2: 0x15678245 (hexidecimal) (Code in ARM assembly language, Using Keil software)
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT