Microsoft KB Archive/52175

Passing a Structure from Assembly Language to COBOL

PSS ID Number: Q52175 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 a structure 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. The COBOL routine displays the values of a passed structure. $SET LITLINK IDENTIFICATION DIVISION. PROGRAM-ID. &quot;_COBPROG“. DATA DIVISION. LINKAGE SECTION. 01 REC-1. 05 INTNUM PIC 9(4) COMP-5. 05 LONGNUM PIC 9(8) COMP-5. 05 THESTRING PIC X(8). PROCEDURE DIVISION using REC-1. DISPLAY”Passed INTNUM : &quot; INTNUM. DISPLAY “Passed LONGNUM :” LONGNUM. DISPLAY “Passed THESTRING :” THESTRING. EXIT PROGRAM. The following program is ASM.ASM, which creates a structure that is passed to a called COBOL routine: .MODEL LARGE, C ; COBOL uses C calling convention usrType STRUC ; structure matches one in COBOL iAsm DW 10 lAsm DD 43210 sAsm DB ‘Assembly’ usrType ENDS .STACK 200h .DATA AsmRec usrType <> .CODE EXTRN CobProg:PROC MasmProg: mov ax, @DATA ; initialize data segment mov ds, ax mov cx, 1 ; load count mov ax, SEG AsmRec ; put address of structure on stack push ax mov ax, OFFSET AsmRec 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 for MS-DOS as follows: COBOL COB.CBL; MASM ASM.ASM; LINK ASM COB; COB.EXE produces the following output: Passed INTNUM : 00010 Passed LONGNUM : 000043210 Passed THESTRING : Assembly

Copyright Microsoft Corporation 1990.