Writing Reentrant Assembler Code

Some programs run so often we take special efforts to make sure that only one copy of the program needs to be loaded into memory, no matter how many users are running it concurrently. That’s what reentrant programming is all about. We can do this by dynamically allocating storage for all the parts of our program that might change. Each user gets their own copy of dynamic storage.

Want to get your assembler program to run in the Language Environment?  It needs to be reentrant.  Future posts will cover COBOL calling Assembler and Assembler calling COBOL in the Language Environment, but to follow along, you first have to learn how to  write assembler reentrantly.

Some programmers write all their programs in a reentrant style. There’s not a lot of extra overhead. Want to give it a try?  I’ve posted a video about how it works here and in the assembler video course. There’s also a sample reentrant program you can start with here.  The video explains in detail how the program works.




Filed under IBM Mainframe Assembler

Marist ECC Conference – Free Online June 7-9

Marist College sponsors one of my favorite mainframe conferences each year called the Enterprise Computing Conference. This year it is scheduled for June 7-9, and it is online and free. The conference always features some interesting general talks by leading IBM and industry experts, as well as a number of smaller talks on mainframe related topics. Here is your chance to attend for free. Check out the conference schedule here: https://ecc.marist.edu/web/conference2020/welcome

Be sure to register early so you won’t miss anything. I’m sorry I won’t get a chance to visit the lovely Marist campus on the Hudson river this year, but I’m looking forward to enjoying the conference virtually. See you there.

Leave a comment

Filed under IBM Mainframe Assembler

Datasets for the COBOL Course

I have added a tab (Course Datasets) at the top of the blog to help provide input data for the programs referenced in the COBOL course.

In the case of input files that contain packed data, I am including a COBOL program that will produce the input file when you run it. Each COBOL program takes its own data from an in-stream dataset. I’m including the COBOL code and the JCL surrounding it to make things easier. You will have to adjust the file names.

In the case textual data files, I’m including a copy of the input data which you can paste into a member in a PDS to create the input file.

Let me know if I can help.

1 Comment

Filed under IBM Mainframe Assembler


I had lots of fun this morning on IBM’s COBOL FRIDAY with Sudharsana Srinivasan and Paul Newton. I talked mostly about COBOL intrinsic functions, but we also considered what to do if you wanted to write something that sort of works like a user-defined function. Enterprise COBOL doesn’t support user-defined functions just yet, but it’s in the works. My work-around involves writing nested programs. You can watch the webcast here if you are interested. I also posted some sample code at the Enterprise COBOL tab that goes along with the talk. The STACKY program does dynamic allocation and creates a stack for storing pointers to records. It uses a nested programming style to create the data structure.

Leave a comment

Filed under IBM Mainframe Assembler

Learn You a COBOL for Great Good

The title is a reference to one of my favorite programming language instruction texts: Learn You a Haskell for Great Good. Funny, well-written and instructive. If you want to learn a functional language, Haskell is a fine choice. I still like writing in Scheme – another functional language that’s almost as old as Cobol.

But today’s topic is Cobol, which has been in the news lately, and which has a few programmers dusting off their old textbooks and manuals.  If you want to learn Cobol or brush up on your old Cobol skills, I might be able to help. I developed an online class a few years ago to use for corporate training. Now I’ve decided to publish it for general use.

You can find it here: IBM Enterprise Cobol and as a link at the top of the home page. It was built with the idea of taking a beginner and turning them into a corporate programmer. If you have some mainframe skills already, you can skip some of the beginning lessons.

The course is divided into 5 units, and if you push hard, it’s possible to get through a unit each day – a week of corporate training.  The course comes with an extensive collection of slides – 299 in all.  There are 15 programming problems that you will need to tackle and complete if you are really wanting to learn something.

You can help me by reporting any problems you have with the site or with the material.

So, … I hope this will help you learn a Cobol for great good!


Filed under IBM Enterprise Cobol, IBM Mainframe Assembler

Introduction to Macros and Conditional Assembly

In the Video Course for IBM Assembler section, I’ve added an introductory lesson on Conditional Assembly and Macro Processing. If you haven’t written macros or want to learn something about conditional assembly instructions, this guide will get you started. There’s also a link to the Powerpoint that goes along with the video.

Leave a comment

Filed under IBM Mainframe Assembler

What you can learn from the Cobol compiler about Assembly language

It can be fun to take a look at the assembly language listing of a Cobol program. Geeky, admittedly, but still fun. If you have never given the listings much thought, take a look at this video. You might be surprised what the Cobol compiler gets up to, and what you can learn about Cobol and assembler. In this video I examine whether to COMPUTE or not to COMPUTE, whether to PERFORM or to PERFORM THRU, and what happens when you tell the optimizer to give it the old college try.

1 Comment

Filed under IBM Mainframe Assembler

It’s worse than he thought

Cobol has been in the news lately since the NJ governor asked for help with some legacy systems.  Perhaps someone should tell him it’s worse than he thought – he’s going to need some assembler programmers, too. 🙂

