Microsoft KB Archive/52097

From BetaArchive Wiki

Passing Common Numerics from COBOL to Assembly by Reference

PSS ID Number: Q52097 Article last modified on 12-06-1990

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

Summary: The two programs below demonstrate how a Microsoft COBOL program can pass common numeric types to an assembly language routine by reference. 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 that will alter the passed numeric values. The COBOL program will then display the returned values. $SET LITLINK IDENTIFICATION DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 FIELD1 PIC 9(4) COMP-5 VALUE 123. 01 FIELD2 PIC 9(8) COMP-5 VALUE 123456. PROCEDURE DIVISION. CALL “MasmSub” USING FIELD1, FIELD2. DISPLAY “Returned PIC 9(4):” FIELD1. DISPLAY “Returned PIC 9(8):” FIELD2. STOP RUN. The following program is ASM.ASM, which accepts an integer and a long. The integer is multiplied by two, and the long is added to 65,536. The new values are then passed back to COBOL: .MODEL LARGE .CODE PUBLIC MasmSub MasmSub PROC push bp mov bp, sp push es mov es, [bp+8] ; get segment of integer mov bx, [bp+6] ; get offset of integer mov ax, es:[bx] ; get actual integer shl ax, 1 ; multiply by 2 mov es:[bx], ax ; put back new value mov es, [bp+12] ; get segment of long mov bx, [bp+10] ; get offset of long mov ax, es:[bx+2] ; get high word of long inc ax ; add 1 to high word (add 65,536) mov es:[bx+2], ax ; put back new value pop es pop bp ret MasmSub ENDP END To demonstrate these programs from an .EXE program, compile and link for MS-DOS as follows: COBOL COB.CBL; MASM ASM.ASM; LINK COB ASM; Compile and link for OS/2 protected mode as follows: PCOBOL COB.CBL; MASM ASM.ASM; LINK COB ASM /NOP /NOD,,,PCOBOL+DOSCALLS; COB.EXE produces the following output: Returned PIC 9(4): 00246 Returned PIC 9(8): 00188992

Copyright Microsoft Corporation 1990.