Microsoft KB Archive/57371

Passing a Two-Dimensional Array of Structures to MASM

PSS ID Number: Q57371 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 COBOL program can pass a two-dimensional array of structures to an assembly language routine. 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 routine that initializes a passed two-dimensional array of structures. After returning, the COBOL program displays the values returned from the assembly language routine. $SET ANS85 $SET LITLINK IDENTIFICATION DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 I1 PIC 9. 01 J1 PIC 9. 01 THE-TABLE. 02 T-TABLE OCCURS 2 TIMES. 05 T-FIELD OCCURS 3 TIMES. 10 FIELD1 PIC 9(4) COMP-5. 10 FIELD2 PIC X(6). PROCEDURE DIVISION using THE-TABLE. CALL “MasmSub” 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[&quot; I1 &quot;][&quot; J1 &quot;]:” FIELD1(I1, J1) DISPLAY &quot; &quot; FIELD2(I1, J1) END-PERFORM END-PERFORM. STOP RUN. The following program is ASM.ASM, which initializes a two-dimensional array of structures passed from COBOL: .MODEL LARGE usrType STRUC ; structure matches one in COBOL iAsm DW ? sAsm DB ’ ’ usrType ENDS .DATA AsmRec11 usrType <11, ‘Asm-11’> AsmRec12 usrType <12, ‘Asm-12’> AsmRec13 usrType <13, ‘Asm-13’> AsmRec21 usrType <21, ‘Asm-21’> AsmRec22 usrType <22, ‘Asm-22’> AsmRec23 usrType <23, ‘Asm-23’> .CODE PUBLIC MasmSub MasmSub PROC push bp mov bp, sp push es push di push si mov ax, [bp+8] ; get segment of structure mov es, ax mov di, [bp+6] ; get offset of structure mov si, OFFSET AsmRec11 ; set up for copy mov ax, SEG AsmRec11 mov ds, ax mov cx, 48 ; number of bytes to copy = 8  ; 2  3 rep movsb ; copy assembly rec to COBOL rec pop si pop di pop es pop bp ret MasmSub 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: Table[1][1]: 00011 Asm-11 Table[1][2]: 00012 Asm-12 Table[1][3]: 00013 Asm-13 Table[2][1]: 00021 Asm-21 Table[2][2]: 00022 Asm-22 Table[2][3]: 00023 Asm-23

Copyright Microsoft Corporation 1990.