AI and mainframe assembler

Generate a routine to format a STCK value using STCKCONV


My previous test was to format a STCKE value using STCKCONV and none of the chatbots were successful.

This time I gave the chatbots a more detailed prompt with more requirements for the STCK conversion. The green text is specific to this request and the blue text is general instructions to use for future requests.

Prompt:
 
Generate HLASM code for a routine that converts a STCK value to readable time and date using the IBM STCKCONV macro
- The routine name is Convert_STCK 
- Input:  R1 has the address of the 8 byte binary STCK value 
- Output: R1 has the address of the 20 byte text string in the format "YYYY-MM-DD HH:MM:SS"
- Output: R15 has the return code from the STCKCONV macro  
- The routine uses BAKR and PR for entry and return 
- The routine will be added to an existing program that uses R12 for the base register and R13 for the Register Save Area. 
- Do not obtain storage. 
- Place new fields after the PR instuction. 
- Register equates are already defined as: R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15  
- 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  


ChatGPT generated this program:
Convert_STCK BAKR  R14,R15               Save caller’s state               
            PR                         Return to caller                    

*--------- Working storage ---------
WD_STCKCONV DS    0CL32                 STCKCONV work area                
WD_TEXT     DS    CL20                 Output text: "YYYY-MM-DD HH:MM:SS"

*--------- Code starts here --------
            L     R2,0(R1)             Load STCK pointer into R2         
            ST    R2,WD_STCK           Save STCK value address           
            LA    R2,WD_STCKCONV       Load address of STCKCONV work     
            LA    R3,WD_TEXT           Load output text buffer address   
            STCKCONV CONVERT=(2),     Use STCKCONV to convert STCK      
                  STCKVAL=WD_STCK,                                    X  
                  TEXT=3,                                               X
                  MF=(E,WD_STCKCONV)                                    
            LR    R15,R0               Move return code to R15           
            LA    R1,WD_TEXT           Set R1 to address of output text  
            PR                         Return to caller                  

*--------- Local fields ---------
WD_STCK     DS    D                    Holds input STCK value            

My comments:


Grok generated this program:
* Convert STCK value to readable date and time
Convert_STCK  BAKR  R14,0         Save caller's registers
* Define storage for STCKCONV parameters and output
             USING *,R12         Establish base register
STCKParm     DS    0F            STCKCONV parameter list
STCKTime     DS    D             8-byte STCK input value
STCKOut      DS    CL20          20-byte output YYYY-MM-DD HH:MM:SS
* Copy input STCK value to parameter area
             MVC   STCKTime(8),0(R1)  Move STCK value to work area
* Call STCKCONV to convert STCK to readable format
             LA    R2,STCKTime   Point to STCK value
             LA    R3,STCKOut    Point to output area
             STCKCONV STCKVAL=(R2),  Input STCK value
               DATETYPE=YYYYMMDD,     Output format YYYY-MM-DD
               TIMETYPE=HHMMSS,       Output time HH:MM:SS
               OUT=(R3)               Output address
* Set return registers
             LR    R1,R3         R1 points to output string
             LR    R15,R15       R15 has STCKCONV return code
* Return to caller
             PR                  Return to caller

My comments:


Gemini generated this program:
***********************************************************************
* *
* Routine: Convert_STCK                                               *
* *
* This routine converts an 8-byte STCK value into a readable          *
* character string format 'YYYY-MM-DD HH:MM:SS'. It uses the           *
* IBM STCKCONV macro to perform the initial conversion.               *
* *
* Input Parameters:                                                   *
* R1 - Contains the address of the 8-byte STCK value.               *
* *
* Output Parameters:                                                  *
* R1 - Contains the address of the 20-byte formatted output string. *
* R15 - Contains the return code from the STCKCONV macro.           *
* *
* Register Usage:                                                     *
* R2 - Holds the input STCK value address.                          *
* R3 - Temporarily saves the STCKCONV return code.                  *
* R12 - Assumed to be the base register for the calling program.    *
* R13 - Assumed to hold the address of the register save area.      *
* R14 - Used for linkage by BAKR and PR.                            *
* R15 - Used for linkage and holds the final return code.           *
* *
***********************************************************************
Convert_STCK BAKR R14,0             Save caller's regs and set linkage
             LR   R2,R1               R2 -> Input STCK value
