Question
Using Assembly X86 Intel: Direct Addressing, Input, and ASCII Code. Please leave comments on code --- 4: Direct Addressing, Input, and ASCII code Purpose: basic
Using Assembly X86 Intel:
Direct Addressing, Input, and ASCII Code.
Please leave comments on code
---
4: Direct Addressing, Input, and ASCII code
Purpose: basic input and output mechanisms of the MS-DOS Operating System, the INT instruction, as well as the conversion of ASCII decimal digits received from the keyboard to a binary number to be used in a computation. The conversion of the binary result to ASCII decimal digits to be displayed on the screen. This is mostly about ASCII to binary conversion.
Introduction: This is a sense that instead of input variables X and Y being hard coded by assigning them inside the program, we want to make the program flexible. We do so by letting a user type in the values of the variables from the keyboard. We will assume the numbers are decimal. Since the number typed from the keyboard consists of ASCII decimal digits it has to be converted to decimal and eventually converted to binary before it can be used in computation. There are a number of algorithms that can be used for this conversion but let us look at one example.
Suppose we want to convert the ASCII string 4096. Let us assume AX will be used keep track of the binary value. AX is initialized to zero. As each ASCII digit is read, we multiply AX by 10 and the digits binary value is added to AX. After all digits have been read, AX contains the binary value of the number 4096. Note that the most significant digit is typed first. The following table describes the algorithm.
AX (before) | New Digit | AX (after) |
0 *10 + | 4 | = 4 |
4*10 + | 0 | = 40 |
40*10 + | 9 | = 409 |
409*10 + | 6 | = 4096 |
Procedure: Write an assembly program that receives the variables X and Y from the keyboard instead of being hard coded in the program. It then used in the following computation to determine W which is printed on the screen.
loc DD 0
W DW 0
Sum DW 0
Lines of Code to input X from the Keyboard
Lines of Code to input Y from the Keyboard
loc = Y * 160 + X * 2
Y = 1000
Y = Y 1
Sum = loc/16 + Y +Y/4 + Y/200
W = Sum % 7 + 5
A typical session will look like the following
Input X= 1
Input Y= 1
Output W= 7
Input X= 19
Input Y= 63
Output W= 6
HINTS: Declare variables for strings in the data area. For instance
inputX db Input X=, $
inputY db Input Y=, $
outputW db Output W=, $
Note1: may not use any library functions. Only DOS/BIOS functions can be used.
Note2: program should be able to handle up to 4 digit unsigned decimal numbers for X and Y but instructor will test it for any two digit numbers.
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