ChatGPT "knows" HLASM

191 views
Skip to first unread message

John McKown

unread,
Jun 1, 2023, 1:39:47 PM6/1/23
to ASSEMBL...@listserv.uga.edu
I asked ChatGPT for an example HLASM program. Here's what I got:

BALR R9,0 Set the base register
USING *,R9 Establish a base register
LR R3,R9 Load the base register into R3
LA R4,ARRAY Load the address of the array into R4
LA R5,SIZE Load the size of the array into R5
L R6,0(R4) Load the first element of the array into
R6
L R7,=F'0' Initialize the sum to zero
LOOP AR R7,R6 Add the current element to the sum
A R4,=F'4' Move to the next element of the array
LA R8,1(0,R4) Load the address of the next element into
R8
L R6,0(R8) Load the next element into R6
CR R4,R5 Compare the current element to the end of
the array
BNE LOOP Branch back to LOOP if not at the end of
the array
BR R14 Return to the caller
ARRAY DC F'1' Array of numbers
DC F'2'
DC F'3'
DC F'4'
DC F'5'
SIZE DC F'5' Size of the array

Of course, there are a lot of problems with this, such as no CSECT and no
END. But I was amazed it had anything at all.It's fun to play with.

Mike Shaw

unread,
Jun 1, 2023, 1:48:32 PM6/1/23
to ASSEMBL...@listserv.uga.edu
bard.google.com is much worse:

----------------------
Sure, here is a sample HLASM program that prints the message "Hello,
world!" to the console:

Code snippet

HLASM program to print "Hello, world!"

* * *

CSECT

* Start of main program
MAIN:

* Print message
MVC SYSPRINT,MESSAGE
PUT SYSPRINT,(1)

* End of main program
END MAIN

* Message to be printed
MESSAGE:

DC C'Hello, world!'

Then it tries to provide an explanation and makes things even more obscure:

This program first defines a section called MAIN. This section contains the
main program code. The next statement, MVC SYSPRINT,MESSAGE, copies the
message Hello, world! to the memory location SYSPRINT. The next statement,
PUT SYSPRINT,(1), prints the contents of SYSPRINT to the console. The last
statement, END MAIN, marks the end of the main program.
Mike Shaw
MVS/QuickRef Support Group
Chicago-Soft, Ltd.

Seymour J Metz

unread,
Jun 1, 2023, 2:09:32 PM6/1/23
to ASSEMBL...@listserv.uga.edu
I cined the term Artificial Stupiditiy (AS) for such code.


--
Shmuel (Seymour J.) Metz
http://mason.gmu.edu/~smetz3

________________________________________
From: IBM Mainframe Assembler List [ASSEMBL...@LISTSERV.UGA.EDU] on behalf of Mike Shaw [quic...@GMAIL.COM]
Sent: Thursday, June 1, 2023 1:47 PM
To: ASSEMBL...@LISTSERV.UGA.EDU
Subject: Re: ChatGPT "knows" HLASM

Paul Gilmartin

unread,
Jun 1, 2023, 2:40:34 PM6/1/23
to ASSEMBL...@listserv.uga.edu
How did it know that? Plagiarism? What sources?

But: too many magic constants. Should use EQU, symbolic differences,
and length attributes:


At last, the best way to clear a register!
L R7,=F'0' Initialize the sum to zero
...
L R6,0(R4) Load the first element of the array into
Why is that outside the loop?

A R4,=F'4' Move to the next element of the array
Use length attribute.

A R4,=F'4' Move to the next element of the array
LA R8,1(0,R4) Load the address of the next element into R8
L R6,0(R8) Load the next element into R6
CR R4,R5 Compare the current element to the end of
??? Is R4 a pointer or a counter?

SIZE DC F'5' Size of the array
Magic constant.

I'd give extra credit for "while" logic to handle a 0-length array.

--
gil

Jon Perryman

unread,
Jun 1, 2023, 2:54:26 PM6/1/23
to ASSEMBL...@listserv.uga.edu
ChatGPT gave you the answer you asked for. You didn't ask for good or functional. Why are you asking AI a question that would yield the same results as a Google search?
Ask ChatGPT to convert an HLASM program (you supply) to C. My guess is that it will say something like it has not been trained to convert HLASM to C which would be a valid answer.
Ask ChatGPT to fix the example HLASM program.  

Schmitt, Michael

unread,
Jun 1, 2023, 3:08:18 PM6/1/23
to ASSEMBL...@listserv.uga.edu
I asked ChatGPT:

Write a z/Architecture assembler program to solve Advent of Code 2021 day 17 part 2.

