Main program to test the basic operations, C/C++ Programming

The Main program is slightly more complicated and you need to think about the I/O process. First of all, for most applications you do not call the low level routines GetChar and PutChar. They are used by the higher level I/O subroutines that you wrote for reading and writing strings and numbers.

Secondly, you cannot just call an input routine like GetStr or GetNum on its own. Think carefully about what would happen. Let's say at some point in your program you want to read a number from the keyboard and place it in a memory location. Consider the following code fragment:

MyNum: dw

Main:
...
...
call GetNum
mov MyNum1, ax

This code will assemble and run and when you enter a number and press ‘Enter' it will store the number at location MyNum. However, how does the person running the program know when to enter a number, or whether to enter a number or a string? When subroutine GetNum is called it will simply wait for input from the keyboard. But the program gives no indication that it is waiting for input! The simple answer is that you must always first write a string to the screen asking for the kind of input you want the user to enter, then call the appropriate input routine. So, our revised program should look like this:

Prompt1: db ‘Enter a number less than 65536:

MyNum: dw
Main:
...
...
Mov ax, Prompt1
Call PutStr
call GetNum
mov MyNum1, ax

Now when the program runs it first prints a message asking for a number and then waits for input. Try this out - if you have written your routines correctly, I think you will like the way this works.

Posted Date: 3/26/2013 2:04:54 AM | Location : United States







Related Discussions:- Main program to test the basic operations, Assignment Help, Ask Question on Main program to test the basic operations, Get Answer, Expert's Help, Main program to test the basic operations Discussions

Write discussion on Main program to test the basic operations
Your posts are moderated
Related Questions
I have a very confusing assignment and I''m struggling to find the right place to begin or how to break the problem down.

Write a program that writes your name on the monitor ten times. Write this program three times, once with each looping method.

Can I drop the [] while deleteing array of some built-in type (char, int, etc)? A: No. you can't Sometimes programmers think that the [] in the delete[] p only present so the

In this problem you are given a board in which some of the elements are placed as shown in diagram below. Each element represents a color. Fill the other elements in the board, suc

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Q: How the compiler arranges the several sections in the executable image? A: The executable contained following sections: 1.      Data Section (initialized data variable sec

Homework – Chapter 5 – Bowling Scores 33. Write a complete C++ program to do the following: The main program reads in and prints three bowling scores, score1, score2, and score

New data members  New member functions  New constructors and destructor  New friends

With this assignment you will build a toy program that manipulates pointers to integers. You will develop the same main program fragment in both C and Assembler. Thus, you'll get t

Hi I''m trying to connect to CISCO router using termios. So I decided to have two threads one for reading data and the other one for writing data. The problem is that I have to add