Microsoft KB Archive/52096

Passing Common Numerics from COBOL to Assembly by Value

PSS ID Number: Q52096 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 common numeric types to assembly language by value. 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 an integer and long number, by value, to an assembly language program: $SET LITLINK IDENTIFICATION DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. * ASCII value for ‘A’ = 65 01 FIELD1 PIC 9(4) COMP-5 VALUE 65. * ASCII value for ‘B’ in low byte ‘C’ in high byte = 4390978 01 FIELD2 PIC 9(8) COMP-5 VALUE 4390978. PROCEDURE DIVISION. CALL “MasmSub” USING BY VALUE FIELD1, BY VALUE FIELD2. STOP RUN. The following program is ASM.ASM, which prints out the ASCII code of a passed integer and the high and low words of a passed long: .MODEL LARGE .CODE PUBLIC MasmSub MasmSub PROC push bp mov bp, sp push es mov dx, [bp+6] ; get integer mov ah, 02 int 21h ; DOS interrupt to print character mov dx, [bp+8] ; get first part of long int 21h ; DOS interrupt to print character mov dx, [bp+10] ; get second part of long int 21h ; print last ASCII value 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; 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: ABC

Copyright Microsoft Corporation 1990.