Microsoft KB Archive/52174

From BetaArchive Wiki

Passing an Array of Integers from Assembly to COBOL

PSS ID Number: Q52174 Article last modified on 11-30-1990

3.00 3.00a MS-DOS

Summary: The two programs shown below demonstrate how a Microsoft assembly language program can pass an array of 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, query in the Software/Data Library on the following word: COBMIXED

Code Example

The following COBOL program is COB.CBL, which is invoked by an assembly language program and is passed an array of integers. The integers are then displayed. $SET LITLINK IDENTIFICATION DIVISION. PROGRAM-ID. "_COBPROG“. DATA DIVISION. LINKAGE SECTION. 01 T-COUNT PIC 99. 01 THE-TABLE PIC 9(4) COMP-5 OCCURS 5 TIMES. PROCEDURE DIVISION using THE-TABLE. PERFORM PRINT-TABLE-VALUE VARYING T-COUNT FROM 1 BY 1 UNTIL T-COUNT > 5. STOP RUN. PRINT-TABLE-VALUE. DISPLAY”Table[" T-COUNT "] : " THE-TABLE(T-COUNT). The following program is ASM.ASM, which creates a one-dimensional array of integers that is passed to a called COBOL routine: .MODEL LARGE, C .STACK 100h ; create program stack .DATA Int1 DW 1 ; create integer array to pass Int2 DW 2 Int3 DW 4 Int4 DW 8 Int5 DW 16 .CODE EXTRN CobProg:PROC MasmProg: mov ax, @DATA ; initialize data segment mov ds, ax mov cx, 1 ; load count mov ax, SEG Int1 ; put address of first array element push ax ; on stack mov ax, OFFSET Int1 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] : 00001 Table[02] : 00002 Table[03] : 00004 Table[04] : 00008 Table[05] : 00016

Copyright Microsoft Corporation 1990.