Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

What's the problem here?

Posted on 1998-06-09
7
Medium Priority
?
237 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 40 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

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!

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.
Suggested Courses

877 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