*
* Convert the STCK value to a simple character string YYYYMMDDHHMMSS
*
             STCKCONV TIMETYPE=DEC,CONVTYPE=TOD,STCKVAL=(R2),        x
               OUTBUF=STCK_CHAR,OUTFORM=Y4O
*
             LR   R3,R15              Save STCKCONV return code
*
* Format the character string from STCKCONV into the desired format.
* The source string (STCK_CHAR) is 'YYYYMMDDHHMMSS'.
* The target string (TIME_STR) is 'YYYY-MM-DD HH:MM:SS'.
*
             MVC  TIME_STR(4),STCK_CHAR       Move YYYY
             MVC  TIME_STR+5(2),STCK_CHAR+4   Move MM
             MVC  TIME_STR+8(2),STCK_CHAR+6   Move DD
             MVC  TIME_STR+11(2),STCK_CHAR+8  Move HH
             MVC  TIME_STR+14(2),STCK_CHAR+10 Move MM
             MVC  TIME_STR+17(2),STCK_CHAR+12 Move SS
*
             LA   R1,TIME_STR         Set R1 to the address of output
             LR   R15,R3              Set R15 to the STCKCONV ret code
             PR                     Return to the calling program
*
*
* --- Storage Definitions ---
* Place new fields after the PR instruction as requested.
*
STCK_CHAR    DS    CL14               Work area for STCKCONV output
TIME_STR     DS    0CL20              Formatted output timestamp
             DC    C'YYYY-MM-DD HH:MM:SS'  Initialize with separators

My comments:


Copilot generated this program:
Convert_STCK CSECT
             BAKR  R14,R12               Entry with base register
             USING Convert_STCK,R12      Establish addressability
             ST    R14,SAVR14            Save return addr in RSA
             ST    R1,SAVR1              Save STCK input addr
             LA    R2,DATEAREA           Point to output text field
             STCKCONV STCK=(SAVR1),TIMEVAL=TIMESTR,               X
                   EBCDIC=DATEAREA,MF=(E,RETAREA)
             LR    R1,R2                 Return output string addr
             L     R15,RETAREA           Return code from STCKCONV
             L     R14,SAVR14            Restore return addr
             PR                          Return to caller
SAVR14       DS    F                     Save area for R14
SAVR1        DS    A                     Save area for R1 input addr
TIMESTR      DS    CL8                   Binary time field
RETAREA      DS    F                     Field for STCKCONV return code
DATEAREA     DS    CL20                  Output "YYYY-MM-DD HH:MM:SS"
             END   Convert_STCK

My comments:


Claude generated this program:
Convert_STCK BAKR  R14,0              Save registers and return addr
         USING Convert_STCK,R12    Establish base register
         LR    R2,R1               Save input STCK address
         LA    R1,STCK_WORK        Point to work area for STCKCONV
         LA    R0,STCK_PARMLIST    Point to parameter list
         STCKCONV STCKVAL=(R2),CONVVAL=(R1),PARMLIST=(R0),       X
               DATETYPE=YYYYMMDD,TIMETYPE=HHMMSS
         LR    R15,R0              Save return code from STCKCONV
         LTR   R15,R15             Check if conversion successful
         BNZ   CONVERT_EXIT        Branch if error occurred
*        Format the output string
         LA    R3,OUTPUT_STRING    Point to output string area
         MVC   0(4,R3),STCK_WORK   Move YYYY
         MVI   4(R3),C'-'          Insert dash
         MVC   5(2,R3),STCK_WORK+4 Move MM
         MVI   7(R3),C'-'          Insert dash
         MVC   8(2,R3),STCK_WORK+6 Move DD
         MVI   10(R3),C' '         Insert space
         MVC   11(2,R3),STCK_WORK+8 Move HH
         MVI   13(R3),C':'         Insert colon
         MVC   14(2,R3),STCK_WORK+10 Move MM
         MVI   16(R3),C':'         Insert colon
         MVC   17(2,R3),STCK_WORK+12 Move SS
         MVI   19(R3),C' '         Blank last position
         LA    R1,OUTPUT_STRING    Return address of formatted string
CONVERT_EXIT PR                    Return to caller
*        Work areas and parameter list
STCK_WORK    DS    CL16            Work area for STCKCONV output
STCK_PARMLIST DS   0F              Parameter list for STCKCONV
         DC    A(STCK_WORK)        Address of conversion work area
         DC    A(16)               Length of work area
         DC    A(0)                Reserved field
OUTPUT_STRING DS   CL20            Formatted output string

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.