Microsoft KB Archive/52171

Passing a PIC X String from COBOL to Assembly Language

PSS ID Number: Q52171 Article last modified on 11-30-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 PIC X string by reference 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 invokes an assembly language routine that modifies a passed PIC X string. The COBOL program then displays the returned string. $SET LITLINK IDENTIFICATION DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 FIELD1 PIC X(10). PROCEDURE DIVISION. CALL “MasmStr” USING FIELD1. DISPLAY “Returned PIC X:” FIELD1. STOP RUN. The following program is ASM.ASM, which copies the word “Assembly” into a passed COBOL string: .MODEL LARGE .DATA AsmStr DB ‘Assembly’ .CODE PUBLIC MasmStr MasmStr PROC push bp mov bp, sp push es push di push si mov ax, [bp+8] ; get segment of string mov es, ax mov di, [bp+6] ; get offset of string mov si, OFFSET AsmStr ; set up for copy mov ax, SEG AsmStr mov ds, ax mov cx, 8 ; number of bytes to copy rep movsb ; copy assembly string to COBOL string pop si pop di pop es pop bp ret MasmStr 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; Compile and link for OS/2 protected mode as follows: PCOBOL COB.CBL; MASM ASM.ASM; LINK COB ASM /NOP /NOD,,,PCOBOL+DOSCALLS; COB.EXE produces the following output: Returned PIC X: Assembly

Copyright Microsoft Corporation 1990.