Microsoft KB Archive/57361

From BetaArchive Wiki

Sample Assembly Function Returning an Integer to COBOL

PSS ID Number: Q57361 Article last modified on 12-06-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 an 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 integer value returned by that function: $SET LITLINK $SET RTNCODE-SIZE(2) IDENTIFICATION DIVISION. DATA DIVISION. PROCEDURE DIVISION. CALL “MasmFunc”. DISPLAY “Returned From Function:” RETURN-CODE. STOP RUN. The following program is ASM.ASM, which passes an integer back to the calling COBOL program: .MODEL LARGE .CODE PUBLIC MasmFunc MasmFunc PROC push bp mov bp, sp mov ax, 123 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: +0123

Copyright Microsoft Corporation 1990.