Question
MIPS/SPIM programming using the data provided Your program is to print the binary representation of a decimal number using a divide by 2 conversion routine.
MIPS/SPIM programming using the data provided
Your program is to print the binary representation of a decimal number using a divide by 2 conversion routine.
1. Use syscall 4 to prompt for a number between -128 and 127 as listed in the data declaration label prompt:
2. Input a number (using syscall 5)
3. If the number is not within the limits, print message at label err: and try again.
4. Convert this decimal number to binary and output its binary representation to the console using divide by 2 method.
4a. Push each remainder on the stack then pop them and print them using syscall 1. A header as listed in the data declaration label ans: should precede that.
4b. The magnitude of the number will always be 8 bits with MSB =1 for negative numbers and 0 for positive numbers.
5. The program will continue prompting for a number as long as y is entered when prompted as listed in the data declaration label newin:
5a. If any other character is entered, the program prints the message at label term: in the data declaration and exits the program.
Hint: The 8-bit binary representation of a negative number m is the same as that of positive number equal to 256 + m.
The beginning of the program and the data declaration are given below
# Program to convert a number between -128 and 127 to its binary equivalent and
# outputs its binary representation to the console.
.text
main:
.data
prompt: .asciiz " Input a decimal number between -128 and 127: "
ans: .asciiz " Binary representation is "
err: .asciiz " input error - try again!"
term: .asciiz " Program terminated"
newin: .asciiz "Do you want to try another number? (y for yes) "
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