Answered step by step
Verified Expert Solution
Link Copied!

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

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 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 0 to exit): " # Prompt for user inputoutput: .asciiz "The number you entered: " # Output labelmultiplied: .asciiz "After it is multiplied by 8: " # Multiplication labelbits_label: .asciiz "The bits [4-1] are: " # Label for printing bitsnewline: .asciiz "
" # Newline character.textmain: # Infinite loop to keep asking the user for inputmain_loop: # Print prompt to enter a number li $v0,4 # Load syscall code for printing string la $a0, prompt # Load address of prompt string syscall # Print prompt # Read integer input from the user li $v0,5 # Load syscall code for reading integer syscall # Read integer move $t1, $v0 # Store the input number in $t1 # Exit loop if input is 0 beqz $t1, exit # Exit loop if 0, otherwise continue # Print the entered number li $v0,4 # Load syscall code for printing string la $a0, output # Load address of output string syscall # Print output label li $v0,1 # Load syscall code for printing integer move $a0, $t1 # Load the integer to be printed syscall # Print entered number # Print newline character li $v0,4 # Load syscall code for printing string la $a0, newline # Load address of newline character syscall # Print newline # Print label for multiplication result li $v0,4 # Load syscall code for printing string la $a0, multiplied # Load address of multiplication label syscall # Print multiplication label # Multiply the number by 8 using shift operations sll $t1, $t1,3 # Shift left by 3 bits (multiply by 8) # Print the multiplied number li $v0,1 # Load syscall code for printing integer move $a0, $t1 # Load the multiplied number to be printed syscall # Print multiplied number # Print newline character li $v0,4 # Load syscall code for printing string la $a0, newline # Load address of newline character syscall # Print newline # Print label for bits li $v0,4 # Load syscall code for printing string la $a0, bits_label # Load address of bits label syscall # Print bits label # Print bits [4-1] of the number with space between each bit li $t2,4 # Initialize counter to 4(bit #4)print_bits_loop: addi $t2, $t2,-1 # Decrement counter bgez $t2, loop_end # Exit loop if counter is not negative (bit #0 printed) andi $t3, $t3,1 # Mask out all bits except the rightmost one li $v0,1 # Load syscall code for printing integer move $a0, $t3 # Load the bit value to be printed syscall # Print the bit value # Print space between bits li $v0,4 # Load syscall code for printing string syscall # Print space j print_bits_loop # Repeat until all bits [4-1] are printedloop_end: # Print newline character li $v0,4 # Load syscall code for printing string la $a0, newline # Load address of newline character syscall # Print newline j main_loop # Repeat the main loop # Exit the programexit: li $v0,10 # Load syscall code for exit s
Mars Messages
Run 1O
Enter a number (enter 0 to exit): 1
The number you entered: 1
After it is multiplied by 8:8
The bits [4-1] are:
Enter a number (enter 0 to exit): 0
-- program is finished running --
yscall # Exit program
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

please dont use chat gpt or other AI 7 5 .

Answered: 1 week ago

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago