Solved

What's the problem here?

Posted on 1998-06-09
7
206 Views
Last Modified: 2012-05-04
I have a DOS program written in a mix of C and Assembly.
I traced the program from the start to the end with Turbo Debugger...
But when the program reached the end which contained the code mov ah,4ch and mov al, 0 and int 21h the computer hanged up.
When I started it on a DOS session from win95, it exits abruptly to Windows when it reached the end.
I also checked the hexcode of the program and it appeared to be alright to me.
Can you give any suggestions?
0
Comment
Question by:whluk
  • 4
  • 3
7 Comments
 
LVL 2

Expert Comment

by:kinkajou
ID: 1165510
Are you getting this hang up in DOS-only mode (ie not a DOS session under windows)?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1165511
The problem is occurring after the program terminates, but it probably is caused by somethign you did before that.  (Possibly long before that.)

Considering the timing og the error and the fact it has assembly code, you might want to use a hardware debugger, like Soft-Ice or periscope.  They will alow you to find the instruction that is experiencing the problem.  The fault is occuring somewhere in the OS, but it probably is not a bug in the OS, but a bug in your program so you will have to work backward from there.

I you don't have access to a hardware, debugger, you can try commenting out portions of the program to see what it is that is causing the problem.
0
 
LVL 2

Accepted Solution

by:
kinkajou earned 20 total points
ID: 1165512
It is my impression that the terminate program (mov ax,004Ch int 21h) will not work correctly when Windows is running in the background (ie your program is running in a DOS window). At best, terminate program will give varying results. Try running the program only in DOS and see if you get the same results. You will need to terminate your program another way. Try using "exit( 0 );"  exit() performs the complete C library termination procedures, terminates the process, and exits  with the supplied status code.
 

0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 22

Expert Comment

by:nietod
ID: 1165513
The terminate function is fine in windows.  All DOS programs terminate that way.  Following the interrupt, DOS tries to clean up and that is where the exception is taking place.  It closes open files and that sort of stuff.  One interesting problem is that if the console cursor has been moved off the screen, like to column 81 when there are only 80 columns, you will get a lock up.
0
 
LVL 2

Expert Comment

by:kinkajou
ID: 1165514
I suggest exit() at the end of your program because it does the necessary clean up properly for CUI applications and is what I use. If exit() is an inappropriate answer, reject my answer and let everyone else in on fixing this problem for you.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1165515
Actually, I wasn't clear in my response.  The terminate app function int 21, function 4CH will not cause a problem.  But it isn't the best way to exit a C application.  As you mentioned, it does not give the C libraries a chance to clean up.  You should exit a C program with exit or by returning from main().  However, exiting using the DOS interrupt should not cause a problem, its just not a good idea.  (In fact, the exit() procedure will eventually call the DOS terminate interrupt.)
0
 
LVL 2

Expert Comment

by:kinkajou
ID: 1165516
I regarded you question as a "I have trouble ending a DOS app". You have mentioned cursor troubles. Can you be more specific about the exact problem you are having.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question