I was expecting a result like linked in this post: https://www.reddit.com/r/adventofcode/comments/ri9kdq/comment/hqcqzqe/?utm_source=share&utm_medium=web2x&context=3 (click on z/Architecture Assembler, I didn't post THAT link because it is HUGE)


The actual result was:

TITLE 'Advent of Code 2021 - Day 17 Part 2'
STM 14,12,12(13) Save registers

USING *,13 Establish base register
LR 12,15 Set the return address

...
... Insert your code here
...

LA 15,0 Set return code 0
LM 14,12,12(13) Restore registers
BR 14 Return to caller

...
... Insert subroutines or helper functions here
...

END


With the explanation:

Certainly! The Advent of Code 2021 Day 17, Part 2 problem involves a 4-dimensional cellular automaton. Although it's not possible for me to write a complete assembler program here, I can provide you with a skeleton program that you can use as a starting point. Please keep in mind that you'll need to fill in the missing details and implement the necessary logic to solve the problem.


...which is way wrong. Advent of Code 2021 Day 17 is a trajectory calculation puzzle, not cellular automaton.

Here's the part 1 puzzle. (You can't see part 2 until you solve part 1.)


But I also would have accepted "I won't give you a solution because that would be cheating."






John McKown

unread,
Jun 1, 2023, 5:30:37 PM6/1/23
to ASSEMBL...@listserv.uga.edu
I'm still having fun using this. But the code is becoming blatantly wrong.
Example:

It referenced SVC 202, which I happen to remember is used by CMS. The
original code used SVC 100, which is just wrong for z/OS. I don't know if
SVC 100 is used in z/VM CMS, but I'd guess not. It used SVC 202 when I told
it to rewrite the code for z/OS. Entirely wrong. The original code also had
some instructions like MVC 0(1),0(1) after doing an LA 1,VARIABLE. Way
wrong.So it might be good for some small code snippets or to generate
ideas, but it isn't replacing an HLASM programmer! Hey, 2 more months and
I'm terminated because the z mainframe is already gone. All the
applications & data has been successfully moved to some Windows application
called FACETS.

LA 1,INPUT L 2,=A(0) Clear work area STC 2,0(1) Clear packed decimal input
LA 1,=P'0' L 15,=V(X'05F0') SVC 202 instruction IC 1,0(15) Read packed
decimal input

On Thu, Jun 1, 2023 at 2:08 PM Schmitt, Michael <michael...@dxc.com>
wrote:

Paul Gilmartin

unread,
Jun 1, 2023, 7:12:26 PM6/1/23
to ASSEMBL...@listserv.uga.edu
On 6/1/23 11:39:34, John McKown wrote:
What happens if you ask not to translate the HLASM to C, but to write
a C program to compute the sum of the elements in an array?
Here's what I might do, based on the above:
#include <stdio.h>

long ARRAY[] = { 1, 2, 3, 4, 5 }; /* Array of numbers */

int main( void ) {
long R7 = 0;
long *R8;

for ( R8 = ARRAY; /* Address first element */
/* (Is there any way to avoid the magic number "5"?) */
R8 < ARRAY + 6; /* Test for end of ARRAY */
++ R8 ) /* Load the address of the next element into R8 */
R7 += *R8;

printf( "Sum is %ld\n", R7 );
return( 0 ); }; /* Return to the caller */

--
gil

John McKown

unread,
Jun 1, 2023, 7:27:55 PM6/1/23
to ASSEMBL...@listserv.uga.edu
>
> Oh, I guess I should mention that what got me interested was s YouTube
> where the person used ChatGPT to create Python code. The entire point was
> that the original Python code was really poor, but by asking and telling
> ChatGPT more and iterating, the code got progressively better. I wanted to
> see if it would work with HLASM. It seems to, but ChatGPT doesn't really
> know HLASM as well as it needs to for generating code. In real life, I am
> guessing that using Metal C would be much better and quicker.


I've found the responses to be very interesting. Hum, I wonder if ChatGPT
know LE.

John McKown

unread,
Jun 1, 2023, 7:46:33 PM6/1/23
to ASSEMBL...@listserv.uga.edu
On Thu, Jun 1, 2023 at 6:27 PM John McKown <john.arch...@gmail.com>
wrote:
In a word, NO. It says it does, but doesn't write LE enabled code at all.
It basically looks the same as its non-LE version. Wish I could train it.
It insists that SVC 202 is a valid z/OS SVC for some functions. I guess it
can't really tell the difference between z/OS and CMS z/OS emulation and so
thinks all z/OS services are done via CMS's SVC 202.

