Solved

What's the problem here?

Posted on 1998-06-09
7
228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

636 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