Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I ' m struggling to finish this program because I can't get it to print the bits. Every time I try, it gives me an
Im struggling to finish this program because I can't get it to print the bits. Every time I try, it gives me an error. I need assistance in making the program print the bits as per the instructions. Below is my current code along with the instructions and the program's current output..dataprompt: asciiz "Enter a number enter to exit: # Prompt for user inputoutput: asciiz "The number you entered: # Output labelmultiplied: asciiz "After it is multiplied by : # Multiplication labelbitslabel: asciiz "The bits are: # Label for printing bitsnewline: asciiz
# Newline character.textmain: # Infinite loop to keep asking the user for inputmainloop: # Print prompt to enter a number li $v # Load syscall code for printing string la $a prompt # Load address of prompt string syscall # Print prompt # Read integer input from the user li $v # Load syscall code for reading integer syscall # Read integer move $t $v # Store the input number in $t # Exit loop if input is beqz $t exit # Exit loop if otherwise continue # Print the entered number li $v # Load syscall code for printing string la $a output # Load address of output string syscall # Print output label li $v # Load syscall code for printing integer move $a $t # Load the integer to be printed syscall # Print entered number # Print newline character li $v # Load syscall code for printing string la $a newline # Load address of newline character syscall # Print newline # Print label for multiplication result li $v # Load syscall code for printing string la $a multiplied # Load address of multiplication label syscall # Print multiplication label # Multiply the number by using shift operations sll $t $t # Shift left by bits multiply by # Print the multiplied number li $v # Load syscall code for printing integer move $a $t # Load the multiplied number to be printed syscall # Print multiplied number # Print newline character li $v # Load syscall code for printing string la $a newline # Load address of newline character syscall # Print newline # Print label for bits li $v # Load syscall code for printing string la $a bitslabel # Load address of bits label syscall # Print bits label # Print bits of the number with space between each bit li $t # Initialize counter to bit #printbitsloop: addi $t $t # Decrement counter bgez $t loopend # Exit loop if counter is not negative bit # printed andi $t $t # Mask out all bits except the rightmost one li $v # Load syscall code for printing integer move $a $t # Load the bit value to be printed syscall # Print the bit value # Print space between bits li $v # Load syscall code for printing string syscall # Print space j printbitsloop # Repeat until all bits are printedloopend: # Print newline character li $v # Load syscall code for printing string la $a newline # Load address of newline character syscall # Print newline j mainloop # Repeat the main loop # Exit the programexit: li $v # Load syscall code for exit s
Mars Messages
Run
Enter a number enter to exit:
The number you entered:
After it is multiplied by :
The bits are:
Enter a number enter to exit:
program is finished running
yscall # Exit program
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started