Well, I will stop bothering ya'll with this silliness.

Paul Gilmartin

unread,
Jun 1, 2023, 8:03:08 PM6/1/23
to ASSEMBL...@listserv.uga.edu
On 6/1/23 17:27:21, John McKown wrote:
>>
>> Oh, I guess I should mention that what got me interested was s YouTube
>> where the person used ChatGPT to create Python code. The entire point was
...
What are you quoting? I can't find it in the Archives.


> I've found the responses to be very interesting. Hum, I wonder if ChatGPT
> know LE.

Eek!

How much guidance did you give it? (Did you ask for the sum of an array?)

What do you get when you pose a very similar request, but "s/HLASM/C/"?

--
gil

John McKown

unread,
Jun 1, 2023, 8:43:49 PM6/1/23
to ASSEMBL...@listserv.uga.edu
On Thu, Jun 1, 2023 at 7:03 PM Paul Gilmartin <
00000014e0e4a59...@listserv.uga.edu> wrote:

> On 6/1/23 17:27:21, John McKown wrote:
> >>
> >> Oh, I guess I should mention that what got me interested was s YouTube
> >> where the person used ChatGPT to create Python code. The entire point
> was
> ...
> What are you quoting? I can't find it in the Archives.
>

I wasn't trying to quote anything. I was just intending to say that a video
I saw where a person used ChatGPT to create some Python code, and how he
had to go back & forth refining things was what made me wonder if it could
do the same with HLASM.

>
>
> > I've found the responses to be very interesting. Hum, I wonder if ChatGPT
> > know LE.
>
> Eek!
>
> How much guidance did you give it? (Did you ask for the sum of an array?)
>

I just asked for a basic Language Enabled HLASM program to start with.
ChatGPT tried to give me the equivalent of the C "Hello, World" program.
The code used SVC 202 (which I remember being part of CMS). I told it to
rewrite for z/OS. It said I was right that SVC 202 was not for z/OS, but
gave me the same code back. I asked what SVC 202 did. It said it invoked
"z/OS Console Services". I tried looking that up using Google & just got
some things about REST web.


> What do you get when you pose a very similar request, but "s/HLASM/C/"?
>

In the same conversation, I said "show me this in the C language" and I got:

#include <stdio.h>
#include <string.h>
#include <csysdef.h>

int main() {
char message[] = "Hello, World!";
int length = strlen(message);

cconsole_code_t code;
code.code = 0;

__consvc(CON_WRITE, message, length, &code);

return 0;
}
I can't find anything about "csysdef.h" nor __consvc with a Google search
on +site:ibm.com It looks vaguely CMSish to me (from long ago).



>
> --
> gil
>

John McKown

unread,
Jun 1, 2023, 8:52:57 PM6/1/23
to ASSEMBL...@listserv.uga.edu
On Thu, Jun 1, 2023 at 7:43 PM John McKown <john.arch...@gmail.com>
wrote:

> In the same conversation, I said "show me this in the C language" and I
> got:
>
> #include <stdio.h>
> #include <string.h>
> #include <csysdef.h>
>
> int main() {
> char message[] = "Hello, World!";
> int length = strlen(message);
>
> cconsole_code_t code;
> code.code = 0;
>
> __consvc(CON_WRITE, message, length, &code);
>
> return 0;
> }
>

Oh, rats' rumps. I asked "where is csysdef.h" defined and ChatGPT said that
it was a placeholder for user supplied code. Which I guess is what the SVC
202 in the original code is also.

If I ask for 'a "hello, world" in C", I get the usual C code that is well
known.

ChatGPT was not very explicit at first about "insert user code here to do
..." and that only came to light after I started grilling it with questions.


>
>
>
>>
>> --
>> gil
>>
>

Wendell Lovewell

unread,
Jun 2, 2023, 1:48:41 PM6/2/23
to ASSEMBL...@listserv.uga.edu
fwiw, I've been using ChatGPT and especially Monica to convert some DOS .BAT programs to Python. I paste in the BAT file and ask it to convert it to Python.

It does a remarkable job generating "real" Python code--not just rewriting the DOS statements one by one.

However, I'd guess it's been wrong maybe 30%-40% of the time. But since I'm just learning Python (this way), it's been a huge help.

It's kind of like being in a computer lab with your own personal assistant who is 100% confident in their answers, but wrong at least 1/3 of the time.

I'd guess it gets a lot more Python questions than Assembler, so I imagine the Assembler code would be even worse. But if you don't know the language, it's an easier way to get started.

