CIS 21JA – Lab 5: Branching and review of arithmetic operations
CIS 21JA – Lab 5: Branching and review of arithmetic operations
Overview
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:
-
Read the user input number and check for valid input.
-
Prompt the user for a number.
-
Check that the input number is within the range of a signed 8-bit.
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.
-
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.
-
Convert the number to binary.
-
Recall from module 1 that to convert from decimal to binary, you keep dividing by 2 to extract one bit at a time
-
You must use a loop to extract each bit. Don’t copy and paste the division code multiple times.
-
Since the user input is 8-bit, use 8-bit division to do the extraction.
-
As you find each bit, convert it to its ASCII character: 0 becomes ‘0’ and 1 becomes ‘1’
-
Store each character in the array of characters that you defined in step 2.
-
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…
-
Call writeString and print the resulting text string to screen. See the sample output.
-
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
SAMPLE ASSIGNMENT