Microsoft KB Archive/57360

Assembly Function Returning Long Integer to COBOL

PSS ID Number: Q57360 Article last modified on 12-07-1990

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

Summary: The two programs shown below demonstrate how a Microsoft assembly language function can return a long integer to COBOL. This information about interlanguage calling applies to Microsoft COBOL versions 3.00 and 3.00a for MS-DOS and MS OS/2.

More Information: For more examples of passing other types of parameters between COBOL and assembly language, query on the following word: COB2MASM For a complete discussion about mixed-language programming with COBOL, search in the Software/Data Library for the following word: COBMIXED

Code Example
The following COBOL program is COB.CBL, which invokes an assembly language function and prints out the long integer value returned by that function: $SET LITLINK $SET RTNCODE-SIZE(4) IDENTIFICATION DIVISION. DATA DIVISION. PROCEDURE DIVISION. CALL “MasmFunc”. DISPLAY “Returned From Function:” RETURN-CODE. STOP RUN. The following program is ASM.ASM, which passes a long integer back to the calling COBOL program: .MODEL LARGE .DATA Dbl DD 98765 .CODE PUBLIC MasmFunc MasmFunc PROC push bp mov bp, sp ; set up stack frame push ds mov ax, @DATA ; get our data segment mov ds, ax mov bx, OFFSET Dbl ; get address of long mov ax, [bx] ; get low byte of long mov bx, [bx+2] ; high byte pop ds pop bp ret MasmFunc ENDP END To demonstrate these programs from an .EXE program, compile and link for DOS as follows: COBOL COB.CBL; MASM ASM.ASM; LINK COB ASM; Compile and link for OS/2 as follows: PCOBOL COB.CBL; MASM ASM.ASM; LINK COB ASM /NOP /NOD,,,PCOBOL+DOSCALLS; COB.EXE produces the following output: Returned From Function: +000098765

Copyright Microsoft Corporation 1990.