Wendell

Gary Weinhold

unread,
Jun 2, 2023, 9:11:07 PM6/2/23
to ASSEMBL...@listserv.uga.edu
Our manager, who is not an HLASM programmer, asked ChatGPT to create an assembler program to move data from one location to another. He then had to ask it to do it for z/OS. The response was:

For z/OS assembly language, you can use the BALR (Branch and Link Register) instruction to move data from one memory address to another. Here's an example program that demonstrates how to perform the data transfer:

USING *,12



START EQU *



LR R1,R3 Load source address into R1

LR R2,R4 Load destination address into R2



L R5,0(R1) Load data from source address

ST R5,0(R2) Store data to destination address



.

.

.

(Rest of the program)



.

.

.



END START

I critiqued the results and in response, a tech support person said, well, I'm sure it could learn quicker than I could. My response was:

* ChatGpt has the limitation that it doesn't have a mentor that takes the time to say, that's a good try but this is better. It is limited to what is published out there and lacking comments, doesn't have a good way to evaluate which are the best techniques. So it guesses just like a human.
* And I personally think you could learn to be effective in assembler faster than ChatGPT, because you'd have a mentor and a place to test your code. ChatGPT obviously doesn't assemble its code and test it.

If you isolate ChatGPT (or any AI) to only consult code samples from sources that have been vetted to be good (for some value of good) and if it accepted and remembered criticism without getting sulky, perhaps it could learn to present acceptable HLASM code.

My concern is that ChapGPT will teach everyone the System 360 (or at best S/370) instruction set (because of the volume of code and textbooks available) instead of consulting Ehrmann's (and others) excellent SHARE presentations.

Gary Weinhold
Senior Application Architect
DATAKINETICS | Data Performance & Optimization
Phone:+1.613.523.5500 x216
Email: wein...@dkl.com
Visit us online at www.DKL.com
E-mail Notification: The information contained in this email and any attachments is confidential and may be subject to copyright or other intellectual property protection. If you are not the intended recipient, you are not authorized to use or disclose this information, and we request that you notify us by reply mail or telephone and delete the original message from your mail system.


________________________________
From: IBM Mainframe Assembler List <ASSEMBL...@LISTSERV.UGA.EDU> on behalf of Wendell Lovewell <000009624390d78...@LISTSERV.UGA.EDU>
Sent: June 2, 2023 13:48
To: ASSEMBL...@LISTSERV.UGA.EDU <ASSEMBL...@LISTSERV.UGA.EDU>
Subject: Re: ChatGPT "knows" HLASM

Janko Kalinic

unread,
Jun 3, 2023, 11:54:24 AM6/3/23
to ASSEMBL...@listserv.uga.edu
I wonder if you prefaced the ChatGPT question with “Using the Assembler
Language Programming for IBM z System Servers
<https://idcp.marist.edu/documents/33945/44724/Assembler.V2.alntext+V2.00.pdf/ad61965e-8485-65e1-f385-e5cd56f08c63?t=1551806232272>
-
Version 2.00 by John R. Ehrman as a reference” generate HLASM code to do
the following…

Do you think AI would find the book, parse it, and then use the results?
Or would it schedule a batch job to do the analysis and update the AI
MongoDB?

Regards,
John K

Robert Netzlof

unread,
Jun 3, 2023, 2:14:36 PM6/3/23
to ASSEMBL...@listserv.uga.edu
Nah! It would probably see the 1346 page count and kill the operator.
--
Bob Netzlof a/k/a Sweet Old Bob

Seymour J Metz

unread,
Jun 4, 2023, 10:58:05 AM6/4/23
to ASSEMBL...@listserv.uga.edu

Breton Imhauser

unread,
Jun 5, 2023, 11:12:48 AM6/5/23
to ASSEMBL...@listserv.uga.edu
Not too long ago, I asked it for some ideas on processing specific SMF records ( in hlasm, of course ), and to my surprise, it had its first response had the DSECT field names correct.
I was pleasantly surprised with the entire "conversation" and end result; haven't messed with it since though.

***PDO Alert: June 17 - 25
Thanks!
Breton Imhauser
Expert Solution Delivery Architect | MF Implementations
o: 501.585.4066
e: breton....@ensono.com
Ensono.com












© 2021 Ensono, LP. All rights reserved. Ensono is a trademark of Ensono, LP. The information contained in this communication is confidential, is intended only for the use of the recipient named above, and may be legally privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please resend this communication to the sender and delete the original message or any copy of it from your computer system.
Reply all
Reply to author
Forward
0 new messages