Solved

What's the problem here?

Posted on 1998-06-09
7
186 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now