Microsoft KB Archive/27207

DS Register Used Instead of DX with Getmqq in Pascal 3.32 PSS ID Number: Q27207 Article last modified on 03-01-1991 PSS database name: S_PasCal

3.32 | 3.32

MS-DOS | OS/2

Problem:

My program uses the long heap allocation function Getmqq, and the address returned is assigned to a record field of ADS type. My program compiled, linked, and ran without error messages, but I received incorrect results. Looking at the .COD file, I noticed that the BX register was initially loaded with the correct value. Farther down in the .COD file the DX register was used to do some other work; however, instead of pushing DX onto the stack first to save its contents, the DS register was being pushed for no apparent reason, then the BX register was corrupted.

I have never had this problem before and looking at the .COD files for numerous other programs I have, I do not see this problem behavior. In fact, I do not see it with the slightly modified versions of the program that does have the problem.

Response:

Your program demonstrated a code-generation problem with Pascal version 3.32. This problem is corrected in Microsoft Pascal version 4.00.

To work around this problem in version 3.32, assign the address returned by function Getmqq to a temporary variable of ADS type. Then assign the temporary variable to the field of the record.

With your program, the problem disappeared with almost any modification to the source code. Adding Writelns, or calculations and assignments before or after the call to Getmqq, also results in correct code.

Copyright Microsoft Corporation 1991.