Microsoft KB Archive/35511

Passing Parameters to Assembly Routine; Check Printer Status

PSS ID Number: Q35511 Article last modified on 04-21-1993

3.00 | 3.00 MS-DOS | OS/2

Summary: The following COBOL Version 3.0 sample program calls an assembly language subprogram which checks the printer status. When passing parameters to an assembly language, you must allow for 4 bytes to be pushed on the stack for each parameter. First the segment, then the offset, gets pushed on.

More Information: Compile Step: cobol cobprog.cob litlink; Link Step: link cobprog adis adisinit adiskey asm.obj; The code example is as follows:

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   This sample program calls an assembly language subprogram * *  which checks the printer status. The printer status is  * *  put into PASS-VAR1, and PASS-VAR2 and PASS-VAR3 are set   * *  in the assembly code to 55 and 99, respectively. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 PASS-VAR1         PIC 9(4)    USAGE COMP-0 VALUE 0. 01 PASS-VAR2         PIC 9(4)    USAGE COMP-0 VALUE 0. 01 PASS-VAR3         PIC 9(4)    USAGE COMP-0 VALUE 0. 01 TEMP-VAR          PIC XX. PROCEDURE DIVISION. 0000-MAIN. DISPLAY &quot;Checking the printer status...&quot; AT 0310 WITH BLANK SCREEN. CALL &quot;prntstat&quot; USING PASS-VAR1, PASS-VAR2, PASS-VAR3. DISPLAY &quot;The printer status is: &quot; AT 0510 PASS-VAR1. DISPLAY &quot;AND THE DUMMIES: &quot; AT 0710 PASS-VAR2 &quot; &quot; PASS-VAR3. ACCEPT TEMP-VAR. STOP RUN. Parameters are passed on the stack using a 4-byte address. The 4 bytes consists of a 2-byte segment and a 2-byte offset placed on the stack in that order. This means that the 2-byte offset will be nearer to the top of the stack. COBOL also pushes the parameters in reverse order from what is specified when the assembly routine is CALLed. This means that the first parameter in the parameter list will be placed on the stack last and therefore be nearest to the top of the stack. After pushing bp, the parameters may be accessed starting at the sixth byte of the stack and continuing in 4-byte increments (i.e., [bp+6],[bp+10],[bp+14]…). If the size of the COBOL data segment does not exceed 64K, the segment portion of the address usually can be ignored. The following is the prntstat assembler routine:

.MODEL large .CODE public prntstat ;make routine visible to COBOL prntstat proc far ;declare it as a far call push bp ;save value of bp mov bp,sp ;load bp with top of stack mov si,[bp+14] ;get address of 3rd parameter mov byte ptr [si+1],55 ;change value to 55 mov si,[bp+10] ;get address of 2nd parameter mov byte ptr [si+1], 99 ;change value to 99 mov si,[bp+6] ;get address of 1st parameter mov ah,02h ;function 2 - get printer status mov dx,0 int 17h ;make function call mov byte ptr [si+1],ah ;status is placed in low byte of ;1st parameter mov byte ptr [si],0 ;zero out high byte of parameter pop bp ;restore bp ret 12 ;restore stack prntstat endp end

Additional reference words: 3.00 Copyright Microsoft Corporation 1993.