Microsoft KB Archive/57369

From BetaArchive Wiki

Passing Two-Dimensional Long Integer Arrays to COBOL

PSS ID Number: Q57369 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 program can pass a two-dimensional array of long integers to a called COBOL routine. This information about interlanguage calling applies to Microsoft COBOL versions 3.00 and 3.00a for MS-DOS.

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 is invoked by an assembly language program and passed a two-dimensional array of long integers: $SET LITLINK $SET ANS85 IDENTIFICATION DIVISION. PROGRAM-ID. "_COBPROG“. DATA DIVISION. WORKING-STORAGE SECTION. 01 I1 PIC 99. 01 J1 PIC 99. LINKAGE SECTION. 01 THE-TABLE OCCURS 2 TIMES. 05 T-FIELD PIC 9(8) COMP-5 OCCURS 3 TIMES. PROCEDURE DIVISION using THE-TABLE. PERFORM VARYING I1 FROM 1 BY 1 UNTIL I1 > 2 PERFORM VARYING J1 FROM 1 BY 1 UNTIL J1 > 3 DISPLAY”Table[" I1 "][" J1 "]: " T-FIELD(I1, J1) END-PERFORM END-PERFORM. STOP RUN. The following program is ASM.ASM, which creates a two-dimensional array of long integers, which is passed to a called COBOL routine: .MODEL LARGE, C .STACK 100h ; create stack for program .DATA Lng11 DD 11 ; create array Lng12 DD 12 Lng13 DD 13 Lng21 DD 21 Lng22 DD 22 Lng23 DD 23 .CODE EXTRN CobProg:PROC MasmProg: mov ax, @DATA ; initialize data segment mov ds, ax mov cx, 1 ; load count mov ax, SEG Lng11 ; put address of first array element push ax ; on stack mov ax, OFFSET Lng11 push ax mov bp, sp ; set up bp for COBOL stack CALL CobProg add sp, 4 ; clean up stack after call mov ax, 4C00h ; terminate process with return code INT 21h ; call MS-DOS to terminate END MasmProg To demonstrate these programs from an .EXE program, compile and link as follows: COBOL COB.CBL; MASM ASM.ASM; LINK COB ASM; COB.EXE produces the following output: Table[01][01]: 000000011 Table[01][02]: 000000012 Table[01][03]: 000000013 Table[02][01]: 000000021 Table[02][02]: 000000022 Table[02][03]: 000000023

Copyright Microsoft Corporation 1990.