Solved

What happened in this cleanup procedure?

Posted on 1998-06-13
2
159 Views
Last Modified: 2011-08-18
Dear All,
     I've got a C program which also contains assembly code.
The 'C' program first calls an assembly routine that does mode setting job. The program have to gain access to a data segment, so I did this mov ax, seg_b and mov ds, ax at the beginning.but when I add these statments into the assembly routine,then there comes some problems concerning the cleanup procedure. If I deleted them, the program works fine.
Why did this happen?

Jacky
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
  • 2
2 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1165830
The code expects that DS will still be pointing to the segment it originally was.  Just restore the original DS when you are done with the assembly and you will be fine.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1165831
I believe that many 16 bit compilers assume that DS will always point to a segment called _TEXT.  I'm not sure of the details about that, though.  Your best bet is to save and restore DS and ES around any procedure that messes with it.  You also might need to save and restore SI and DI, some compilers assume they will not change as well.
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

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…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 learn how to clear a vector as well as how to detect empty vectors in C++.

728 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