91.4k views
0 votes
Answer should be in MIPS please! Please also ensure the code runs and works properly without any errors. Thank you in advanced.

Your program should be able to take one integer values from user input until you enter 0 and program should end if user types in an integer 0.
(The prompt should be Enter an integer: )
2. Store the integer into $t5 and multiply the number by 8 using shift operations (Do not use multiplication). And then print the values of bit number 6 to 10 of $t5. (The rightmost bit is bit 0)
3. You need give detail comments to explain what is happening in the code. The level of detail will be graded.
4. You need to show the result screens for at least five pairs of numbers including negative numbers.
5. You need to use the newlines spaces properly so that the output prints in orderly manner. Your output should look like:
The number you entered:
After it is multiplied by 8:
The bits [6-10] are: (there should be one space between each bit value)
Please Note:
The program first receives user input (integer) and stores it in $t0.
Print the entered number in decimal value
Multiply the number in $t0 and print the number in decimal value
Print the value of Bit #6, 7, 8, 9, and 10 of $t5. (The output should look like: 0 1 1 0 0 )

1 Answer

2 votes

Final answer:

To write a program in MIPS that takes an integer input from the user and multiplies it by 8 using shift operations, you can use the provided code. The program prompts the user to enter an integer, stores it in $t5, multiplies it by 8 using shift operations, and then prints the value of bits 6 to 10 of $t5. The code includes detailed comments to explain each step.

Step-by-step explanation:

To write a program in MIPS that takes an integer input from the user and multiplies it by 8 using shift operations, you can use the following code:

.data
prompt: .asciiz "Enter an integer: "
result_prompt: .asciiz "The number you entered:"
after_multiply_prompt: .asciiz "After it is multiplied by 8:"
bits_prompt: .asciiz "The bits [6-10] are:"


.text

.globl main

main:
# Prompt the user to enter an integer
li $v0, 4
la $a0, prompt
syscall

# Read the integer input from the user
li $v0, 5
syscall

# Store the input integer in $t5
move $t5, $v0

multiply:
# Multiply the number by 8 using shift operations
sll $t5, $t5, 3

# Print the entered number in decimal value
li $v0, 4
la $a0, result_prompt
syscall
li $v0, 1
move $a0, $t5
syscall

# Print the number after being multiplied by 8
li $v0, 4
la $a0, after_multiply_prompt
syscall
li $v0, 1
move $a0, $t5
syscall

# Print the value of bits 6 to 10 of $t5
li $v0, 4
la $a0, bits_prompt
syscall
li $v0, 1
move $a0, $t5
srl $a0, $a0, 6
andi $a0, $a0, 0b0000000000000000000011111
syscall

# Check if the entered number is 0
beqz $t5, exit

# Otherwise, repeat the process
j multiply

exit:
# Exit the program
li $v0, 10
syscall

User Phil Kang
by
8.2k points