Solved

What's the problem here?

Posted on 1998-06-09
7
220 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

713 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