Microsoft KB Archive/58827

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

DSPACE.ASM from COBOL 2.x User’s Guide Is Incomplete; Hangs

PSS ID Number: Q58827 Article last modified on 04-20-1993

2.00 2.10 2.20 MS-DOS

The information in this article applies to:
- Microsoft COBOL for MS-DOS, versions 2.0, 2.1, and 2.2

Summary: Four lines are missing from the bottom of the assembly language program DSPACE.ASM on Pages 103-104 of the “Microsoft COBOL Compiler for MS-DOS: User’s Guide” for Versions 2.0, 2.1, and 2.2. The assembly routine, when assembled as the book states, often hangs the machine. You must add the following lines after the “spret:” label: spret: pop bp ret END_CSEG DSPACE END

More Information:

The complete corrected code for DSPACE.ASM is as follows: ;********************************************* ; Contains a routine to call the MS-DOS Get ; Free Disk Space function. Zero is returned ; in the third parameter in case of error. ;********************************************* include userseg.mac ; ;Structure for accessing parameters on stack ; DYNS2 STRUC DW ? ;Pushed BP. DD ? ;Long return address. ARG3 DW ? ;Parameter number 3. ARG2 DW ? ;Parameter number 2. ARG1 DW ? ;Parameter number 1. DYNS2 ENDS MSDOS EQU 21H ;standard MS-DOS entry point SPACE EQU 36H ;get disk free space function START_DSEG DSPACE savbc dw ? ;bytes per disk cluster savdx dw ? ;temporary register area END_DSEG DSPACE START_CSEG DSPACE push bp ;use bp to point to arguments mov bp,sp mov bx,[bp].arg1 ;get addr of arg1 (drive number) mov dx,[bx] ;get drive to dl xchg dh,dl ;COBOL COMP-0 bytes reversed mov ah,SPACE ;call MS-DOS function INT MSDOS ;on return: ; bx = # of free clusters on drive ; dx = total # of clusters on drive ; cx = bytes of sector ; ax = sectors per cluster or FFFF if error cmp ax, 0FFFFH ;error? jz error mov savdx,dx ;multiply wipes out dx, so save it mul cx ;bytes/clusters in ax jc error ;should never overflow, but… mov savbc,ax ;save for later use mul bx ;low order result in ax, ;high order in dx mov bx,[bp].arg2 ; get addr od COMP-4 free space ; store 4 byte value in this order: ; least significant word (in dx), ; then most significant word (in ax) ; with bytes of each word reversed xchg dh,dl ;COBOL COMP-0 bytes reversed mov [bx],dx xchg ah,al ;COBOL COMP-0 bytes reversed mov [bx+2],ax mov ax,savbc ;restore ax and dx mov dx,savdx mul dx ;low order result in ax, ;high in dx mov bx,[bp].arg3 ;get addr of COMP-4 total space ;store 4 byte variable xchg ah,al ;COBOL COMP-0 bytes reversed mov [bx+2],ax jmp spret ;done… error: xor ax,ax ;zero arg3 to indicate error mov bx,[bp].arg3 mov [bx],ax mov [bx+2],ax ;**** modified lines follow: spret: pop bp ret END_CSEG DSPACE END

Additional reference words: 2.00 2.10 2.20 Copyright Microsoft Corporation 1993.