AI and mainframe assembler

Generate a program to write a record to a file



Prompt:
 
Generate a HLASM Program that opens a file for output, writes a record and closes the file 
- The DD name for the file is SYSPRINT. 
- SYSPRINT is a LRECL=80 RECFM=F file
- Use QSAM for the access method 
- Write one record with "Hello World"  
- Use consise comments to explain what the code is doing. 
- Comments should be in mixed case 
- Comments that don't start in column 1 should not start with "*"
- Generated code and comments should not exceed 71 bytes  
- Do not put an instruction on the same line as a label 


ChatGPT generated this program:
HELLOPGM START 0                              
          USING *,15             Base register  
          OPEN  (OUTDCB,(OUTPUT)) Open SYSPRINT for output
          MVC   OUTREC,=CL80'Hello World' Move "Hello World" to record
          PUT   OUTDCB,OUTREC    Write the record
          CLOSE (OUTDCB)         Close the SYSPRINT file
          RETURN (14,12),RC=0    Return to caller
          END   HELLOPGM         End of program

OUTDCB    DCB   DDNAME=SYSPRINT,DSORG=PS,MACRF=PM,        +
               RECFM=F,LRECL=80     Define output DCB      

OUTREC    DS    CL80             Output record buffer         

My comments:


Grok was not tested.


Gemini generated this program:
HELLOWLD CSECT
*
* This program demonstrates basic file output using QSAM.
* It opens SYSPRINT, writes one record, and closes it.
*
* Standard entry linkage: save registers and establish a base
         STM   14,12,12(13)     Save the caller's registers
         BALR  12,0             Load the current address into R12
         USING *,12             Tell the assembler R12 is the base
*
* Open the SYSPRINT file, specifying it's for output
         OPEN  (SYSPRINT,(OUTPUT))
*
* Write the pre-defined record to the file
         PUT   SYSPRINT,HELLOREC
*
* Close the file now that we are done with it
         CLOSE (SYSPRINT)
*
* Standard exit linkage: restore registers and return
         L     13,4(13)         Restore the caller's save area
         LM    14,12,12(13)     Restore the original registers
         SR    15,15            Set a return code of 0 (success)
         BR    14               Branch back to the caller
*
* Define the Data Control Block (DCB) for the SYSPRINT file
SYSPRINT DCB   DSORG=PS,MACRF=PM,DDNAME=SYSPRINT,RECFM=F,LRECL=80
*
* Define the output record constant
HELLOREC DC    CL80'Hello World'
*
         END   HELLOWLD

My comments:


Copilot generated this program:
HELLOPG  START
         OPEN   (SYSPRINT,OUTPUT)     OPEN file for output
         USING  *,15                  Establish addressability
         MVC    OUTREC,=C'Hello World'Move text to output buffer
         PUT    SYSPRINT,OUTREC       Write buffer to file
         CLOSE  SYSPRINT              Close the file
         END    HELLOPG               End of program

OUTREC   DS     CL80                  Output record buffer

My comments:


Claude generated this program:
HELLO    CSECT                        Main program entry point
         STM   R14,R12,12(R13)           Save registers
         LR    R12,R15                   Establish base register
         USING HELLO,R12                 Tell assembler about base
         LA    R11,SAVEAREA              Point to save area
         ST    R13,4(R11)               Chain save areas
         ST    R11,8(R13)               Chain save areas
         LR    R13,R11                   Set new save area
*
         OPEN  (SYSPRINT,OUTPUT)         Open file for output
         LTR   R15,R15                   Check return code
         BNZ   ERROR                     Branch if open failed
*
         PUT   SYSPRINT,RECORD           Write the record
         LTR   R15,R15                   Check return code
         BNZ   ERROR                     Branch if write failed
*
         CLOSE SYSPRINT                  Close the file
         LTR   R15,R15                   Check return code
         BNZ   ERROR                     Branch if close failed
*
         LA    R15,0                     Set return code to zero
         B     RETURN                    Branch to return
*
ERROR    DS    0H                        Error handling
         LA    R15,8                     Set error return code
*
RETURN   DS    0H                        Return to caller
         L     R13,4(R13)               Restore save area pointer
         LM    R14,R12,12(R13)           Restore registers
         BR    R14                       Return to caller
*
SAVEAREA DS    18F                       Register save area
*
SYSPRINT DCB   DDNAME=SYSPRINT,DSORG=PS,MACRF=PM,RECFM=F,LRECL=80
*
RECORD   DC    CL80'Hello World'         Output record
*
         END   HELLO                     End of program

My comments:

My take on these results:

Same prompt, different results

You may get different results with the same prompt. As I've seen with creating images with chatbots, you can get different results on repeated requests. You will probably get different results if you use the same prompt I did.


Return to Dave's AI and mainframe assembler page .

Last Updated: 2025-07-09
This web page is © 2025+ by David Alcock. All Rights Reserved.