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

8 responses to “Writing Reentrant Assembler Code

  1. Niemand Thuis

    All GRT (good, right and true) but besides z/OS system level, e.g., SVCs, exits, STCs, (E)LPA programming and the CICS OTE, where in userland is reentrancy necessary (“… no matter how many users are running it concurrently.”)?
    As for LE-compliant HLASM, the overhead of enclave creation / destruction may well be the ‘deal breaker’ where ILC (interlanguage communication) is not required.

    • Good points.
      – I do know a company that adopted reentrancy as a standard approach for their base system, but I viewed it as a stylistic choice. I’ll ask the designer what advantages, if any, he thought it added.
      – I think you’re right about LE Compliant Assembler – not needed unless you’re making multiple interlanguage calls – or want to standardize some of the library calls among the languages you’re using. In my case, it’s an interesting corner of the world to explore, and I did want to write about LE briefly, so I thought I’d better add something on reentrancy.
      Many thanks for taking time to respond, Niemand. It’s great to hear from you – keep me straight.

    • Re-reading the article, I see what you mean about “no matter how many users are running it concurrently”. Not exactly what I intended. Probably should have said “We use it in cases where many users might run it concurrently.” Thanks, again.

  2. Steve Comstock, retired Assembler Programming lecturer, advocates reentrant coding as simply good practice for optimum performance. In his “Applications Assembler Programming for z, A Technical Discourse”(*), he advises:
    Quote: “If there are instructions and data in the same cache line and any of the data is changed, both caches must be refreshed. This can cause a big performance hit. So the coding guidelines include:
    –> code in a reentrant style
    reentrant code by its very nature separates instructions and data and never causes cache refresh due to storing into itself.” End quote.

    Works for me!
    Reentrant coding isn’t really all that difficult, and it’s good a discipline to help create “clean” code. And don’t we all want our code to be as clean as can be? 😉

    (*) http://web.archive.org/web/20120813154951/http://www.trainersfriend.com/Papers/Assembler.Coding.1.pdf

    • Thanks for weighing in, David. And thanks much for the great link – we can all benefit from reading it. I’m going to spend some time with it.I haven’t heard anyone talk about the effect of reentrant programming on the cache before, but it makes sense.

  3. Jay

    Thanks for this great article. There are times when we have to rely on EX instruction which will break reentrancy. How do you find alternates to that. For example I would need to write a generic parser that
    parse a sysin card that contains keyword and value pair.

    AGE 30

    Usually we can use TRT to find the next blank character from the start and calculate the length and move the value for that specific length using EX and target instruction being MVC.
    How do you see any alternate code without EX involved.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.