Some of the recent discussion of Cobol by people who should know better is amusing if it weren’t also disappointing.  You would think that Cobol died in the 1970s.  The fact is, IBM’s Cobol compiler is quite sophisticated, as is the language.  This isn’t your father’s or mother’s Cobol. It is a truly modern language, even object-oriented if you want it to be. On the other hand, writing business systems in Java, C, Python, Ruby, etc.  represents a challenge I would not like to tackle (even though I love those languages).  In many ways those languages are ill-suited to the task – for example, just doing business arithmetic in Java requires some really ugly code.

But what do I know? I still think assembler is fun to write.

One thing’s for sure: It will be fun to hear the forensics of what happened with the governor’s legacy systems. I’m guessing it has little to do with any shortcomings in Cobol.


Filed under IBM Mainframe Assembler

Channeling John Ehrman

In the last post I suggested we take the challenge that John Ehrman posed in problem 41.7.1 of his well-known and used assembler book:

Programming Problem 41.3.(3)+ Write a program with a program interruption exit that generates each of the 15 possible interruption types in turn. For each interruption, generate a message describing the interruption type and the address of the interrupted instruction. Then, return to the mainline program to generate the next interruption.

David Staudacher contributed a number of interesting ways to abend, but I especially liked BCTR R15,R15 for a protection exception. Melvyn Maltz had some interesting comments about the whole issue and suggested he gets S0C5s whenever he uses a bad index into a branch table. You can see all their contributions in the comments on the last article.

I was surprised (after posting) to discover that John himself had already weighed in on this challenge in the Solutions part of his book. Here is what he published (page 1275 of his book):

41.7.1. Some possible but unverified instruction sequences are:

(01)  DC H’0′ Invalid operation

(02)   LPSW 0,8(0,0) Privileged operation

(03)  EX 0,* Execute

(04)  MVI 0,0 Protection

(05)  LGHI 1,-1

IC 1,0(,1) Addressing

(06)   DC X’1D11′ DR 1,1: Specification

(07)  AP *,* Decimal Data

(08)  LA 1,1

SLA 1,33 Fixed-point overflow

(09)   SRDL 0,63

DR 0,0 Fixed-point divide

(0A)   AP A,A Decimal Overflow

A DC P’6′

(0B)   DP A,=P’0′ Decimal Divide

(0C)   LE 0,=E’1E72′ Exponent overflow

MER 0,0

(0D)  LE 0,=E’1E-72′ Exponent underflow

MER 0,0

(0E) LE 0,=X’41000001′ Significance

SU 0,=X’41000001′

(0F)  LE 0,=E’1′ Floating-pointdivide

D 0,=E’0′

I tried running the code above and found an assembly error on (02). John said the code suggestions were unverified! Still he was on the right track. LPSW is a type S instruction and expects a simple base/displacement address, so LPSW 0(8) will generate the error he intended.

You can also get away with SLA 1,32 on (08), but that’s nit-picking.

The only problem in the list was his suggestion for (05) which generated an S0C6 for me instead of the S0C5 we require.

So how do we get a S0C5 exception to occur? I’ve tried a number of bad branches – protection errors every one. After reading the Principles of Operation, I’m wondering if a garden-variety programmer can easily get a S0C5? I hope one of you will prove me wrong. Send me the code that generates a S0C5!


Filed under IBM Mainframe Assembler

Help Me Write The Worst Program Ever

I never got to meet John Erhman but we corresponded a little.  He was kind enough to get me included on the program at a Share conference in Anaheim.  John wrote an excellent Assembler reference titled  Assembler Language Programming for IBM z System Servers . Even a seasoned assembler programmer can learn a lot from this book – it’s packed with many interesting assembler goodies. I keep a link to it nearby and you should, too. I was browsing through it today and came across a suggestion he had for a program to write:

Programming Problem 41.3.(3)+ Write a program with a program interruption exit that generates each of the 15 possible interruption types in turn. For each interruption, generate a message describing the interruption type and the address of the interrupted instruction. Then, return to the mainline program to generate the next interruption.


The program suggestion comes after a section of the book that covers how to handle program interruptions using ESPIE. It wasn’t too hard to get a basic version of the program going. You do have to write some “bad” code to generate the 15 possible program interruptions. As I began to write this code, it struck me as funny that this would be the worst program ever. That’s when I thought it would be fun to enlist your help. Many of the interruptions are easy to generate – we’ve all sinned. But I did scratch my head on how to generate a S0C5. I can’t remember ever getting that interruption, but then my memory isn’t as good as it used to be.

Here’s how you can help: If you have a favorite way to generate one of the 15 possible program interrupts in just a few lines (the fewer the better) send it in. I’ll pick the ones I like best and include them in my program and give you credit. The program will appear in a future post or article on recovering from program interrupts. The program I’m writing does have an input file (FILEIN) and an output file (FILEOUT). That might help you with some of the interrupts. Be sure to include the definitions of any fields you need. As a small tribute to John, we’ll commit every possible error. Help me write the worst program ever!


Filed under IBM Mainframe Assembler