Question: Assembly Language, please add comments explaining coding Write a program that converts a signed decimal number to binary and prints the binary result as a

Assembly Language, please add comments explaining coding

Write a program that converts a signed decimal number to binary and prints the binary result as a numeric text string. Details The program does the following 5 steps:

1. Read the user input number and check for valid input.

  1. Prompt the user for a number.

  1. Check that the input number is within the range of a signed 8-bit integer..

If the input number is larger or smaller than the signed 8-bit range, print an error message to tell the user the range of values, then loop back and re-prompt.

2. Create an array of characters (a text string) that will be used to store all the bits as characters ('1' or '0'), a space character in the middle of the 8 bits, and the null termination character. See the sample output.

3. Convert the number to binary.

  1. Recall from module 1 that to convert from decimal to binary, you keep dividing by 2 to extract one bit at a time

  1. You must use a loop to extract each bit. Don't copy and paste the division code multiple times.

  1. Since the user input is 8-bit, use 8-bit division to do the extraction.

  1. As you find each bit, convert it to its ASCII character: 0 becomes '0' and 1 becomes '1'

  1. Store each character in the array of characters that you defined in step 2.

  1. Accessing an element of an array is similar as in HLL: arr[0] is the first element, arr[3] is the 4th element, etc. The index value 0,1,2.. can be stored in a 32-bit register: arr[ecx] for example, where ecx can be 0,1,2...

4. Call writeString and print the resulting text string to screen. See the sample output.

5. After printing the text string, loop back to prompt the user for another number.

The loop ends when the user enters 0.

When the loop ends, print a "goodbye" message before ending the program.

Additional requirements, don't miss them:

  • Don't use any memory variables other than for text strings. Store all numeric data in registers. The available registers are: EAX, EBX, ECX, EDX, EBP, ESI, EDI and their smaller sizes: AL, BH...

  • You must use writeString to print the binary string output. Using writeBin means an automatic 5 point deduction.

  • Don't use bit-wise instructions (shift, and, or...) for this lab.

  • Don't use the decision directives of MASM. Implement loops and if statements with assembly instructions.

  • Keep your logic flow as simple as you can. Use "fall through" logic as shown in the class notes or the book.

  • Document your program to get full credit: your name at the top of the file, and optionally explain your loop and if statements.

Testing

Test your result adequately: with valid small and large input, positive and negative input, and invalid input

Sample output

Enter a number within 8 bits: 2000

Must be between -- and -- ; the range has been removed so you can fill them in

Enter a number within 8 bits: -3

1111 1101 ; note the space in the middle of the 8 bits

Enter a number within 8 bits: 2

0000 0010

Enter a number within 8 bits: -800

Must be between -- and --

Enter a number within 8 bits: 0

Goodbye

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!