Microsoft KB Archive/52094

Passing COBOL Record to Assembly Language by Reference

PSS ID Number: Q52094 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 a record to an assembly language program. 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 passes a record to an assembly language program by reference. After returning, the record is displayed. $SET LITLINK IDENTIFICATION DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 REC-1. 05 INTNUM PIC 9(4) COMP-5 VALUE 1. 05 LONGNUM PIC 9(8) COMP-5 VALUE 123456. 05 THESTRING PIC X(8) VALUE “COBOL”. PROCEDURE DIVISION. CALL “MasmSub” USING REC-1. DISPLAY “Returned INTNUM :” INTNUM. DISPLAY “Returned LONGNUM :” LONGNUM. DISPLAY “Returned THESTRING :” THESTRING. STOP RUN. The following program is ASM.ASM, which copies a predefined structure into a passed COBOL record: .MODEL LARGE usrType STRUC ; structure matches on in COBOL iAsm DW 10 lAsm DD 43210 sAsm DB ‘Assembly’ usrType ENDS .DATA AsmRec usrType <> .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 AsmRec ; set up for copy mov ax, SEG AsmRec mov ds, ax mov cx, 14 ; number of bytes to copy 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 MS-DOS as follows: COBOL COB.CBL; MASM ASM.ASM; LINK COB ASM; For OS/2 protected mode, compile and link as follows: PCOBOL COB.CBL; MASM ASM.ASM; LINK COB ASM /NOP /NOD,,,PCOBOL+DOSCALLS; COB.EXE produces the following output: Returned INTNUM : 00010 Returned LONGNUM : 000043210 Returned THESTRING : Assembly

Copyright Microsoft Corporation 1990.