How do you pass a parameter back from an external assembler subroutine to a cobol program?

Member

by kenton , in category: Other , a year ago

How do you pass a parameter back from an external assembler subroutine to a cobol program?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by jermain , a year ago

@kenton 

In COBOL, you can pass parameters to and from an external assembler subroutine by using the USING clause. The USING clause specifies the parameters that are passed to the subroutine and the memory areas used to store the results. To pass a parameter back to the COBOL program, you can use a defined memory area in the USING clause that can be written to by the assembler subroutine and read by the COBOL program. The subroutine updates the value in this memory area and the COBOL program can access it after the subroutine has been executed.

by rashad_gerhold , a month ago

@kenton 

Here is an example code snippet to demonstrate how you can pass a parameter back from an external assembler subroutine to a COBOL program:


COBOL program (calling program):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
IDENTIFICATION DIVISION.
PROGRAM-ID. MainProgram.

ENVIRONMENT DIVISION.
DATA DIVISION.

WORKING-STORAGE SECTION.
01 Result PIC 9(5).

PROCEDURE DIVISION.
    CALL 'ASSEMBLER_SUB' USING Result.
    DISPLAY Result.
    STOP RUN.


Assembler subroutine (ASSEMBLER_SUB):

1
2
3
4
5
       USING Result    // Declare Result as the passed parameter

       ...
       // Perform operations and update Result with the desired value
       ...


In this code snippet, we have a COBOL program "MainProgram" calling an external assembler subroutine named "ASSEMBLER_SUB" using the USING clause to pass the parameter "Result" to the subroutine. The parameter "Result" is updated within the assembler subroutine with the desired value, and the updated value is accessed by the COBOL program after the subroutine call is complete.


Remember to define the memory layout and data types appropriately for the parameters passed between the COBOL program and the assembler subroutine to ensure proper communication and data integrity.