Convert this decimal number to binary and output its binary


This program is to print the binary representation of a decimal number using a divide by 2 conversion routine and the Stack. This program should be written in MIPS/QtSpim

1. Use syscall 4 to prompt for a number between -128 and 127 (0 will terminate the program)

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.

5. Push each remainder to the stack until 8 digits are stored then pop them to output the result with syscall 1 after an answer header as listed in the declaration.

6. The magnitude of the number will always be 8 bits with MSB =1 for negative numbers and 0 for positive numbers.

7. The program will continue prompting for a number until 0 is entered. If number 0 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 the positive number (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 "\n Input a decimal number between -128 and 127 (0 to exit): "

answer: .asciiz "\n Binary representation is "

err: .asciiz "\n input error - try again!"

term: .asciiz "\n Program terminated"

Request for Solution File

Ask an Expert for Answer!!
Other Engineering: Convert this decimal number to binary and output its binary
Reference No:- TGS02900775

Expected delivery within 24 Hours