ChatGPT generated this program:
STCK2ASC CSECT
STCK2ASC AMODE 31
STCK2ASC RMODE 31
BAKR 14,0 Save caller's registers
USING STCK2ASC,15
LR 13,15 Establish base
STM 14,12,12(13) Save registers 14-12
YREGS Load general-purpose register equates
*---------------------------------------------------------------
* R1 contains pointer to 16-byte STCKE input
* Convert to TOD structure using STCKCONV
*---------------------------------------------------------------
L R2,=A(TODWORK) Point to TOD work area
L R3,R1 Load pointer to STCKE value
STCKCONV STCKVAL=(R3),TODVAL=(R2),STCKE=YES
*---------------------------------------------------------------
* Format time as HH:MM:SS and date as CCYY-MM-DD
*---------------------------------------------------------------
L R4,=A(OUTBUF) Point to output buffer
MVC 0(2,R4),0(R2) Copy hours
MVC 2(1,R4),=C':' Add colon
MVC 3(2,R4),2(R2) Copy minutes
MVC 5(1,R4),=C':' Add colon
MVC 6(2,R4),4(R2) Copy seconds
MVC 8(1,R4),=C' ' Space separator
MVC 9(4,R4),8(R2) Copy CCYY
MVC 13(1,R4),=C'-' Dash
MVC 14(2,R4),12(R2) Copy MM
MVC 16(1,R4),=C'-' Dash
MVC 17(2,R4),14(R2) Copy DD
LA R1,OUTBUF Return pointer in R1
*---------------------------------------------------------------
* Restore and return
*---------------------------------------------------------------
LM 14,12,12(13) Restore registers
PR 14,0 Return to caller
DROP R15
LTORG
*---------------------------------------------------------------
* Working storage
*---------------------------------------------------------------
TODWORK DS 0CL16 TOD structure (HHMMSS,CCYYMMDD)
OUTBUF DS CL25 Output buffer "HH:MM:SS CCYY-MM-DD"
END STCK2ASC
My comments:
- Inconsistent use of register equates
- R13 is not a good base register
- No need to save and restore registers with STM and LM when using BAKR/PR
- STCKCONV macro was not coded correctly:
- STCKVAL= should have been STCKEVAL=
- TODVAL= should be CONVVAL=
- STCKE=YES is not valid
- Needed TIMETYPE=DEC,DATETYPE=YYYYMMDD
- Uses wrong offsets for converted values
Grok generated this program:
* Define register equates using YREGS
YREGS
* Define storage for STCKCONV output (TOD)
TOD DS 0D
* Define storage for formatted time
OUTTIME DS CL8 HH:MM:SS
* Define storage for formatted date
OUTDATE DS CL10 CCYY-MM-DD
* Define output buffer for final result
OUTBUF DS CL19 HH:MM:SS CCYY-MM-DD
* Define work area for STCKCONV
CONVAREA DS 0D
CONVDATE DS CL8
CONVTIME DS CL8
* Define constant for space character
SPACE DC C' '
* Define constant for colon
COLON DC C':'
* Define constant for hyphen
HYPHEN DC C'-'
* Subroutine entry point
STCKTOFM DS 0H
* Save caller's registers and establish linkage
BAKR 14,0 Save caller's registers
USING STCKTOFM,15 Establish addressability
* Save STCKE value from R1
STG 1,TOD Store STCKE value to TOD
* Convert STCKE to readable format using STCKCONV
STCKCONV TOD=TOD, Input TOD value X
DATETYPE=DATE1, Output format CCYYMMDD X
TIMETYPE=TIME1, Output format HHMMSSTH X
CONVVAL=CONVAREA Output area
* Format time (HH:MM:SS)
MVC OUTTIME(2),CONVTIME Move hours
MVC OUTTIME+2(1),COLON Insert colon
MVC OUTTIME+3(2),CONVTIME+2 Move minutes
MVC OUTTIME+5(1),COLON Insert colon
MVC OUTTIME+6(2),CONVTIME+4 Move seconds
* Format date (CCYY-MM-DD)
MVC OUTDATE(4),CONVDATE Move century and year
MVC OUTDATE+4(1),HYPHEN Insert hyphen
MVC OUTDATE+5(2),CONVDATE+4 Move month
MVC OUTDATE+7(1),HYPHEN Insert hyphen
MVC OUTDATE+8(2),CONVDATE+6 Move day
* Combine time and date with space separator
MVC OUTBUF(8),OUTTIME Move time portion
MVC OUTBUF+8(1),SPACE Insert space
MVC OUTBUF+9(10),OUTDATE Move date portion
* Return pointer to result in R1
LA 1,OUTBUF Load address of output buffer
* Restore registers and return
PR Return to caller
LTORG
END
My comments:
- Didn't use YREG register equates in code.
- Ugliest code of the bunch.
- DATETYPE=DATE1 is not valid
- TIMETYPE=TIME1 is not valid
- Uses wrong offsets for converted values
Gemini generated this program:
*// UID.HLASM.SOURCE(STCKE2DT)
*//********************************************************************/
*//* */
*//* Subroutine: STCKE2DT */
*//* */
*//* Function: Converts an 8-byte STCKE value to a readable */
*//* character string in the format: */
*//* 'HH:MM:SS CCYY-MM-DD' */
*//* */
*//* Entry: */
*//* R1 -> An 8-byte field containing the STCKE value. */
*//* */
*//* Exit: */
*//* R1 -> A 19-byte buffer containing the formatted date/time. */
*//* The caller is responsible for FREEMAINing this storage. */
*//* R15 = 0 for successful completion. */
*//* */
*//********************************************************************/
STCKE2DT CSECT
YREGS * Generate register equates (R0, R1, etc.)
*
* ------------------ Entry Linkage and Setup ------------------------- *
*
BAKR R14,0 * Save caller's registers and link stack
LR R12,R15 * Establish R12 as the base register
USING STCKE2DT,R12 * Inform the assembler of addressability
LR R2,R1 * Save the input STCKE value address in R2
*
* ------------------ Acquire Storage and Convert --------------------- *
*
* Get storage for the output buffer and work areas
GETMAIN RU,LV=STORLEN,SP=1 * Get reentrant storage from subpool 1
LR R10,R1 * Use R10 as the base for GETMAIN'd storage
USING STORE,R10 * Establish addressability to the DSECT
*
* Convert the STCKE value to decimal format using the STCKCONV macro
STCKCONV STCKVAL=(R2),CONVVAL=CVTVAL,TIMETYPE=DEC,DATETYPE=YYYYMMDD
*
* ------------------ Format Time into HH:MM:SS ----------------------- *
*
* CVTTIM contains the time in 4 bytes of packed decimal: X'HHMMSSth'
UNPK WORKUNPK(8),CVTTIM(4) * Unpack time into zoned decimal
OI WORKUNPK+7,X'F0' * Fix the sign nibble to be printable
*
MVC OUTBUFF(2),WORKUNPK+1 * Move HH to output
MVI OUTBUFF+2,C':' * Insert colon
MVC OUTBUFF+3(2),WORKUNPK+3 * Move MM to output
MVI OUTBUFF+5,C':' * Insert colon
MVC OUTBUFF+6(2),WORKUNPK+5 * Move SS to output
*
* ------------------ Format Date into CCYY-MM-DD --------------------- *
*
* CVTDAT contains the date in 4 bytes of packed decimal: X'YYYYMMDD'
MVI OUTBUFF+8,C' ' * Insert space separator
UNPK WORKUNPK(8),CVTDAT(4) * Unpack date into zoned decimal
OI WORKUNPK+7,X'F0' * Fix the sign nibble
*
MVC OUTBUFF+9(4),WORKUNPK * Move CCYY to output
MVI OUTBUFF+13,C'-' * Insert dash
MVC OUTBUFF+14(2),WORKUNPK+4* Move MM to output
MVI OUTBUFF+16,C'-' * Insert dash
MVC OUTBUFF+17(2),WORKUNPK+6* Move DD to output
*
* ------------------ Return to Caller -------------------------------- *
*
LR R1,R10 * Load address of output buffer into R1
LA R15,0 * Set return code to 0 (Success)
PR * Program Return (restores regs & returns)
*
* ------------------ Constants and Storage Areas --------------------- *
*
LTORG * Define the literal pool here
*
* -------------------------------------------------------------------- *
* DSECT to map the storage acquired via GETMAIN. R10 is the base. *
* -------------------------------------------------------------------- *
STORE DSECT
OUTBUFF DS CL19 * FINAL OUTPUT: 'HH:MM:SS CCYY-MM-DD'
CVTVAL DS XL16 * STCKCONV macro output work area
WORKUNPK DS CL8 * Work area for the UNPK instruction
STORLEN EQU *-STORE * Total length of GETMAIN'd storage
*
* -------------------------------------------------------------------- *
* Equates to map fields within the 16-byte CVTVAL area. *
* -------------------------------------------------------------------- *
CVTTIM EQU CVTVAL,4 * Time of day: HHMMSSth (Packed)
* Bytes 4-7: Microseconds
* Byte 8: Leap second adjustment byte
CVTDAT EQU CVTVAL+9,4 * Date: YYYYMMDD (Packed)
*
END STCKE2DT
My comments:
- Generated code that didn't fit in 72 columns
- Generated code that had comments without space after operand
- STCKCONV "STCKVAL=" should be "STCKEVAL="
- Uses wrong offsets for converted values
Copilot generated this program:
STCKREAD CSECT
STCKREAD AMODE 31
STCKREAD RMODE ANY
YREGS Define register equates
BAKR 14,0 Save caller registers using BAKR
* R1 contains the pointer to STCKE input value
LR 3,1 Save STCKE pointer in R3
STORAGE OBTAIN,LENGTH=(LSTCKCONV+100),LOC=(31) Get storage for STCKCONV and output
ST 13,SAVFWD Save caller save area forward pointer
* Initialize the STCKCONV fields
LA 4,STCKCONV_AREA Set pointer to work area
L 5,0(3) Load STCKE value from passed pointer
ST 5,STCKCONV_AREA.STCKE Store in STCKCONV area
* Convert STCKE to readable format
STCKCONV STCKCONV_AREA
* Build output string "HH:MM:SS CCYY-MM-DD"
LA 6,OUTPUT_AREA Pointer to output string buffer
MVC 0(8,6),STCKCONV_AREA.HOUR HH:MM:SS
MVC 9(10,6),STCKCONV_AREA.YEAR CCYY-MM-DD
* Return pointer to string in R1
LR 1,6
PR 14,0 Restore registers and return
LTORG
* Work area
STCKCONV_AREA DS 0D
DS CL(STCKCONV_LEN) Reserve area for STCKCONV
OUTPUT_AREA DS CL22 Buffer for formatted string
SAVFWD DS F Caller save area forward pointer
END STCKREAD
My comments:
- Did not use YREG register equates as requested
- Did not invoke the STCKCONV macro correctly
- Uses wrong offsets for converted values
Claude generated this program:
TITLE 'STCKE TO DATE/TIME CONVERSION SUBROUTINE'
***********************************************************************
* SUBROUTINE: STCKE2DT *
* PURPOSE: Convert STCKE value to readable date/time format *
* INPUT: R1 -> 16-byte STCKE value *
* OUTPUT: R1 -> 19-byte formatted string "HH:MM:SS CCYY-MM-DD" *
* REGISTERS: Saved using BAKR/PR *
***********************************************************************
YREGS Register equates
STCKE2DT CSECT
USING STCKE2DT,R15 Establish addressability
BAKR R14,0 Save registers and return addr
LR R12,R15 Load base register
DROP R15 Drop temporary base
USING STCKE2DT,R12 Establish permanent base
ST R1,STCKEP Save input STCKE pointer
* Convert STCKE to date/time components using STCKCONV
L R2,STCKEP Load STCKE pointer
STCKCONV STCKVAL=(R2),CONVVAL=CVTAREA,TIMETYPE=DEC, X
DATETYPE=YYYYMMDD,CLOCKTYPE=STCKE
* Format time portion (HH:MM:SS)
LA R3,OUTBUF Point to output buffer
* Extract and format hours
LH R4,CVTAREA+8 Load hours (HH)
CVD R4,WORKD Convert to decimal
UNPK WORKC(3),WORKD+6(2) Unpack to character
OI WORKC+2,X'F0' Fix sign
MVC 0(2,R3),WORKC Move hours to output
MVI 2(R3),C':' Add colon separator
LA R3,3(R3) Advance output pointer
* Extract and format minutes
LH R4,CVTAREA+10 Load minutes (MM)
CVD R4,WORKD Convert to decimal
UNPK WORKC(3),WORKD+6(2) Unpack to character
OI WORKC+2,X'F0' Fix sign
MVC 0(2,R3),WORKC Move minutes to output
MVI 2(R3),C':' Add colon separator
LA R3,3(R3) Advance output pointer
* Extract and format seconds
LH R4,CVTAREA+12 Load seconds (SS)
CVD R4,WORKD Convert to decimal
UNPK WORKC(3),WORKD+6(2) Unpack to character
OI WORKC+2,X'F0' Fix sign
MVC 0(2,R3),WORKC Move seconds to output
MVI 2(R3),C' ' Add space separator
LA R3,3(R3) Advance output pointer
* Format date portion (CCYY-MM-DD)
* Extract and format year
LH R4,CVTAREA Load year (CCYY)
CVD R4,WORKD Convert to decimal
UNPK WORKC(5),WORKD+5(3) Unpack to character
OI WORKC+4,X'F0' Fix sign
MVC 0(4,R3),WORKC Move year to output
MVI 4(R3),C'-' Add dash separator
LA R3,5(R3) Advance output pointer
* Extract and format month
LH R4,CVTAREA+2 Load month (MM)
CVD R4,WORKD Convert to decimal
UNPK WORKC(3),WORKD+6(2) Unpack to character
OI WORKC+2,X'F0' Fix sign
MVC 0(2,R3),WORKC Move month to output
MVI 2(R3),C'-' Add dash separator
LA R3,3(R3) Advance output pointer
* Extract and format day
LH R4,CVTAREA+4 Load day (DD)
CVD R4,WORKD Convert to decimal
UNPK WORKC(3),WORKD+6(2) Unpack to character
OI WORKC+2,X'F0' Fix sign
MVC 0(2,R3),WORKC Move day to output
* Return formatted string address in R1
LA R1,OUTBUF Load output buffer address
PR Restore registers and return
* Working storage
STCKEP DS A STCKE pointer storage
CVTAREA DS 0CL16 STCKCONV output area
DS H Year (CCYY)
DS H Month (MM)
DS H Day (DD)
DS H Day of year
DS H Hours (HH)
DS H Minutes (MM)
DS H Seconds (SS)
DS H Microseconds
OUTBUF DS CL19 Output buffer "HH:MM:SS CCYY-MM-DD"
WORKD DS D Work area for CVD
WORKC DS CL8 Work area for UNPK
END STCKE2DT
My comments:
- Generated coded longer than 72 bytes
- STCKCONV "STCKVAL=" should have been "STCKEVAL="
- STCKCONV ",CLOCKTYPE=STCKE" is not valid.
- Uses wrong offsets for converted values